-1

I used JWT to protect my node.js REST api calls. I used below code to generate the token:

jwt.sign({ foo: 'bar' }, private_key, { algorithm: 'RS256'}, (err, token) => {
      res.json({
        token
      });

But I don't get any token with when I use the algorithm: 'RS256'. But above code works with algorithm: 'HS256'.

Do you know a solution?

jps
  • 20,041
  • 15
  • 75
  • 79
Jogi Prasad Pakki
  • 2,013
  • 2
  • 11
  • 21
  • You didn't show what private key actually is. Do you get any errors? Please click on edit to complete the code above and add more information to your question. – jps May 23 '19 at 08:38
  • What npm package are you using to try and generate the JWT? Also please add `console.log(err, token);` to your code and report the results. – Tom May 23 '19 at 08:40
  • quite a waste of time, if you just dump your uncomplete questions and then don't react anymore – jps May 28 '19 at 06:44

1 Answers1

0

try this:

jwt.sign({ foo: 'bar' }, private_key, [{ algorithm: 'RS256'}, (err, token) => {
  res.json({
    token
  }}]);

In npm docs appear this jwt.sign(payload, secretOrPrivateKey, [options, callback]) so pass your options and callback like an array. Hope this help

Schwarz54
  • 964
  • 1
  • 9
  • 18