From ace414d0347685190bacdc2218bd22db4ec91613 Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Mon, 12 Dec 2016 15:19:01 -0700 Subject: [PATCH 1/3] Fix linting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Linting wasn’t running because the jshint-style passing in of paths. --- example/app.js | 11 ++++++----- example/primus-client.js | 4 ++-- example/rest-client.js | 6 +++--- example/socketio-client.js | 4 ++-- package.json | 2 +- src/index.js | 6 +++--- src/passport.js | 12 ++++++------ test/index.test.js | 2 +- 8 files changed, 24 insertions(+), 23 deletions(-) diff --git a/example/app.js b/example/app.js index 871cb1d..35cda22 100644 --- a/example/app.js +++ b/example/app.js @@ -1,18 +1,19 @@ const feathers = require('feathers'); const rest = require('feathers-rest'); const socketio = require('feathers-socketio'); -const primus = require('feathers-primus'); +// const primus = require('feathers-primus'); const hooks = require('feathers-hooks'); const memory = require('feathers-memory'); const bodyParser = require('body-parser'); -const errors = require('feathers-errors'); +// const errors = require('feathers-errors'); const errorHandler = require('feathers-errors/handler'); const auth = require('feathers-authentication'); const local = require('feathers-authentication-local'); const jwt = require('feathers-authentication-jwt'); +const path = require('path'); -function customizeJWTPayload() { - return function(hook) { +function customizeJWTPayload () { + return function (hook) { hook.data.payload = { id: hook.params.user.id }; @@ -32,7 +33,7 @@ app.configure(rest()) .configure(local()) .configure(jwt()) .use('/users', memory()) - .use('/', feathers.static(__dirname + '/public')) + .use('/', feathers.static(path.join(__dirname, '/public'))) .use(errorHandler()); app.service('authentication').hooks({ diff --git a/example/primus-client.js b/example/primus-client.js index c2cf890..fcd2758 100644 --- a/example/primus-client.js +++ b/example/primus-client.js @@ -45,6 +45,6 @@ client.authenticate({ client.set('user', user); console.log('User', client.get('user')); }) -.catch(function(error){ +.catch(function (error) { console.error('Error authenticating!', error); -}); \ No newline at end of file +}); diff --git a/example/rest-client.js b/example/rest-client.js index bb51a80..8467855 100644 --- a/example/rest-client.js +++ b/example/rest-client.js @@ -2,7 +2,7 @@ // Most of the code is the same for the browser with the exception // of how modules are imported and configured. It depends on how you choose // to load them. Refer to the client section of docs.feathersjs.com for more detail. -// +// const feathers = require('feathers/client'); const rest = require('feathers-rest/client'); const superagent = require('superagent'); @@ -33,6 +33,6 @@ client.authenticate({ client.set('user', user); console.log('User', client.get('user')); }) -.catch(function(error){ +.catch(function (error) { console.error('Error authenticating!', error); -}); \ No newline at end of file +}); diff --git a/example/socketio-client.js b/example/socketio-client.js index 10d0a9e..aafe53a 100644 --- a/example/socketio-client.js +++ b/example/socketio-client.js @@ -34,6 +34,6 @@ client.authenticate({ client.set('user', user); console.log('User', client.get('user')); }) -.catch(function(error){ +.catch(function (error) { console.error('Error authenticating!', error); -}); \ No newline at end of file +}); diff --git a/package.json b/package.json index b8971a6..4726b81 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "changelog": "github_changelog_generator && git add CHANGELOG.md && git commit -am \"Updating changelog\"", "compile": "rimraf lib/ && babel -d lib/ src/", "watch": "babel --watch -d lib/ src/", - "lint": "semistandard src/**/*.js test/**/*.js --fix", + "lint": "semistandard --fix", "mocha": "mocha --opts mocha.opts", "coverage": "istanbul cover _mocha -- --opts mocha.opts", "test": "npm run compile && npm run lint && npm run coverage", diff --git a/src/index.js b/src/index.js index b486aac..ebc3ecd 100644 --- a/src/index.js +++ b/src/index.js @@ -5,13 +5,13 @@ const defaults = { header: 'authorization', cookie: 'feathers-jwt', storageKey: 'feathers-jwt', - jwtStrategy: 'jwt', + jwtStrategy: 'jwt', path: '/authentication', entity: 'user', service: 'users' }; -export default function init(config = {}) { +export default function init (config = {}) { const options = Object.assign({}, defaults, config); return function () { @@ -41,4 +41,4 @@ export default function init(config = {}) { }; } -init.defaults = defaults; \ No newline at end of file +init.defaults = defaults; diff --git a/src/passport.js b/src/passport.js index 9864759..ad6b6c0 100644 --- a/src/passport.js +++ b/src/passport.js @@ -9,7 +9,7 @@ export default class Passport { if (app.passport) { throw new Error('You have already registered authentication on this client app instance. You only need to do it once.'); } - + this.options = options; this.app = app; this.storage = app.get('storage') || this.getStorage(options.storage); @@ -22,7 +22,7 @@ export default class Passport { this.setupSocketListeners(); } - setupSocketListeners() { + setupSocketListeners () { const app = this.app; const socket = app.io || app.primus; const emit = app.io ? 'emit' : 'send'; @@ -40,7 +40,7 @@ export default class Passport { if (socket.authenticated) { const data = { strategy: this.options.jwtStrategy, - accessToken: app.get('accessToken'), + accessToken: app.get('accessToken') }; this.authenticateSocket(data, socket, emit) .then(this.setJWT) @@ -61,7 +61,7 @@ export default class Passport { if (socket.authenticated) { const data = { strategy: this.options.jwtStrategy, - accessToken: app.get('accessToken'), + accessToken: app.get('accessToken') }; this.authenticateSocket(data, socket, emit) @@ -93,7 +93,7 @@ export default class Passport { debug('Socket already connected'); return Promise.resolve(socket); } - + return new Promise((resolve, reject) => { const connected = app.primus ? 'open' : 'connect'; const disconnect = app.io ? 'disconnect' : 'end'; @@ -233,7 +233,7 @@ export default class Passport { try { let payload = decode(token); - + if (this.payloadIsValid(payload)) { return Promise.resolve(payload); } diff --git a/test/index.test.js b/test/index.test.js index 1586169..f2ea980 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -47,4 +47,4 @@ describe('Feathers Authentication Client', () => { expect(client.passport.options.service).to.equal('users'); }); }); -}); \ No newline at end of file +}); From 0f483498a338c89754c171a61a672a9763416a36 Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Tue, 13 Dec 2016 11:21:51 -0700 Subject: [PATCH 2/3] Make sure done gets called after rest tests. --- test/integration/rest.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/integration/rest.test.js b/test/integration/rest.test.js index 4c3bf91..f0931bc 100644 --- a/test/integration/rest.test.js +++ b/test/integration/rest.test.js @@ -40,6 +40,7 @@ describe('REST client authentication', () => { after(done => { server.close(done); + done(); }); it('can use client.passport.getJWT() to get the accessToken', () => { From b687aab42992f6f115e688d0222095d3bc44e173 Mon Sep 17 00:00:00 2001 From: Marshall Thompson Date: Tue, 13 Dec 2016 11:57:48 -0700 Subject: [PATCH 3/3] Remove comments. --- example/app.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/example/app.js b/example/app.js index 35cda22..2deb057 100644 --- a/example/app.js +++ b/example/app.js @@ -1,11 +1,9 @@ const feathers = require('feathers'); const rest = require('feathers-rest'); const socketio = require('feathers-socketio'); -// const primus = require('feathers-primus'); const hooks = require('feathers-hooks'); const memory = require('feathers-memory'); const bodyParser = require('body-parser'); -// const errors = require('feathers-errors'); const errorHandler = require('feathers-errors/handler'); const auth = require('feathers-authentication'); const local = require('feathers-authentication-local');