Merge pull request #167 from prmtl/feature/pass-token-header

Pass token header to secret fetching function
This commit is contained in:
Conrad Sopala 2020-01-21 15:43:06 +01:00 committed by GitHub
commit 16fefb61bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -243,13 +243,18 @@ function getSecret (request, secret, token, callback) {
return callback({ code: 'invalid_token', message: 'jwt signature is required' }); return callback({ code: 'invalid_token', message: 'jwt signature is required' });
} }
let decodedToken = jwt.decode(token); let decodedToken = jwt.decode(token, { complete: true });
if (!decodedToken) { if (!decodedToken) {
return callback({ code: 'invalid_token', message: 'jwt malformed' }); return callback({ code: 'invalid_token', message: 'jwt malformed' });
} }
secret(request, decodedToken, callback); const arity = secret.length;
if (arity == 4) {
secret(request, decodedToken.header, decodedToken.payload, callback);
} else { // arity == 3
secret(request, decodedToken.payload, callback);
}
} else { } else {
callback(null, secret); callback(null, secret);
} }