From e7c826735c520c0e3946d587c388494260bf1b80 Mon Sep 17 00:00:00 2001 From: Sebastian Kalinowski Date: Sun, 16 Jun 2019 19:16:32 +0200 Subject: [PATCH] Pass token header to secret fetching function Depending of function arity pass decoded header of the token. This is to allow backward compatibilty. --- lib/index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 575875b..fce7444 100644 --- a/lib/index.js +++ b/lib/index.js @@ -243,13 +243,18 @@ function getSecret (request, secret, token, callback) { return callback({ code: 'invalid_token', message: 'jwt signature is required' }); } - let decodedToken = jwt.decode(token); + let decodedToken = jwt.decode(token, { complete: true }); if (!decodedToken) { 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 { callback(null, secret); }