Skip to content

Commit

Permalink
feat(authentication): Add parseStrategies to allow separate strategie…
Browse files Browse the repository at this point in the history
…s for creating JWTs and parsing headers (#1708)
  • Loading branch information
daffl committed Nov 27, 2019
1 parent 18ba231 commit 5e65629
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/authentication-local/test/fixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (app = feathers()) => {
service: 'users',
secret: 'supersecret',
authStrategies: [ 'local', 'jwt' ],
parseStrategies: [ 'jwt' ],
local: {
usernameField: 'email',
passwordField: 'password'
Expand Down
5 changes: 3 additions & 2 deletions packages/express/lib/authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ exports.parseAuthentication = (settings = {}) => {
return next();
}

const { authStrategies = [] } = service.configuration;
const config = service.configuration;
const authStrategies = config.parseStrategies || config.authStrategies || [];

if (authStrategies.length === 0) {
debug('No `authStrategies` found in authentication configuration');
debug('No `authStrategies` or `parseStrategies` found in authentication configuration');
return next();
}

Expand Down
3 changes: 2 additions & 1 deletion packages/express/test/authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ describe('@feathersjs/express/authentication', () => {
});
});

it('errors when there are no authStrategies', () => {
it('errors when there are no authStrategies and parseStrategies', () => {
const { accessToken } = authResult;
app.get('authentication').authStrategies = [];
delete app.get('authentication').parseStrategies;

return axios.get('/dummy/dave', {
headers: {
Expand Down
3 changes: 2 additions & 1 deletion packages/socketio/lib/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ exports.authentication = (app, getParams, settings = {}) => (socket, next) => {
return next();
}

const { authStrategies = [] } = service.configuration;
const config = service.configuration;
const authStrategies = config.parseStrategies || config.authStrategies || [];

if (authStrategies.length === 0) {
return next();
Expand Down

0 comments on commit 5e65629

Please sign in to comment.