Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lib/extract_jwt): correctly parse comma terminated token #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/extract_jwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion test/extractors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down