Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Update to new plugin infrastructure #37

Merged
merged 1 commit into from
Oct 24, 2017
Merged
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: 0 additions & 4 deletions .babelrc

This file was deleted.

7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@ node_modules
# Users Environment Variables
.lock-wscript

# The compiled/babelified modules
lib/

# Yarn lockfile
yarn.lock
/.vscode
dist/
6 changes: 2 additions & 4 deletions .istanbul.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
verbose: false
instrumentation:
root: ./src/
excludes:
- lib/
root: ./lib/
include-all-sources: true
reporting:
print: summary
Expand All @@ -14,4 +12,4 @@ reporting:
statements: [50, 80]
lines: [50, 80]
functions: [50, 80]
branches: [50, 80]
branches: [50, 80]
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.istanbul.yml
.babelrc
.idea/
src/
.vscode/
test/
!lib/
coverage/
.github/
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ language: node_js
node_js:
- node
- '6'
- '4'
addons:
code_climate:
repo_token: e343c2f43b67fdeaad91aa90c6010f2330d9440595c8337d7d757d0aa6cd25ae
Expand Down
1 change: 0 additions & 1 deletion example/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ app.configure(rest())
.use('/users', memory())
.use(errorHandler());


// Authenticate the user using the default
// email/password strategy and if successful
// return a JWT.
Expand Down
10 changes: 5 additions & 5 deletions src/hooks/hash-password.js → lib/hooks/hash-password.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import hasher from '../utils/hash';
import merge from 'lodash.merge';
import Debug from 'debug';
const hasher = require('../utils/hash');
const merge = require('lodash.merge');
const Debug = require('debug');

const debug = Debug('feathers-authentication-local:hooks:hash-password');

export default function hashPassword (options = {}) {
module.exports = function hashPassword (options = {}) {
return function (hook) {
if (hook.type !== 'before') {
return Promise.reject(new Error(`The 'hashPassword' hook should only be used as a 'before' hook.`));
Expand Down Expand Up @@ -72,4 +72,4 @@ export default function hashPassword (options = {}) {
return Promise.resolve(hook);
});
};
}
};
5 changes: 5 additions & 0 deletions lib/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const hashPassword = require('./hash-password');

module.exports = {
hashPassword
};
33 changes: 17 additions & 16 deletions src/index.js → lib/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import Debug from 'debug';
import merge from 'lodash.merge';
import omit from 'lodash.omit';
import pick from 'lodash.pick';
import hooks from './hooks';
import DefaultVerifier from './verifier';
import { Strategy as LocalStrategy } from 'passport-local';
const Debug = require('debug');
const merge = require('lodash.merge');
const omit = require('lodash.omit');
const pick = require('lodash.pick');
const hooks = require('./hooks');
const DefaultVerifier = require('./verifier');

const passportLocal = require('passport-local');

const debug = Debug('feathers-authentication-local');
const defaults = {
Expand All @@ -20,8 +21,8 @@ const KEYS = [
'session'
];

export default function init(options = {}) {
return function localAuth() {
module.exports = function init (options = {}) {
return function localAuth () {
const app = this;
const _super = app.setup;

Expand All @@ -46,22 +47,22 @@ export default function init(options = {}) {
let verifier = new Verifier(app, localSettings);

if (!verifier.verify) {
throw new Error(`Your verifier must implement a 'verify' function. It should have the same signature as a local passport verify callback.`)
throw new Error(`Your verifier must implement a 'verify' function. It should have the same signature as a local passport verify callback.`);
}

// Register 'local' strategy with passport
debug('Registering local authentication strategy with options:', localSettings);
app.passport.use(localSettings.name, new LocalStrategy(localSettings, verifier.verify.bind(verifier)));
app.passport.use(localSettings.name, new passportLocal.Strategy(localSettings, verifier.verify.bind(verifier)));
app.passport.options(localSettings.name, localSettings);

return result;
}
};
};
}
};

// Exposed Modules
Object.assign(init, {
Object.assign(module.exports, {
defaults,
hooks,
Verifier: DefaultVerifier
});
});
6 changes: 3 additions & 3 deletions src/utils/hash.js → lib/utils/hash.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import bcrypt from 'bcryptjs';
const bcrypt = require('bcryptjs');

const BCRYPT_WORK_FACTOR_BASE = 12;
const BCRYPT_DATE_BASE = 1483228800000;
const BCRYPT_WORK_INCREASE_INTERVAL = 47300000000;

export default function hasher (password) {
module.exports = function hasher (password) {
return new Promise((resolve, reject) => {
let BCRYPT_CURRENT_DATE = new Date().getTime();
let BCRYPT_WORK_INCREASE = Math.max(0, Math.floor((BCRYPT_CURRENT_DATE - BCRYPT_DATE_BASE) / BCRYPT_WORK_INCREASE_INTERVAL));
Expand All @@ -24,4 +24,4 @@ export default function hasher (password) {
});
});
});
}
};
17 changes: 8 additions & 9 deletions src/verifier.js → lib/verifier.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Debug from 'debug';
import errors from 'feathers-errors';
import bcrypt from 'bcryptjs';
import get from 'lodash.get';
import omit from 'lodash.omit';
const Debug = require('debug');
const bcrypt = require('bcryptjs');
const get = require('lodash.get');
const omit = require('lodash.omit');

const debug = Debug('feathers-authentication-local:verify');

Expand Down Expand Up @@ -43,7 +42,7 @@ class LocalVerifier {

if (!result) {
debug('Password incorrect');
return reject(false);
return reject(false); // eslint-disable-line
}

debug('Password correct');
Expand All @@ -59,7 +58,7 @@ class LocalVerifier {

// Handle bad username.
if (!entity) {
return Promise.reject(false);
return Promise.reject(false); // eslint-disable-line
}

debug(`${this.options.entity} found`);
Expand All @@ -80,7 +79,7 @@ class LocalVerifier {

if (id === null || id === undefined) {
debug('failed: the service.id was not set');
return done(new Error('the `id` property must be set on the entity service for authentication'))
return done(new Error('the `id` property must be set on the entity service for authentication'));
}

// Look up the entity
Expand All @@ -102,4 +101,4 @@ class LocalVerifier {
}
}

export default LocalVerifier;
module.exports = LocalVerifier;
1 change: 0 additions & 1 deletion mocha.opts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
--recursive test/
--compilers js:babel-core/register
Loading