1
votes

I am trying to verify a jwt using jsonwebtoken. When I am using:

jwt.verify(jwt, publicKey)

I am getting a :

JsonWebTokenError {name: "JsonWebTokenError", message: "invalid algorithm", stack: "JsonWebTokenError: invalid algorithm }

When I am using:

jwt.verify(jwt, publicKey, { algorithms: 'RS256'}) 

I am getting:

Error: error:0909006C:PEM routines:get_name:no start line

Any ideas? Is there an alternative to verify a jwt?

Update

The problem lies on the RS256 selection probably.

2

2 Answers

0
votes

Try passing an options object with both audience and issuer attributes .

let options = {
    clockTolerance: 60*24*10, 
    audience: "account",
    issuer: "https://login.someorganization/auth"
};

jwt.verify(jwt, publicKey, options);
0
votes

From the sample above, you are referencing the jwt instance in your verify function

Use the link npm-jsonwebtoken

You will have to verify a token, not the jwt instance Example

const jwt = require('jsonwebtoken')

var decoded = jwt.verify(token, 'private_key');

Where 'private_key' is the exact key used for hashing