Skip to content

Commit

Permalink
Merge pull request #2 from feathersjs/include-commons
Browse files Browse the repository at this point in the history
include feathers-commons and use omit, pick, and makeUrl from that.
  • Loading branch information
ekryski authored and daffl committed Aug 28, 2018
1 parent 334ac59 commit 1daf1c3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 84 deletions.
5 changes: 2 additions & 3 deletions packages/authentication-oauth2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@
},
"dependencies": {
"debug": "^2.2.0",
"feathers-commons": "^0.8.5",
"feathers-errors": "^2.4.0",
"feathers-rest": "^1.5.2",
"lodash.merge": "^4.6.0",
"lodash.omit": "^4.5.0",
"lodash.pick": "^4.4.0"
"lodash.merge": "^4.6.0"
},
"devDependencies": {
"babel-cli": "^6.16.0",
Expand Down
21 changes: 10 additions & 11 deletions packages/authentication-oauth2/src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import Debug from 'debug';
import merge from 'lodash.merge';
import omit from 'lodash.omit';
import pick from 'lodash.pick';
import url from 'url';
import auth from 'feathers-authentication';
import { formatter as defaultFormatter } from 'feathers-rest';
import url from './url';
import { parse } from 'url';
import { omit, pick, makeUrl } from 'feathers-commons';
import merge from 'lodash.merge';
import defaultHandler from './express/handler';
import DefaultVerifier from './verifier';

const debug = Debug('feathers-authentication-oauth2');

const KEYS = [
const INCLUDE_KEYS = [
'entity',
'service',
'passReqToCallback',
'session'
];

const EXCLUDE_KEYS = ['Verifier', 'Strategy', 'formatter'];

export default function init (options = {}) {
return function oauth2Auth () {
const app = this;
Expand Down Expand Up @@ -45,8 +45,8 @@ export default function init (options = {}) {
const oauth2Settings = merge({
idField: `${name}Id`,
path: `/auth/${name}`,
callbackURL: url(app, `/auth/${name}/callback`)
}, pick(authSettings, KEYS), providerSettings, omit(options, ['Verifier', 'Strategy', 'formatter']));
callbackURL: makeUrl(`/auth/${name}/callback`, app)
}, pick(authSettings, ...INCLUDE_KEYS), providerSettings, omit(options, ...EXCLUDE_KEYS));

if (!oauth2Settings.clientID) {
throw new Error(`You must provide a 'clientID' in your authentication configuration or pass one explicitly`);
Expand All @@ -64,7 +64,7 @@ export default function init (options = {}) {
debug(`Registering '${name}' Express OAuth middleware`);
app.get(oauth2Settings.path, auth.express.authenticate(name));
app.get(
parse(oauth2Settings.callbackURL).pathname,
url.parse(oauth2Settings.callbackURL).pathname,
// NOTE (EK): We register failure redirect here so that we can
// retain the natural express middleware redirect ability like
// you would have with vanilla passport.
Expand Down Expand Up @@ -96,6 +96,5 @@ export default function init (options = {}) {

// Exposed Modules
Object.assign(init, {
Verifier: DefaultVerifier,
url: url
Verifier: DefaultVerifier
});
12 changes: 0 additions & 12 deletions packages/authentication-oauth2/src/url.js

This file was deleted.

7 changes: 1 addition & 6 deletions packages/authentication-oauth2/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import feathers from 'feathers';
import memory from 'feathers-memory';
import authentication from 'feathers-authentication';
import oauth2, { url, Verifier } from '../src';
import oauth2, { Verifier } from '../src';
import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
Expand All @@ -23,11 +23,6 @@ describe('feathers-authentication-oauth2', () => {
expect(typeof oauth2.Verifier).to.equal('function');
});

it('exposes url utility function', () => {
expect(typeof url).to.equal('function');
expect(typeof oauth2.url).to.equal('function');
});

describe('initialization', () => {
let app;
let config;
Expand Down
52 changes: 0 additions & 52 deletions packages/authentication-oauth2/test/url.test.js

This file was deleted.

0 comments on commit 1daf1c3

Please sign in to comment.