Node-jsonwebtoken: [JsonWebTokenError: invalid token] when using a authentication type

Created on 2 Nov 2016  路  1Comment  路  Source: auth0/node-jsonwebtoken

I have the following header:

authorization: 'JWT kjf838.token.8383bfjefjh'

When I try to verify the token I get a invalid token error:

var token = req.headers['authorization'];
jwt.verify(token, config.secret, function (err, decoded) {...}

Do I have to remove the JWT-prefix on my own?

Most helpful comment

That's correct. Try with this:

var token = req.headers['authorization'].replace(/^JWT\s/, '');

>All comments

That's correct. Try with this:

var token = req.headers['authorization'].replace(/^JWT\s/, '');
Was this page helpful?
0 / 5 - 0 ratings