Skip to content

Commit

Permalink
Fix default authentication config keys (#506)
Browse files Browse the repository at this point in the history
* Updating changelog

* fixing the authentication config key that is referenced. Closes #497

* Work with 'authentication' or 'auth' config key

* Fix reference to app -> this.app
  • Loading branch information
ekryski authored and daffl committed Aug 29, 2018
1 parent 7e4b0b6 commit 5d279cd
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 30 deletions.
5 changes: 2 additions & 3 deletions packages/authentication/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Change Log

## [Unreleased](https://github.com/feathersjs/feathers-authentication/tree/HEAD)

[Full Changelog](https://github.com/feathersjs/feathers-authentication/compare/v1.2.2...HEAD)
## [v1.2.3](https://github.com/feathersjs/feathers-authentication/tree/v1.2.3) (2017-05-10)
[Full Changelog](https://github.com/feathersjs/feathers-authentication/compare/v1.2.2...v1.2.3)

**Closed issues:**

Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ These other middleware are included and exposed but typically you don't need to

### Default Options

The following default options will be mixed in with your global `auth` object from your config file. It will set the mixed options back on to the app so that they are available at any time by calling `app.get('auth')`. They can all be overridden and are depended upon by some of the authentication plugins.
The following default options will be mixed in with your global `auth` object from your config file. It will set the mixed options back on to the app so that they are available at any time by calling `app.get('authentication')`. They can all be overridden and are depended upon by some of the authentication plugins.

```js
{
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/docs/migrating.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ For most of you, migrating your app should be fairly straight forward as there a
const authentication = require('feathers-authentication');
const FacebookStrategy = require('passport-facebook').Strategy;

let config = app.get('auth');
let config = app.get('authentication');
config.facebook.strategy = FacebookStrategy;
app.configure(authentication(config))
.use('/users', memory()) // this use to be okay to be anywhere
Expand Down Expand Up @@ -83,7 +83,7 @@ const FacebookStrategy = require('passport-facebook').Strategy;

// The services you are setting the `entity` param for need to be registered before authentication
app.use('/users', memory())
.configure(auth(app.get('auth')))
.configure(auth(app.get('authentication')))
.configure(jwt())
.configure(local())
.configure(oauth1())
Expand Down
1 change: 1 addition & 0 deletions packages/authentication/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function init (config = {}) {
options.cookie.secure = false;
}

app.set('authentication', options);
app.set('auth', options);

debug('Setting up Passport');
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/src/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Service {
}

create (data = {}, params = {}) {
const defaults = this.app.get('auth');
const defaults = this.app.get('authentication') || this.app.get('auth');
const payload = params.payload;

// create accessToken
Expand All @@ -26,7 +26,7 @@ class Service {
}

remove (id, params) {
const defaults = this.app.get('auth');
const defaults = this.app.get('authentication') || this.app.get('auth');
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/authentication/src/socket/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function handleSocketCallback (promise, callback) {
}

export default function setupSocketHandler (app, options, { feathersParams, provider, emit, disconnect }) {
const authSettings = app.get('auth');
const authSettings = app.get('authentication') || app.get('auth');
const service = app.service(authSettings.path);
const entityService = app.service(authSettings.service);
let isUpdateEntitySetup = false;
Expand Down
8 changes: 4 additions & 4 deletions packages/authentication/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,30 +62,30 @@ describe('Feathers Authentication', () => {
it('sets cookie to be insecure', () => {
app.set('env', 'development');
app.configure(authentication(config));
expect(app.get('auth').cookie.secure).to.equal(false);
expect(app.get('authentication').cookie.secure).to.equal(false);
});
});

describe('when in test mode', () => {
it('sets cookie to be insecure', () => {
app.set('env', 'test');
app.configure(authentication(config));
expect(app.get('auth').cookie.secure).to.equal(false);
expect(app.get('authentication').cookie.secure).to.equal(false);
});
});

describe('when in production mode', () => {
it('sets cookie to be secure', () => {
app.set('env', 'production');
app.configure(authentication(config));
expect(app.get('auth').cookie.secure).to.equal(true);
expect(app.get('authentication').cookie.secure).to.equal(true);
});
});

it('sets custom config options', () => {
config.custom = 'custom';
app.configure(authentication(config));
expect(app.get('auth').custom).to.equal('custom');
expect(app.get('authentication').custom).to.equal('custom');
});

it('sets up feathers passport adapter', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/authentication/test/integration/primus.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ describe('Primus authentication', function () {
let accessToken;

before(done => {
const options = merge({}, app.get('auth'), { jwt: { expiresIn: '1ms' } });
const options = merge({}, app.get('authentication'), { jwt: { expiresIn: '1ms' } });
app.passport.createJWT({}, options)
.then(token => {
expiredToken = token;
return app.passport.createJWT({ userId: 0 }, app.get('auth'));
return app.passport.createJWT({ userId: 0 }, app.get('authentication'));
})
.then(token => {
accessToken = token;
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Primus authentication', function () {
socket.send('authenticate', data, (error, response) => {
expect(error).to.not.be.ok;
expect(response.accessToken).to.exist;
app.passport.verifyJWT(response.accessToken, app.get('auth')).then(payload => {
app.passport.verifyJWT(response.accessToken, app.get('authentication')).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
expect(payload.userId).to.equal(0);
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('Primus authentication', function () {
socket.send('authenticate', data, (error, response) => {
expect(error).to.not.be.ok;
expect(response.accessToken).to.exist;
app.passport.verifyJWT(response.accessToken, app.get('auth')).then(payload => {
app.passport.verifyJWT(response.accessToken, app.get('authentication')).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
expect(payload.userId).to.equal(0);
Expand All @@ -209,7 +209,7 @@ describe('Primus authentication', function () {
socket.send('authenticate', data, (error, response) => {
expect(error).to.not.be.ok;
expect(response.accessToken).to.exist;
app.passport.verifyJWT(response.accessToken, app.get('auth')).then(payload => {
app.passport.verifyJWT(response.accessToken, app.get('authentication')).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
expect(payload.userId).to.equal(0);
Expand Down
10 changes: 5 additions & 5 deletions packages/authentication/test/integration/rest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ describe('REST authentication', function () {
let accessToken;

before(done => {
const options = merge({}, app.get('auth'), { jwt: { expiresIn: '1ms' } });
const options = merge({}, app.get('authentication'), { jwt: { expiresIn: '1ms' } });
app.passport.createJWT({}, options)
.then(token => {
expiredToken = token;
return app.passport.createJWT({ userId: 0 }, app.get('auth'));
return app.passport.createJWT({ userId: 0 }, app.get('authentication'));
})
.then(token => {
accessToken = token;
Expand Down Expand Up @@ -52,7 +52,7 @@ describe('REST authentication', function () {
.send(data)
.then(response => {
expect(response.body.accessToken).to.exist;
return app.passport.verifyJWT(response.body.accessToken, app.get('auth'));
return app.passport.verifyJWT(response.body.accessToken, app.get('authentication'));
}).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('REST authentication', function () {
.send(data)
.then(response => {
expect(response.body.accessToken).to.exist;
return app.passport.verifyJWT(response.body.accessToken, app.get('auth'));
return app.passport.verifyJWT(response.body.accessToken, app.get('authentication'));
}).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
Expand All @@ -123,7 +123,7 @@ describe('REST authentication', function () {
.send(data)
.then(response => {
expect(response.body.accessToken).to.exist;
return app.passport.verifyJWT(response.body.accessToken, app.get('auth'));
return app.passport.verifyJWT(response.body.accessToken, app.get('authentication'));
}).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
Expand Down
10 changes: 5 additions & 5 deletions packages/authentication/test/integration/socketio.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ describe('Socket.io authentication', function () {
let accessToken;

before(done => {
const options = merge({}, app.get('auth'), { jwt: { expiresIn: '1ms' } });
const options = merge({}, app.get('authentication'), { jwt: { expiresIn: '1ms' } });
app.passport.createJWT({}, options)
.then(token => {
expiredToken = token;
return app.passport.createJWT({ userId: 0 }, app.get('auth'));
return app.passport.createJWT({ userId: 0 }, app.get('authentication'));
})
.then(token => {
accessToken = token;
Expand Down Expand Up @@ -88,7 +88,7 @@ describe('Socket.io authentication', function () {
socket.emit('authenticate', data, (error, response) => {
expect(error).to.not.equal(undefined);
expect(response.accessToken).to.exist;
app.passport.verifyJWT(response.accessToken, app.get('auth')).then(payload => {
app.passport.verifyJWT(response.accessToken, app.get('authentication')).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
expect(payload.userId).to.equal(0);
Expand Down Expand Up @@ -186,7 +186,7 @@ describe('Socket.io authentication', function () {
socket.emit('authenticate', data, (error, response) => {
expect(error).to.not.be.ok;
expect(response.accessToken).to.exist;
app.passport.verifyJWT(response.accessToken, app.get('auth')).then(payload => {
app.passport.verifyJWT(response.accessToken, app.get('authentication')).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
expect(payload.userId).to.equal(0);
Expand All @@ -203,7 +203,7 @@ describe('Socket.io authentication', function () {
socket.emit('authenticate', data, (error, response) => {
expect(error).to.not.be.ok;
expect(response.accessToken).to.exist;
app.passport.verifyJWT(response.accessToken, app.get('auth')).then(payload => {
app.passport.verifyJWT(response.accessToken, app.get('authentication')).then(payload => {
expect(payload).to.exist;
expect(payload.iss).to.equal('feathers');
expect(payload.userId).to.equal(0);
Expand Down
4 changes: 2 additions & 2 deletions packages/authentication/test/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('/authentication service', () => {
return app.service('authentication').create(data, params).then(result => {
return app.service('authentication').create(data).then(result => {
return app.passport
.verifyJWT(result.accessToken, app.get('auth'))
.verifyJWT(result.accessToken, app.get('authentication'))
.then(payload => {
const delta = (payload.exp - payload.iat);
expect(delta).to.equal(24 * 60 * 60);
Expand All @@ -117,7 +117,7 @@ describe('/authentication service', () => {

beforeEach(() => {
return app.passport
.createJWT({ id: 1 }, app.get('auth'))
.createJWT({ id: 1 }, app.get('authentication'))
.then(token => { accessToken = token; });
});

Expand Down

0 comments on commit 5d279cd

Please sign in to comment.