diff --git a/lib/extract_jwt.js b/lib/extract_jwt.js index 7f112abd..cc53d2db 100644 --- a/lib/extract_jwt.js +++ b/lib/extract_jwt.js @@ -58,7 +58,9 @@ extractors.fromAuthHeaderWithScheme = function (auth_scheme) { if (request.headers[AUTH_HEADER]) { var auth_params = auth_hdr.parse(request.headers[AUTH_HEADER]); if (auth_params && auth_scheme_lower === auth_params.scheme.toLowerCase()) { - token = auth_params.value; + token = auth_params.value.endsWith(",") + ? auth_params.value.split(",")[0] + : auth_params.value; } } return token; diff --git a/test/extractors-test.js b/test/extractors-test.js index e38a9bfe..e80bbfd5 100644 --- a/test/extractors-test.js +++ b/test/extractors-test.js @@ -139,8 +139,16 @@ describe('Token extractor', function() { expect(token).to.equal('abcd123'); }); - }); + it('should return the value from the authorization header without a comma at the end', function () { + var req = new Request() + req.headers['authorization'] = 'test_scheme abcd123,'; + + var token = extractor(req); + + expect(token).to.equal('abcd123'); + }); + }); describe('fromAuthHeader', function() {