Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
Add support for Bearer scheme in remove method (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
boybundit authored and ekryski committed Mar 22, 2017
1 parent 0415be3 commit 5df16e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class Service {

remove (id, params) {
const defaults = this.app.get('auth');
const accessToken = id !== null ? id : params.headers[defaults.header.toLowerCase()];
const authHeader = params.headers && params.headers[defaults.header.toLowerCase()];
const authParams = authHeader && authHeader.match(/(\S+)\s+(\S+)/);
const accessToken = id !== null ? id : authParams && authParams[2] || authHeader;

// TODO (EK): return error if token is missing?
return this.passport
.verifyJWT(accessToken, merge(defaults, params))
Expand Down
14 changes: 14 additions & 0 deletions test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,19 @@ describe('/authentication service', () => {
expect(response).to.deep.equal({ accessToken });
});
});

it('verifies an accessToken in the header', () => {
const params = { headers: { authorization: accessToken } };
return app.service('authentication').remove(null, params).then(response => {
expect(response).to.deep.equal({ accessToken });
});
});

it('verifies an accessToken in the header with Bearer scheme', () => {
const params = { headers: { authorization: `Bearer ${accessToken}` } };
return app.service('authentication').remove(null, params).then(response => {
expect(response).to.deep.equal({ accessToken });
});
});
});
});

0 comments on commit 5df16e5

Please sign in to comment.