@feathersjs/authentication-oauth
Advanced tools
Comparing version 4.0.0-pre.0 to 4.0.0-pre.1
@@ -6,2 +6,22 @@ # Change Log | ||
# [4.0.0-pre.1](https://github.com/feathersjs/feathers/compare/v4.0.0-pre.0...v4.0.0-pre.1) (2019-05-08) | ||
### Bug Fixes | ||
* Always require strategy parameter in authentication ([#1327](https://github.com/feathersjs/feathers/issues/1327)) ([d4a8021](https://github.com/feathersjs/feathers/commit/d4a8021)) | ||
* Improve authentication parameter handling ([#1333](https://github.com/feathersjs/feathers/issues/1333)) ([6e77204](https://github.com/feathersjs/feathers/commit/6e77204)) | ||
* Improve oAuth option handling and usability ([#1335](https://github.com/feathersjs/feathers/issues/1335)) ([adb137d](https://github.com/feathersjs/feathers/commit/adb137d)) | ||
* Merge httpStrategies and authStrategies option ([#1308](https://github.com/feathersjs/feathers/issues/1308)) ([afa4d55](https://github.com/feathersjs/feathers/commit/afa4d55)) | ||
* Rename jwtStrategies option to authStrategies ([#1305](https://github.com/feathersjs/feathers/issues/1305)) ([4aee151](https://github.com/feathersjs/feathers/commit/4aee151)) | ||
### Features | ||
* Change and *JWT methods to *accessToken ([#1304](https://github.com/feathersjs/feathers/issues/1304)) ([5ac826b](https://github.com/feathersjs/feathers/commit/5ac826b)) | ||
# [4.0.0-pre.0](https://github.com/feathersjs/feathers/compare/v3.2.0-pre.1...v4.0.0-pre.0) (2019-04-21) | ||
@@ -8,0 +28,0 @@ |
@@ -1,1 +0,1 @@ | ||
{"processes":{"364f08b8-b765-4673-bfd2-87419cb2c084":{"parent":null,"children":["d182eee4-05da-4d5e-8452-d1dfaa511656"]},"75343a4e-2816-41d1-a918-cce9789be0c7":{"parent":"d182eee4-05da-4d5e-8452-d1dfaa511656","children":[]},"d182eee4-05da-4d5e-8452-d1dfaa511656":{"parent":"364f08b8-b765-4673-bfd2-87419cb2c084","children":["75343a4e-2816-41d1-a918-cce9789be0c7"]}},"files":{"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/index.ts":["75343a4e-2816-41d1-a918-cce9789be0c7"],"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/strategy.ts":["75343a4e-2816-41d1-a918-cce9789be0c7"],"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/express.ts":["75343a4e-2816-41d1-a918-cce9789be0c7"],"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/utils.ts":["75343a4e-2816-41d1-a918-cce9789be0c7"]},"externalIds":{}} | ||
{"processes":{"6bb228c9-f305-4987-baa3-afd0c121272b":{"parent":"9657d08d-2265-4f43-9315-5a9f22863cf9","children":["93486aac-5181-458d-aefe-1d326757094b"]},"93486aac-5181-458d-aefe-1d326757094b":{"parent":"6bb228c9-f305-4987-baa3-afd0c121272b","children":[]},"9657d08d-2265-4f43-9315-5a9f22863cf9":{"parent":null,"children":["6bb228c9-f305-4987-baa3-afd0c121272b"]}},"files":{"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/index.ts":["93486aac-5181-458d-aefe-1d326757094b"],"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/strategy.ts":["93486aac-5181-458d-aefe-1d326757094b"],"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/express.ts":["93486aac-5181-458d-aefe-1d326757094b"],"/Users/daffl/Development/feathersjs/feathers/packages/authentication-oauth/src/utils.ts":["93486aac-5181-458d-aefe-1d326757094b"]},"externalIds":{}} |
@@ -163,3 +163,3 @@ /* eslint-disable */ | ||
} | ||
loadColumns(); | ||
cols = loadColumns(); | ||
loadData(); | ||
@@ -166,0 +166,0 @@ addSortIndicators(); |
@@ -163,3 +163,3 @@ /* eslint-disable */ | ||
} | ||
loadColumns(); | ||
cols = loadColumns(); | ||
loadData(); | ||
@@ -166,0 +166,0 @@ addSortIndicators(); |
@@ -26,3 +26,2 @@ "use strict"; | ||
const debug_1 = __importDefault(require("debug")); | ||
const express_session_1 = __importDefault(require("express-session")); | ||
const querystring_1 = __importDefault(require("querystring")); | ||
@@ -34,6 +33,5 @@ const express_1 = require("@feathersjs/express"); | ||
return (feathersApp) => { | ||
const { path, authService, linkStrategy } = options; | ||
const { authService, linkStrategy } = options; | ||
const app = feathersApp; | ||
const config = app.get('grant'); | ||
const secret = Math.random().toString(36).substring(7); | ||
if (!config) { | ||
@@ -43,9 +41,6 @@ debug('No grant configuration found, skipping Express oAuth setup'); | ||
} | ||
const { path } = config.defaults; | ||
const grantApp = grant(config); | ||
const authApp = express_1.original(); | ||
authApp.use(express_session_1.default({ | ||
secret, | ||
resave: true, | ||
saveUninitialized: true | ||
})); | ||
authApp.use(options.expressSession); | ||
authApp.get('/:name', (req, res) => { | ||
@@ -67,13 +62,20 @@ const { name } = req.params; | ||
const service = app.service(authService); | ||
const [strategy] = service.getStrategies(name); | ||
const sendResponse = (data) => __awaiter(this, void 0, void 0, function* () { | ||
const redirect = yield options.getRedirect(service, data); | ||
if (redirect !== null) { | ||
res.redirect(redirect); | ||
try { | ||
const redirect = yield strategy.getRedirect(data); | ||
if (redirect !== null) { | ||
res.redirect(redirect); | ||
} | ||
else if (data instanceof Error) { | ||
throw data; | ||
} | ||
else { | ||
res.json(data); | ||
} | ||
} | ||
else if (data instanceof Error) { | ||
next(data); | ||
catch (error) { | ||
debug('oAuth error', error); | ||
next(error); | ||
} | ||
else { | ||
res.json(data); | ||
} | ||
}); | ||
@@ -84,4 +86,3 @@ try { | ||
const params = { | ||
provider: 'rest', | ||
jwtStrategies: [name], | ||
authStrategies: [name], | ||
authentication: accessToken ? { | ||
@@ -100,3 +101,3 @@ strategy: linkStrategy, | ||
debug('Received oAuth authentication error', error); | ||
sendResponse(error); | ||
yield sendResponse(error); | ||
} | ||
@@ -103,0 +104,0 @@ })); |
@@ -6,2 +6,2 @@ import { Application } from '@feathersjs/feathers'; | ||
export declare const setup: (options: OauthSetupSettings) => (app: Application<any>) => void; | ||
export declare const express: (settings?: OauthSetupSettings) => (app: Application<any>) => void; | ||
export declare const express: (settings?: Partial<OauthSetupSettings>) => (app: Application<any>) => void; |
@@ -14,17 +14,18 @@ "use strict"; | ||
exports.setup = (options) => (app) => { | ||
const path = options.authService; | ||
const service = app.service(path); | ||
const authPath = options.authService; | ||
const service = app.service(authPath); | ||
if (!service) { | ||
throw new Error(`'${path}' authentication service must exist before registering @feathersjs/authentication-oauth`); | ||
throw new Error(`'${authPath}' authentication service must exist before registering @feathersjs/authentication-oauth`); | ||
} | ||
const { oauth } = service.configuration; | ||
if (!oauth) { | ||
debug(`No oauth configuration found at '${path}'. Skipping oAuth setup.`); | ||
debug(`No oauth configuration found at '${authPath}'. Skipping oAuth setup.`); | ||
return; | ||
} | ||
const { strategyNames } = service; | ||
const { path = '/auth' } = oauth.defaults; | ||
const grant = lodash_1.merge({ | ||
defaults: { | ||
path, | ||
host: `${app.get('host')}:${app.get('port')}`, | ||
path: '/auth', | ||
protocol: app.get('env') === 'production' ? 'https' : 'http', | ||
@@ -36,3 +37,3 @@ transport: 'session' | ||
if (key !== 'defaults') { | ||
value.callback = value.callback || `/auth/${key}/authenticate`; | ||
value.callback = value.callback || `${path}/${key}/authenticate`; | ||
if (!strategyNames.includes(key)) { | ||
@@ -39,0 +40,0 @@ debug(`Registering oAuth default strategy for '${key}'`); |
@@ -1,2 +0,2 @@ | ||
import { AuthenticationRequest, AuthenticationBaseStrategy } from '@feathersjs/authentication'; | ||
import { AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult } from '@feathersjs/authentication'; | ||
import { Params } from '@feathersjs/feathers'; | ||
@@ -10,4 +10,11 @@ export interface OAuthProfile { | ||
readonly entityId: string; | ||
getEntityQuery(profile: OAuthProfile, _params: Params): Promise<{ | ||
[x: string]: any; | ||
}>; | ||
getEntityData(profile: OAuthProfile, _existingEntity: any, _params: Params): Promise<{ | ||
[x: string]: any; | ||
}>; | ||
getProfile(data: AuthenticationRequest, _params: Params): Promise<any>; | ||
getCurrentEntity(params: Params): Promise<any>; | ||
getRedirect(data: AuthenticationResult | Error): Promise<string>; | ||
findEntity(profile: OAuthProfile, params: Params): Promise<any>; | ||
@@ -14,0 +21,0 @@ createEntity(profile: OAuthProfile, params: Params): Promise<any>; |
@@ -16,5 +16,5 @@ "use strict"; | ||
const client_1 = __importDefault(require("grant-profile/lib/client")); | ||
const querystring_1 = __importDefault(require("querystring")); | ||
const debug_1 = __importDefault(require("debug")); | ||
const authentication_1 = require("@feathersjs/authentication"); | ||
const errors_1 = require("@feathersjs/errors"); | ||
const debug = debug_1.default('@feathersjs/authentication-oauth/strategy'); | ||
@@ -31,2 +31,16 @@ class OAuthStrategy extends authentication_1.AuthenticationBaseStrategy { | ||
} | ||
getEntityQuery(profile, _params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
[`${this.name}Id`]: profile.sub || profile.id | ||
}; | ||
}); | ||
} | ||
getEntityData(profile, _existingEntity, _params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return { | ||
[`${this.name}Id`]: profile.sub || profile.id | ||
}; | ||
}); | ||
} | ||
/* istanbul ignore next */ | ||
@@ -50,3 +64,3 @@ getProfile(data, _params) { | ||
.authenticate(authentication, params, strategy); | ||
return authResult[entity] || null; | ||
return authResult[entity]; | ||
} | ||
@@ -56,7 +70,21 @@ return null; | ||
} | ||
getRedirect(data) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { redirect } = this.authentication.configuration.oauth; | ||
if (!redirect) { | ||
return null; | ||
} | ||
const separator = redirect.endsWith('?') ? '' : '#'; | ||
const authResult = data; | ||
const query = authResult.accessToken ? { | ||
access_token: authResult.accessToken | ||
} : { | ||
error: data.message || 'OAuth Authentication not successful' | ||
}; | ||
return redirect + separator + querystring_1.default.stringify(query); | ||
}); | ||
} | ||
findEntity(profile, params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const query = { | ||
[`${this.name}Id`]: profile.id | ||
}; | ||
const query = yield this.getEntityQuery(profile, params); | ||
debug('findEntity with query', query); | ||
@@ -71,5 +99,3 @@ const result = yield this.entityService.find(Object.assign({}, params, { query })); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const data = { | ||
[`${this.name}Id`]: profile.id | ||
}; | ||
const data = yield this.getEntityData(profile, null, params); | ||
debug('createEntity with data', data); | ||
@@ -82,5 +108,3 @@ return this.entityService.create(data, params); | ||
const id = entity[this.entityId]; | ||
const data = { | ||
[`${this.name}Id`]: profile.id | ||
}; | ||
const data = yield this.getEntityData(profile, entity, params); | ||
debug(`updateEntity with id ${id} and data`, data); | ||
@@ -92,5 +116,2 @@ return this.entityService.patch(id, data, params); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (authentication.strategy !== this.name) { | ||
throw new errors_1.NotAuthenticated('Not authenticated'); | ||
} | ||
const entity = this.configuration.entity; | ||
@@ -101,4 +122,3 @@ const profile = yield this.getProfile(authentication, params); | ||
debug(`authenticate with (existing) entity`, existingEntity); | ||
const authEntity = existingEntity === null | ||
? yield this.createEntity(profile, params) | ||
const authEntity = !existingEntity ? yield this.createEntity(profile, params) | ||
: yield this.updateEntity(existingEntity, profile, params); | ||
@@ -105,0 +125,0 @@ return { |
@@ -0,10 +1,8 @@ | ||
import { RequestHandler } from 'express'; | ||
import { Application } from '@feathersjs/feathers'; | ||
import { AuthenticationService, AuthenticationResult } from '@feathersjs/authentication'; | ||
export interface OauthSetupSettings { | ||
path?: string; | ||
authService?: string; | ||
linkStrategy?: string; | ||
getRedirect?(service: AuthenticationService, data: AuthenticationResult | Error): Promise<string>; | ||
authService: string; | ||
linkStrategy: string; | ||
expressSession: RequestHandler; | ||
} | ||
export declare const getRedirect: (service: AuthenticationService, data: Error | AuthenticationResult) => Promise<string>; | ||
export declare const getDefaultSettings: (app: Application<any>, other?: OauthSetupSettings) => OauthSetupSettings; | ||
export declare const getDefaultSettings: (app: Application<any>, other?: Partial<OauthSetupSettings>) => OauthSetupSettings; |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -14,21 +6,11 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const querystring_1 = __importDefault(require("querystring")); | ||
exports.getRedirect = (service, data) => __awaiter(this, void 0, void 0, function* () { | ||
const { redirect } = service.configuration.oauth; | ||
if (!redirect) { | ||
return null; | ||
} | ||
const separator = redirect.endsWith('?') ? '' : '#'; | ||
const authResult = data; | ||
const query = authResult.accessToken ? { | ||
access_token: authResult.accessToken | ||
} : { | ||
error: data.message || 'OAuth Authentication not successful' | ||
}; | ||
return redirect + separator + querystring_1.default.stringify(query); | ||
}); | ||
const express_session_1 = __importDefault(require("express-session")); | ||
exports.getDefaultSettings = (app, other) => { | ||
const defaults = Object.assign({ path: '/auth', authService: app.get('defaultAuthentication'), linkStrategy: 'jwt', getRedirect: exports.getRedirect }, other); | ||
const defaults = Object.assign({ authService: app.get('defaultAuthentication'), linkStrategy: 'jwt', expressSession: express_session_1.default({ | ||
secret: Math.random().toString(36).substring(7), | ||
saveUninitialized: true, | ||
resave: true | ||
}) }, other); | ||
return defaults; | ||
}; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "@feathersjs/authentication-oauth", | ||
"description": "oAuth 1 and 2 authentication for Feathers. Powered by Grant.", | ||
"version": "4.0.0-pre.0", | ||
"version": "4.0.0-pre.1", | ||
"homepage": "https://feathersjs.com", | ||
@@ -41,5 +41,5 @@ "main": "lib/", | ||
"dependencies": { | ||
"@feathersjs/authentication": "^4.0.0-pre.0", | ||
"@feathersjs/errors": "^4.0.0-pre.0", | ||
"@feathersjs/express": "^4.0.0-pre.0", | ||
"@feathersjs/authentication": "^4.0.0-pre.1", | ||
"@feathersjs/errors": "^4.0.0-pre.1", | ||
"@feathersjs/express": "^4.0.0-pre.1", | ||
"debug": "^4.1.1", | ||
@@ -52,3 +52,3 @@ "express-session": "^1.15.6", | ||
"devDependencies": { | ||
"@feathersjs/feathers": "^4.0.0-pre.0", | ||
"@feathersjs/feathers": "^4.0.0-pre.1", | ||
"@types/debug": "^4.1.3", | ||
@@ -66,3 +66,3 @@ "@types/express": "^4.16.1", | ||
}, | ||
"gitHead": "f415041c465858436a475302aabc7b8cc75adfef" | ||
"gitHead": "e8ce9116c6a4433b64ffe400585b60a9c31ba644" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
247976
1352