@feathersjs/authentication-oauth 5.0.0-pre.28 → 5.0.0-pre.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/lib/index.d.ts +1 -3
- package/lib/index.js +19 -54
- package/lib/index.js.map +1 -1
- package/lib/service.d.ts +36 -0
- package/lib/service.js +141 -0
- package/lib/service.js.map +1 -0
- package/lib/strategy.js +7 -14
- package/lib/strategy.js.map +1 -1
- package/lib/utils.d.ts +13 -4
- package/lib/utils.js +89 -7
- package/lib/utils.js.map +1 -1
- package/package.json +21 -14
- package/src/index.ts +29 -66
- package/src/service.ts +177 -0
- package/src/strategy.ts +9 -16
- package/src/utils.ts +114 -8
- package/lib/express.d.ts +0 -19
- package/lib/express.js +0 -120
- package/lib/express.js.map +0 -1
- package/src/express.ts +0 -140
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,23 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [5.0.0-pre.29](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.28...v5.0.0-pre.29) (2022-09-16)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **authentication-oauth:** Fix oAuth origin and error handling ([#2752](https://github.com/feathersjs/feathers/issues/2752)) ([f7e1c33](https://github.com/feathersjs/feathers/commit/f7e1c33de1b7af0672a302d2ba6e15d997f0aa83))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* Add CORS support to oAuth, Express, Koa and generated application ([#2744](https://github.com/feathersjs/feathers/issues/2744)) ([fd218f2](https://github.com/feathersjs/feathers/commit/fd218f289f8ca4c101e9938e8683e2efef6e8131))
|
|
17
|
+
* **authentication-oauth:** Koa and transport independent oAuth authentication ([#2737](https://github.com/feathersjs/feathers/issues/2737)) ([9231525](https://github.com/feathersjs/feathers/commit/9231525a24bb790ba9c5d940f2867a9c727691c9))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
6
23
|
# [5.0.0-pre.28](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.27...v5.0.0-pre.28) (2022-08-03)
|
|
7
24
|
|
|
8
25
|
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,4 @@ import { Application } from '@feathersjs/feathers';
|
|
|
2
2
|
import { OAuthStrategy, OAuthProfile } from './strategy';
|
|
3
3
|
import { OauthSetupSettings } from './utils';
|
|
4
4
|
export { OauthSetupSettings, OAuthStrategy, OAuthProfile };
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const express: (settings?: Partial<OauthSetupSettings>) => (app: Application) => void;
|
|
7
|
-
export declare const expressOauth: (settings?: Partial<OauthSetupSettings>) => (app: Application) => void;
|
|
5
|
+
export declare const oauth: (settings?: Partial<OauthSetupSettings>) => (app: Application) => void;
|
package/lib/index.js
CHANGED
|
@@ -1,70 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const defaultsDeep_1 = __importDefault(require("lodash/defaultsDeep"));
|
|
8
|
-
const each_1 = __importDefault(require("lodash/each"));
|
|
9
|
-
const omit_1 = __importDefault(require("lodash/omit"));
|
|
3
|
+
exports.oauth = exports.OAuthStrategy = void 0;
|
|
10
4
|
const commons_1 = require("@feathersjs/commons");
|
|
5
|
+
const schema_1 = require("@feathersjs/schema");
|
|
11
6
|
const strategy_1 = require("./strategy");
|
|
12
7
|
Object.defineProperty(exports, "OAuthStrategy", { enumerable: true, get: function () { return strategy_1.OAuthStrategy; } });
|
|
13
|
-
const
|
|
8
|
+
const service_1 = require("./service");
|
|
14
9
|
const utils_1 = require("./utils");
|
|
15
10
|
const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth');
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
11
|
+
const oauth = (settings = {}) => (app) => {
|
|
12
|
+
const authService = app.defaultAuthentication ? app.defaultAuthentication(settings.authService) : null;
|
|
13
|
+
if (!authService) {
|
|
19
14
|
throw new Error('An authentication service must exist before registering @feathersjs/authentication-oauth');
|
|
20
15
|
}
|
|
21
|
-
|
|
22
|
-
if (!oauth) {
|
|
16
|
+
if (!authService.configuration.oauth) {
|
|
23
17
|
debug('No oauth configuration found in authentication configuration. Skipping oAuth setup.');
|
|
24
18
|
return;
|
|
25
19
|
}
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let host = app.get('host');
|
|
30
|
-
let protocol = 'https';
|
|
31
|
-
// Development environments commonly run on HTTP with an extended port
|
|
32
|
-
if (app.get('env') === 'development') {
|
|
33
|
-
protocol = 'http';
|
|
34
|
-
if (String(port) !== '80') {
|
|
35
|
-
host += `:${port}`;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
const grant = (0, defaultsDeep_1.default)({}, (0, omit_1.default)(oauth, ['redirect', 'origins']), {
|
|
39
|
-
defaults: {
|
|
40
|
-
prefix: '/oauth',
|
|
41
|
-
origin: `${protocol}://${host}`,
|
|
42
|
-
transport: 'session',
|
|
43
|
-
response: ['tokens', 'raw', 'profile']
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
const getUrl = (url) => {
|
|
47
|
-
const { defaults } = grant;
|
|
48
|
-
return `${defaults.origin}${defaults.prefix}/${url}`;
|
|
20
|
+
const oauthOptions = {
|
|
21
|
+
linkStrategy: 'jwt',
|
|
22
|
+
...settings
|
|
49
23
|
};
|
|
50
|
-
(0,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
debug(`Registering oAuth default strategy for '${name}'`);
|
|
56
|
-
service.register(name, new strategy_1.OAuthStrategy());
|
|
57
|
-
}
|
|
58
|
-
}
|
|
24
|
+
const serviceOptions = (0, utils_1.getServiceOptions)(authService, oauthOptions);
|
|
25
|
+
app.use('oauth/:provider', new service_1.OAuthService(authService, oauthOptions), serviceOptions);
|
|
26
|
+
const oauthService = app.service('oauth/:provider');
|
|
27
|
+
oauthService.hooks({
|
|
28
|
+
around: { all: [(0, schema_1.resolveDispatch)(), (0, service_1.redirectHook)()] }
|
|
59
29
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const express = (settings = {}) => (app) => {
|
|
64
|
-
const options = (0, utils_1.getDefaultSettings)(app, settings);
|
|
65
|
-
app.configure((0, exports.setup)(options));
|
|
66
|
-
app.configure((0, express_1.default)(options));
|
|
30
|
+
if (typeof oauthService.publish === 'function') {
|
|
31
|
+
app.service('oauth/:provider').publish(() => null);
|
|
32
|
+
}
|
|
67
33
|
};
|
|
68
|
-
exports.
|
|
69
|
-
exports.expressOauth = exports.express;
|
|
34
|
+
exports.oauth = oauth;
|
|
70
35
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,iDAAiD;AACjD,+CAAoD;AAEpD,yCAAwD;AAM3B,8FANpB,wBAAa,OAMoB;AAL1C,uCAAsD;AACtD,mCAA+D;AAE/D,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,kCAAkC,CAAC,CAAA;AAItD,MAAM,KAAK,GAChB,CAAC,WAAwC,EAAE,EAAE,EAAE,CAC/C,CAAC,GAAgB,EAAE,EAAE;IACnB,MAAM,WAAW,GAAG,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAEtG,IAAI,CAAC,WAAW,EAAE;QAChB,MAAM,IAAI,KAAK,CACb,0FAA0F,CAC3F,CAAA;KACF;IAED,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,KAAK,EAAE;QACpC,KAAK,CAAC,qFAAqF,CAAC,CAAA;QAC5F,OAAM;KACP;IAED,MAAM,YAAY,GAAG;QACnB,YAAY,EAAE,KAAK;QACnB,GAAG,QAAQ;KACZ,CAAA;IACD,MAAM,cAAc,GAAG,IAAA,yBAAiB,EAAC,WAAW,EAAE,YAAY,CAAC,CAAA;IAEnE,GAAG,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,sBAAY,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,cAAc,CAAC,CAAA;IAEvF,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAA;IAEnD,YAAY,CAAC,KAAK,CAAC;QACjB,MAAM,EAAE,EAAE,GAAG,EAAE,CAAC,IAAA,wBAAe,GAAE,EAAE,IAAA,sBAAY,GAAE,CAAC,EAAE;KACrD,CAAC,CAAA;IAEF,IAAI,OAAO,YAAY,CAAC,OAAO,KAAK,UAAU,EAAE;QAC9C,GAAG,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAA;KACnD;AACH,CAAC,CAAA;AAjCU,QAAA,KAAK,SAiCf"}
|
package/lib/service.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { HookContext, NextFunction, Params } from '@feathersjs/feathers';
|
|
2
|
+
import { FeathersError } from '@feathersjs/errors';
|
|
3
|
+
import { AuthenticationService } from '@feathersjs/authentication';
|
|
4
|
+
import { OauthSetupSettings } from './utils';
|
|
5
|
+
export declare type GrantResponse = {
|
|
6
|
+
location: string;
|
|
7
|
+
session: any;
|
|
8
|
+
state: any;
|
|
9
|
+
};
|
|
10
|
+
export declare type OAuthParams = Omit<Params, 'route'> & {
|
|
11
|
+
session: any;
|
|
12
|
+
state: Record<string, any>;
|
|
13
|
+
route: {
|
|
14
|
+
provider: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
export declare class OAuthError extends FeathersError {
|
|
18
|
+
location: string;
|
|
19
|
+
constructor(message: string, data: any, location: string);
|
|
20
|
+
}
|
|
21
|
+
export declare const redirectHook: () => (context: HookContext, next: NextFunction) => Promise<void>;
|
|
22
|
+
export declare class OAuthService {
|
|
23
|
+
service: AuthenticationService;
|
|
24
|
+
settings: OauthSetupSettings;
|
|
25
|
+
grant: any;
|
|
26
|
+
constructor(service: AuthenticationService, settings: OauthSetupSettings);
|
|
27
|
+
handler(method: string, params: OAuthParams, body?: any, override?: string): Promise<GrantResponse>;
|
|
28
|
+
authenticate(params: OAuthParams, result: GrantResponse): Promise<{
|
|
29
|
+
location: string;
|
|
30
|
+
}>;
|
|
31
|
+
find(params: OAuthParams): Promise<GrantResponse>;
|
|
32
|
+
get(override: string, params: OAuthParams): Promise<{
|
|
33
|
+
location: string;
|
|
34
|
+
}>;
|
|
35
|
+
create(data: any, params: OAuthParams): Promise<GrantResponse>;
|
|
36
|
+
}
|
package/lib/service.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.OAuthService = exports.redirectHook = exports.OAuthError = void 0;
|
|
7
|
+
const commons_1 = require("@feathersjs/commons");
|
|
8
|
+
const errors_1 = require("@feathersjs/errors");
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
10
|
+
//@ts-ignore
|
|
11
|
+
const grant_1 = __importDefault(require("grant/lib/grant"));
|
|
12
|
+
const utils_1 = require("./utils");
|
|
13
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth/services');
|
|
14
|
+
class OAuthError extends errors_1.FeathersError {
|
|
15
|
+
constructor(message, data, location) {
|
|
16
|
+
super(message, 'NotAuthenticated', 401, 'not-authenticated', data);
|
|
17
|
+
this.location = location;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.OAuthError = OAuthError;
|
|
21
|
+
const redirectHook = () => async (context, next) => {
|
|
22
|
+
try {
|
|
23
|
+
await next();
|
|
24
|
+
const { location } = context.result;
|
|
25
|
+
debug(`oAuth redirect to ${location}`);
|
|
26
|
+
if (location) {
|
|
27
|
+
context.http = {
|
|
28
|
+
...context.http,
|
|
29
|
+
location
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
if (error.location) {
|
|
35
|
+
context.http = {
|
|
36
|
+
...context.http,
|
|
37
|
+
location: error.location
|
|
38
|
+
};
|
|
39
|
+
context.result = typeof error.toJSON === 'function' ? error.toJSON() : error;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
exports.redirectHook = redirectHook;
|
|
47
|
+
class OAuthService {
|
|
48
|
+
constructor(service, settings) {
|
|
49
|
+
this.service = service;
|
|
50
|
+
this.settings = settings;
|
|
51
|
+
const config = (0, utils_1.getGrantConfig)(service);
|
|
52
|
+
this.grant = (0, grant_1.default)({ config });
|
|
53
|
+
}
|
|
54
|
+
async handler(method, params, body, override) {
|
|
55
|
+
const { session, state, query, route: { provider } } = params;
|
|
56
|
+
const result = await this.grant({
|
|
57
|
+
params: { provider, override },
|
|
58
|
+
state: state.grant,
|
|
59
|
+
session: session.grant,
|
|
60
|
+
query,
|
|
61
|
+
method,
|
|
62
|
+
body
|
|
63
|
+
});
|
|
64
|
+
session.grant = result.session;
|
|
65
|
+
state.grant = result.state;
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
async authenticate(params, result) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
const name = params.route.provider;
|
|
71
|
+
const { linkStrategy, authService } = this.settings;
|
|
72
|
+
const { accessToken, grant, query = {}, redirect } = params.session;
|
|
73
|
+
const strategy = this.service.getStrategy(name);
|
|
74
|
+
const authParams = {
|
|
75
|
+
...params,
|
|
76
|
+
authStrategies: [name],
|
|
77
|
+
authentication: accessToken
|
|
78
|
+
? {
|
|
79
|
+
strategy: linkStrategy,
|
|
80
|
+
accessToken
|
|
81
|
+
}
|
|
82
|
+
: null,
|
|
83
|
+
query,
|
|
84
|
+
redirect
|
|
85
|
+
};
|
|
86
|
+
const payload = (grant === null || grant === void 0 ? void 0 : grant.response) || ((_a = result === null || result === void 0 ? void 0 : result.session) === null || _a === void 0 ? void 0 : _a.response) || ((_b = result === null || result === void 0 ? void 0 : result.state) === null || _b === void 0 ? void 0 : _b.response) || params.query;
|
|
87
|
+
const authentication = {
|
|
88
|
+
strategy: name,
|
|
89
|
+
...payload
|
|
90
|
+
};
|
|
91
|
+
try {
|
|
92
|
+
debug(`Calling ${authService}.create authentication with strategy ${name}`);
|
|
93
|
+
const authResult = await this.service.create(authentication, authParams);
|
|
94
|
+
debug('Successful oAuth authentication, sending response');
|
|
95
|
+
const location = await strategy.getRedirect(authResult, authParams);
|
|
96
|
+
if (typeof params.session.destroy === 'function') {
|
|
97
|
+
await params.session.destroy();
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
...authResult,
|
|
101
|
+
location
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
const location = await strategy.getRedirect(error, authParams);
|
|
106
|
+
const e = new OAuthError(error.message, error.data, location);
|
|
107
|
+
if (typeof params.session.destroy === 'function') {
|
|
108
|
+
await params.session.destroy();
|
|
109
|
+
}
|
|
110
|
+
e.stack = error.stack;
|
|
111
|
+
throw e;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async find(params) {
|
|
115
|
+
const { session, query } = params;
|
|
116
|
+
const { feathers_token, redirect, ...restQuery } = query;
|
|
117
|
+
const handlerParams = {
|
|
118
|
+
...params,
|
|
119
|
+
query: restQuery
|
|
120
|
+
};
|
|
121
|
+
if (feathers_token) {
|
|
122
|
+
debug('Got feathers_token query parameter to link accounts', feathers_token);
|
|
123
|
+
session.accessToken = feathers_token;
|
|
124
|
+
}
|
|
125
|
+
session.redirect = redirect;
|
|
126
|
+
session.query = restQuery;
|
|
127
|
+
return this.handler('GET', handlerParams, {});
|
|
128
|
+
}
|
|
129
|
+
async get(override, params) {
|
|
130
|
+
const result = await this.handler('GET', params, {}, override);
|
|
131
|
+
if (override === 'callback') {
|
|
132
|
+
return this.authenticate(params, result);
|
|
133
|
+
}
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
async create(data, params) {
|
|
137
|
+
return this.handler('POST', params, data);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.OAuthService = OAuthService;
|
|
141
|
+
//# sourceMappingURL=service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";;;;;;AAAA,iDAAiD;AAEjD,+CAAkD;AAClD,6DAA6D;AAC7D,YAAY;AACZ,4DAAmC;AAGnC,mCAA4D;AAE5D,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,2CAA2C,CAAC,CAAA;AAgBtE,MAAa,UAAW,SAAQ,sBAAa;IAC3C,YAAY,OAAe,EAAE,IAAS,EAAS,QAAgB;QAC7D,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,GAAG,EAAE,mBAAmB,EAAE,IAAI,CAAC,CAAA;QADrB,aAAQ,GAAR,QAAQ,CAAQ;IAE/D,CAAC;CACF;AAJD,gCAIC;AAEM,MAAM,YAAY,GAAG,GAAG,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AE;YAClB,KAAK,CAAC,qDAAqD,EAAE,cAAc,CAAC,CAAA;YAC5E,OAAO,CAAC,WAAW,GAAG,cAAc,CAAA;SACrC;QAED,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAA;QAC3B,OAAO,CAAC,KAAK,GAAG,SAAS,CAAA;QAEzB,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED,KAAK,CAAC,GAAG,CAAC,QAAgB,EAAE,MAAmB;QAC7C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAA;QAE9D,IAAI,QAAQ,KAAK,UAAU,EAAE;YAC3B,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;SACzC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,IAAS,EAAE,MAAmB;QACzC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;IAC3C,CAAC;CACF;AArHD,oCAqHC"}
|
package/lib/strategy.js
CHANGED
|
@@ -4,13 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.OAuthStrategy = void 0;
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
const querystring_1 = __importDefault(require("querystring"));
|
|
11
7
|
const authentication_1 = require("@feathersjs/authentication");
|
|
12
8
|
const errors_1 = require("@feathersjs/errors");
|
|
13
9
|
const commons_1 = require("@feathersjs/commons");
|
|
10
|
+
const qs_1 = __importDefault(require("qs"));
|
|
14
11
|
const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth/strategy');
|
|
15
12
|
class OAuthStrategy extends authentication_1.AuthenticationBaseStrategy {
|
|
16
13
|
get configuration() {
|
|
@@ -53,12 +50,12 @@ class OAuthStrategy extends authentication_1.AuthenticationBaseStrategy {
|
|
|
53
50
|
}
|
|
54
51
|
async getAllowedOrigin(params) {
|
|
55
52
|
var _a;
|
|
56
|
-
const { redirect, origins } = this.authentication.configuration.oauth;
|
|
53
|
+
const { redirect, origins = this.app.get('origins') } = this.authentication.configuration.oauth;
|
|
57
54
|
if (Array.isArray(origins)) {
|
|
58
|
-
const referer = ((_a = params === null || params === void 0 ? void 0 : params.headers) === null || _a === void 0 ? void 0 : _a.referer) ||
|
|
55
|
+
const referer = ((_a = params === null || params === void 0 ? void 0 : params.headers) === null || _a === void 0 ? void 0 : _a.referer) || origins[0];
|
|
59
56
|
const allowedOrigin = origins.find((current) => referer.toLowerCase().startsWith(current.toLowerCase()));
|
|
60
57
|
if (!allowedOrigin) {
|
|
61
|
-
throw new errors_1.NotAuthenticated(`Referer "${referer
|
|
58
|
+
throw new errors_1.NotAuthenticated(`Referer "${referer}" is not allowed.`);
|
|
62
59
|
}
|
|
63
60
|
return allowedOrigin;
|
|
64
61
|
}
|
|
@@ -74,13 +71,9 @@ class OAuthStrategy extends authentication_1.AuthenticationBaseStrategy {
|
|
|
74
71
|
const separator = redirect.endsWith('?') ? '' : redirect.indexOf('#') !== -1 ? '?' : '#';
|
|
75
72
|
const authResult = data;
|
|
76
73
|
const query = authResult.accessToken
|
|
77
|
-
? {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
: {
|
|
81
|
-
error: data.message || 'OAuth Authentication not successful'
|
|
82
|
-
};
|
|
83
|
-
return `${redirectUrl}${separator}${querystring_1.default.stringify(query)}`;
|
|
74
|
+
? { access_token: authResult.accessToken }
|
|
75
|
+
: { error: data.message || 'OAuth Authentication not successful' };
|
|
76
|
+
return `${redirectUrl}${separator}${qs_1.default.stringify(query)}`;
|
|
84
77
|
}
|
|
85
78
|
async findEntity(profile, params) {
|
|
86
79
|
const query = await this.getEntityQuery(profile, params);
|
package/lib/strategy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;;;;AAAA
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;;;;AAAA,+DAKmC;AAEnC,+CAAqD;AACrD,iDAAoD;AACpD,4CAAmB;AAEnB,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,2CAA2C,CAAC,CAAA;AAOtE,MAAa,aAAc,SAAQ,2CAA0B;IAC3D,IAAI,aAAa;QACf,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAA;QAC9E,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAQ,CAAA;QAEtC,OAAO;YACL,MAAM;YACN,OAAO;YACP,QAAQ;YACR,GAAG,MAAM;SACV,CAAA;IACH,CAAC;IAED,IAAI,QAAQ;QACV,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAA;QAE9B,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,IAAI,CAAC,aAAa,IAAK,aAAqB,CAAC,EAAE,CAAC,CAAA;IACpF,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAqB,EAAE,OAAe;QACzD,OAAO;YACL,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,EAAE;SAC9C,CAAA;IACH,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,OAAqB,EAAE,eAAoB,EAAE,OAAe;QAC9E,OAAO;YACL,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG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AA;IACH,CAAC;CACF;AA7JD,sCA6JC"}
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import { RequestHandler } from 'express';
|
|
2
|
-
import {
|
|
1
|
+
import type { RequestHandler } from 'express';
|
|
2
|
+
import type { Middleware } from '@feathersjs/koa';
|
|
3
|
+
import type { ServiceOptions } from '@feathersjs/feathers';
|
|
4
|
+
import '@feathersjs/koa';
|
|
5
|
+
import '@feathersjs/express';
|
|
6
|
+
import { AuthenticationService } from '@feathersjs/authentication';
|
|
7
|
+
import { GrantConfig } from 'grant';
|
|
3
8
|
export interface OauthSetupSettings {
|
|
9
|
+
linkStrategy: string;
|
|
4
10
|
authService?: string;
|
|
5
11
|
expressSession?: RequestHandler;
|
|
6
|
-
|
|
12
|
+
koaSession?: Middleware;
|
|
7
13
|
}
|
|
8
|
-
export declare const
|
|
14
|
+
export declare const getGrantConfig: (service: AuthenticationService) => GrantConfig;
|
|
15
|
+
export declare const setExpressParams: RequestHandler;
|
|
16
|
+
export declare const setKoaParams: Middleware;
|
|
17
|
+
export declare const getServiceOptions: (service: AuthenticationService, settings: OauthSetupSettings) => ServiceOptions;
|
package/lib/utils.js
CHANGED
|
@@ -1,12 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
exports.getServiceOptions = exports.setKoaParams = exports.setExpressParams = exports.getGrantConfig = void 0;
|
|
7
|
+
require("@feathersjs/koa");
|
|
8
|
+
require("@feathersjs/express");
|
|
9
|
+
const cookie_session_1 = __importDefault(require("cookie-session"));
|
|
10
|
+
const koa_session_1 = __importDefault(require("koa-session"));
|
|
11
|
+
const lodash_1 = require("lodash");
|
|
12
|
+
const getGrantConfig = (service) => {
|
|
13
|
+
const { app, configuration: { oauth } } = service;
|
|
14
|
+
// Set up all the defaults
|
|
15
|
+
const port = app.get('port');
|
|
16
|
+
let host = app.get('host');
|
|
17
|
+
let protocol = 'https';
|
|
18
|
+
// Development environments commonly run on HTTP with an extended port
|
|
19
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
20
|
+
protocol = 'http';
|
|
21
|
+
if (String(port) !== '80') {
|
|
22
|
+
host += `:${port}`;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
const grant = (0, lodash_1.defaultsDeep)({}, (0, lodash_1.omit)(oauth, ['redirect', 'origins']), {
|
|
26
|
+
defaults: {
|
|
27
|
+
prefix: '/oauth',
|
|
28
|
+
origin: `${protocol}://${host}`,
|
|
29
|
+
transport: 'state',
|
|
30
|
+
response: ['tokens', 'raw', 'profile']
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
const getUrl = (url) => {
|
|
34
|
+
const { defaults } = grant;
|
|
35
|
+
return `${defaults.origin}${defaults.prefix}/${url}`;
|
|
36
|
+
};
|
|
37
|
+
(0, lodash_1.each)(grant, (value, name) => {
|
|
38
|
+
if (name !== 'defaults') {
|
|
39
|
+
value.redirect_uri = value.redirect_uri || getUrl(`${name}/callback`);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return grant;
|
|
43
|
+
};
|
|
44
|
+
exports.getGrantConfig = getGrantConfig;
|
|
45
|
+
const setExpressParams = (req, res, next) => {
|
|
46
|
+
var _a;
|
|
47
|
+
(_a = req.session).destroy || (_a.destroy = () => {
|
|
48
|
+
req.session = null;
|
|
49
|
+
});
|
|
50
|
+
req.feathers = {
|
|
51
|
+
...req.feathers,
|
|
52
|
+
session: req.session,
|
|
53
|
+
state: res.locals
|
|
54
|
+
};
|
|
55
|
+
next();
|
|
56
|
+
};
|
|
57
|
+
exports.setExpressParams = setExpressParams;
|
|
58
|
+
const setKoaParams = async (ctx, next) => {
|
|
59
|
+
var _a;
|
|
60
|
+
(_a = ctx.session).destroy || (_a.destroy = () => {
|
|
61
|
+
ctx.session = null;
|
|
62
|
+
});
|
|
63
|
+
ctx.feathers = {
|
|
64
|
+
...ctx.feathers,
|
|
65
|
+
session: ctx.session,
|
|
66
|
+
state: ctx.state
|
|
67
|
+
};
|
|
68
|
+
await next();
|
|
69
|
+
};
|
|
70
|
+
exports.setKoaParams = setKoaParams;
|
|
71
|
+
const getServiceOptions = (service, settings) => {
|
|
72
|
+
const { secret } = service.configuration;
|
|
73
|
+
const koaApp = service.app;
|
|
74
|
+
if (koaApp.context) {
|
|
75
|
+
koaApp.keys = [secret];
|
|
76
|
+
const { koaSession = (0, koa_session_1.default)({ key: 'feathers.oauth' }, koaApp) } = settings;
|
|
77
|
+
return {
|
|
78
|
+
koa: {
|
|
79
|
+
before: [koaSession, exports.setKoaParams]
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const { expressSession = (0, cookie_session_1.default)({
|
|
84
|
+
name: 'feathers.oauth',
|
|
85
|
+
keys: [secret]
|
|
86
|
+
}) } = settings;
|
|
87
|
+
return {
|
|
88
|
+
express: {
|
|
89
|
+
before: [expressSession, exports.setExpressParams]
|
|
90
|
+
}
|
|
8
91
|
};
|
|
9
|
-
return defaults;
|
|
10
92
|
};
|
|
11
|
-
exports.
|
|
93
|
+
exports.getServiceOptions = getServiceOptions;
|
|
12
94
|
//# sourceMappingURL=utils.js.map
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;AAKA,2BAAwB;AACxB,+BAA4B;AAC5B,oEAAiD;AACjD,8DAA0C;AAK1C,mCAAiD;AAS1C,MAAM,cAAc,GAAG,CAAC,OAA8B,EAAe,EAAE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IAAA,qBAAgB,EAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,EAAE,MAAa,CAAC,EAAE,GAAG,QAAQ,CAAA;QAE5F,OAAO;YACL,GAAG,EAAE;gBACH,MAAM,EAAE,CAAC,UAAU,EAAE,oBAAY,CAAC;aACnC;SACF,CAAA;KACF;IAED,MAAM,EACJ,cAAc,GAAG,IAAA,wBAAoB,EAAC;QACpC,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,CAAC,MAAM,CAAC;KACf,CAAC,EACH,GAAG,QAAQ,CAAA;IAEZ,OAAO;QACL,OAAO,EAAE;YACP,MAAM,EAAE,CAAC,cAAc,EAAE,wBAAgB,CAAC;SAC3C;KACF,CAAA;AACH,CAAC,CAAA;AA/BY,QAAA,iBAAiB,qBA+B7B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/authentication-oauth",
|
|
3
3
|
"description": "oAuth 1 and 2 authentication for Feathers. Powered by Grant.",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.29",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -54,27 +54,34 @@
|
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@feathersjs/authentication": "^5.0.0-pre.
|
|
58
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
59
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
60
|
-
"@feathersjs/express": "^5.0.0-pre.
|
|
61
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
62
|
-
"
|
|
57
|
+
"@feathersjs/authentication": "^5.0.0-pre.29",
|
|
58
|
+
"@feathersjs/commons": "^5.0.0-pre.29",
|
|
59
|
+
"@feathersjs/errors": "^5.0.0-pre.29",
|
|
60
|
+
"@feathersjs/express": "^5.0.0-pre.29",
|
|
61
|
+
"@feathersjs/feathers": "^5.0.0-pre.29",
|
|
62
|
+
"@feathersjs/koa": "^5.0.0-pre.29",
|
|
63
|
+
"@feathersjs/schema": "^5.0.0-pre.29",
|
|
64
|
+
"cookie-session": "^2.0.0",
|
|
63
65
|
"grant": "^5.4.21",
|
|
64
|
-
"
|
|
66
|
+
"koa-session": "^6.2.0",
|
|
67
|
+
"lodash": "^4.17.21",
|
|
68
|
+
"qs": "^6.11.0"
|
|
65
69
|
},
|
|
66
70
|
"devDependencies": {
|
|
67
|
-
"@feathersjs/memory": "^5.0.0-pre.
|
|
71
|
+
"@feathersjs/memory": "^5.0.0-pre.29",
|
|
72
|
+
"@types/cookie-session": "^2.0.44",
|
|
68
73
|
"@types/express": "^4.17.13",
|
|
69
|
-
"@types/
|
|
70
|
-
"@types/lodash": "^4.14.
|
|
74
|
+
"@types/koa-session": "^5.10.6",
|
|
75
|
+
"@types/lodash": "^4.14.185",
|
|
71
76
|
"@types/mocha": "^9.1.1",
|
|
72
|
-
"@types/node": "^18.
|
|
77
|
+
"@types/node": "^18.7.17",
|
|
78
|
+
"@types/tough-cookie": "^4.0.2",
|
|
73
79
|
"axios": "^0.27.2",
|
|
74
80
|
"mocha": "^10.0.0",
|
|
75
81
|
"shx": "^0.3.4",
|
|
82
|
+
"tough-cookie": "^4.1.2",
|
|
76
83
|
"ts-node": "^10.9.1",
|
|
77
|
-
"typescript": "^4.
|
|
84
|
+
"typescript": "^4.8.3"
|
|
78
85
|
},
|
|
79
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "4314dc89a41a8bbaabf00b47697bf7887861d17d"
|
|
80
87
|
}
|