Я использую JWT с Auth0. Я проверяю токен с помощью открытого ключа (pemCert).
Однако я видел примеры, когда токен декодировался другими способами, например, с помощью закрытого ключа. Является ли использование открытого ключа таким же безопасным, как и другие методы?
const jwt = require('jsonwebtoken');
function authoriseToken(req, res, next) {
const token = req.headers.authorization;
const pemCert = process.env.JWT_PEM;
// If there is no token the user is not logged in
if (!token || token.length === 0) {
next();
return;
}
const tokenCrop = token.replace('Bearer ', '');
jwt.verify(
tokenCrop,
pemCert,
{ algorithm: 'RS256' },
(err, decodedToken) => {
if (err) {
// If the token isn't verified eg expired then forward as if no token
next();
} else if (decodedToken) {
// If the token is verified then add fields to the res
req.authId = decodedToken.sub
next();
}
},
);
}