问题
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.
回答1:
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);
回答2:
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
来源:https://stackoverflow.com/questions/62173970/error-error0909006cpem-routinesget-nameno-start-line