@feathersjs/authentication-oauth 5.0.0-pre.1 → 5.0.0-pre.15

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 CHANGED
@@ -3,6 +3,162 @@
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.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
7
+
8
+
9
+ ### Features
10
+
11
+ * **authentication-oauth:** Allow dynamic oAuth redirect ([#2469](https://github.com/feathersjs/feathers/issues/2469)) ([b7143d4](https://github.com/feathersjs/feathers/commit/b7143d4c0fbe961e714f79512be04449b9bbd7d9))
12
+
13
+
14
+
15
+
16
+
17
+ # [5.0.0-pre.14](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.13...v5.0.0-pre.14) (2021-10-13)
18
+
19
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
20
+
21
+
22
+
23
+
24
+
25
+ # [5.0.0-pre.13](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.12...v5.0.0-pre.13) (2021-10-13)
26
+
27
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
28
+
29
+
30
+
31
+
32
+
33
+ # [5.0.0-pre.12](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.11...v5.0.0-pre.12) (2021-10-12)
34
+
35
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
36
+
37
+
38
+
39
+
40
+
41
+ # [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06)
42
+
43
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
44
+
45
+
46
+
47
+
48
+
49
+ # [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19)
50
+
51
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
52
+
53
+
54
+
55
+
56
+
57
+ # [5.0.0-pre.9](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.8...v5.0.0-pre.9) (2021-08-09)
58
+
59
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
60
+
61
+
62
+
63
+
64
+
65
+ # [5.0.0-pre.8](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.7...v5.0.0-pre.8) (2021-08-09)
66
+
67
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
68
+
69
+
70
+
71
+
72
+
73
+ # [5.0.0-pre.7](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.6...v5.0.0-pre.7) (2021-08-09)
74
+
75
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
76
+
77
+
78
+
79
+
80
+
81
+ # [5.0.0-pre.6](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.5...v5.0.0-pre.6) (2021-08-08)
82
+
83
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
84
+
85
+
86
+
87
+
88
+
89
+ # [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23)
90
+
91
+
92
+ ### Bug Fixes
93
+
94
+ * **authentication-oauth:** Omit query from internal calls ([#2398](https://github.com/feathersjs/feathers/issues/2398)) ([04c7c83](https://github.com/feathersjs/feathers/commit/04c7c83eeaa6a7466c84b958071b468ed42f0b0f))
95
+ * **koa:** Use extended query parser for compatibility ([#2397](https://github.com/feathersjs/feathers/issues/2397)) ([b2944ba](https://github.com/feathersjs/feathers/commit/b2944bac3ec6d5ecc80dc518cd4e58093692db74))
96
+
97
+
98
+ ### Features
99
+
100
+ * **adapter-commons:** Add support for params.adapter option and move memory adapter to @feathersjs/memory ([#2367](https://github.com/feathersjs/feathers/issues/2367)) ([a43e7da](https://github.com/feathersjs/feathers/commit/a43e7da22b6b981a96d1321736ea9a0cb924fb4f))
101
+
102
+
103
+
104
+
105
+
106
+ # [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13)
107
+
108
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
109
+
110
+
111
+
112
+
113
+
114
+ # [5.0.0-pre.3](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.2...v5.0.0-pre.3) (2021-04-21)
115
+
116
+
117
+ ### Bug Fixes
118
+
119
+ * **typescript:** Improve TypeScript backwards compatibility ([#2310](https://github.com/feathersjs/feathers/issues/2310)) ([f33be73](https://github.com/feathersjs/feathers/commit/f33be73fc46a533efb15df9aab0658e3240d3897))
120
+
121
+
122
+ ### Features
123
+
124
+ * **dependencies:** Remove direct debug dependency ([#2296](https://github.com/feathersjs/feathers/issues/2296)) ([501d416](https://github.com/feathersjs/feathers/commit/501d4164d30c6a126906dc640cdfdc82207ba34a))
125
+
126
+
127
+
128
+
129
+
130
+ # [5.0.0-pre.2](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.1...v5.0.0-pre.2) (2021-04-06)
131
+
132
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
133
+
134
+
135
+
136
+
137
+
138
+ # [5.0.0-beta.1](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.0...v5.0.0-beta.1) (2021-04-03)
139
+
140
+ **Note:** Version bump only for package @feathersjs/authentication-oauth
141
+
142
+
143
+
144
+
145
+
146
+ # [5.0.0-beta.0](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.1...v5.0.0-beta.0) (2021-03-28)
147
+
148
+
149
+ ### Bug Fixes
150
+
151
+ * Update Grant usage and other dependencies ([#2264](https://github.com/feathersjs/feathers/issues/2264)) ([7b0f8fa](https://github.com/feathersjs/feathers/commit/7b0f8fad252419ed0ad0bf259cdf3104d322ab60))
152
+
153
+
154
+ ### Features
155
+
156
+ * Feathers v5 core refactoring and features ([#2255](https://github.com/feathersjs/feathers/issues/2255)) ([2dafb7c](https://github.com/feathersjs/feathers/commit/2dafb7ce14ba57406aeec13d10ca45b1e709bee9))
157
+
158
+
159
+
160
+
161
+
6
162
  # [5.0.0-pre.1](https://github.com/feathersjs/feathers/compare/v4.5.11...v5.0.0-pre.1) (2020-12-17)
7
163
 
8
164
 
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Feathers
3
+ Copyright (c) 2021 Feathers
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -18,6 +18,6 @@ Refer to the [Feathers oAuth authentication API documentation](https://docs.feat
18
18
 
19
19
  ## License
20
20
 
21
- Copyright (c) 2019 [Feathers contributors](https://github.com/feathersjs/client/graphs/contributors)
21
+ Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
22
22
 
23
23
  Licensed under the [MIT license](LICENSE).
package/lib/express.d.ts CHANGED
@@ -10,6 +10,9 @@ declare module 'express-session' {
10
10
  grant: {
11
11
  [key: string]: any;
12
12
  };
13
+ headers: {
14
+ [key: string]: any;
15
+ };
13
16
  }
14
17
  }
15
18
  declare const _default: (options: OauthSetupSettings) => (feathersApp: Application) => void;
package/lib/express.js CHANGED
@@ -1,35 +1,14 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
25
5
  Object.defineProperty(exports, "__esModule", { value: true });
26
- // @ts-ignore
27
- const grant_1 = require("grant");
28
- const debug_1 = __importDefault(require("debug"));
6
+ const grant_1 = __importDefault(require("grant"));
29
7
  const express_session_1 = __importDefault(require("express-session"));
8
+ const commons_1 = require("@feathersjs/commons");
30
9
  const express_1 = require("@feathersjs/express");
31
- const grant = grant_1.express();
32
- const debug = debug_1.default('@feathersjs/authentication-oauth/express');
10
+ const grantInstance = grant_1.default.express();
11
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth/express');
33
12
  exports.default = (options) => {
34
13
  return (feathersApp) => {
35
14
  const { authService, linkStrategy } = options;
@@ -40,37 +19,44 @@ exports.default = (options) => {
40
19
  return;
41
20
  }
42
21
  const { prefix } = config.defaults;
43
- const expressSession = options.expressSession || express_session_1.default({
22
+ const expressSession = options.expressSession || (0, express_session_1.default)({
44
23
  secret: Math.random().toString(36).substring(7),
45
24
  saveUninitialized: true,
46
25
  resave: true
47
26
  });
48
- const grantApp = grant(config);
49
- const authApp = express_1.original();
27
+ const grantApp = grantInstance(config);
28
+ const authApp = (0, express_1.original)();
50
29
  authApp.use(expressSession);
51
30
  authApp.get('/:name', (req, _res, next) => {
52
- const _a = req.query, { feathers_token, redirect } = _a, query = __rest(_a, ["feathers_token", "redirect"]);
31
+ const { feathers_token, redirect, ...query } = req.query;
53
32
  if (feathers_token) {
54
33
  debug('Got feathers_token query parameter to link accounts', feathers_token);
55
34
  req.session.accessToken = feathers_token;
56
35
  }
57
36
  req.session.redirect = redirect;
58
37
  req.session.query = query;
38
+ req.session.headers = req.headers;
59
39
  next();
60
40
  });
61
- authApp.get('/:name/authenticate', (req, res, next) => __awaiter(void 0, void 0, void 0, function* () {
41
+ authApp.get('/:name/authenticate', async (req, res, next) => {
62
42
  const { name } = req.params;
63
- const { accessToken, grant, query = {}, redirect } = req.session;
43
+ const { accessToken, grant, query = {}, redirect, headers } = req.session;
64
44
  const service = app.defaultAuthentication(authService);
65
45
  const [strategy] = service.getStrategies(name);
66
- const params = Object.assign(Object.assign({}, req.feathers), { authStrategies: [name], authentication: accessToken ? {
46
+ const params = {
47
+ ...req.feathers,
48
+ authStrategies: [name],
49
+ authentication: accessToken ? {
67
50
  strategy: linkStrategy,
68
51
  accessToken
69
- } : null, query,
70
- redirect });
71
- const sendResponse = (data) => __awaiter(void 0, void 0, void 0, function* () {
52
+ } : null,
53
+ query,
54
+ redirect,
55
+ headers
56
+ };
57
+ const sendResponse = async (data) => {
72
58
  try {
73
- const redirect = yield strategy.getRedirect(data, params);
59
+ const redirect = await strategy.getRedirect(data, params);
74
60
  if (redirect !== null) {
75
61
  res.redirect(redirect);
76
62
  }
@@ -85,28 +71,31 @@ exports.default = (options) => {
85
71
  debug('oAuth error', error);
86
72
  next(error);
87
73
  }
88
- });
74
+ };
89
75
  try {
90
76
  const payload = config.defaults.transport === 'session' ?
91
77
  grant.response : req.query;
92
- const authentication = Object.assign({ strategy: name }, payload);
93
- yield new Promise((resolve, reject) => {
78
+ const authentication = {
79
+ strategy: name,
80
+ ...payload
81
+ };
82
+ await new Promise((resolve, reject) => {
94
83
  if (!req.session.destroy) {
95
84
  req.session = null;
96
85
  resolve();
97
86
  }
98
- req.session.destroy(err => err ? reject(err) : resolve());
87
+ req.session.destroy((err) => err ? reject(err) : resolve());
99
88
  });
100
89
  debug(`Calling ${authService}.create authentication with strategy ${name}`);
101
- const authResult = yield service.create(authentication, params);
90
+ const authResult = await service.create(authentication, params);
102
91
  debug('Successful oAuth authentication, sending response');
103
- yield sendResponse(authResult);
92
+ await sendResponse(authResult);
104
93
  }
105
94
  catch (error) {
106
95
  debug('Received oAuth authentication error', error.stack);
107
- yield sendResponse(error);
96
+ await sendResponse(error);
108
97
  }
109
- }));
98
+ });
110
99
  authApp.use(grantApp);
111
100
  app.set('grant', grantApp.config);
112
101
  app.use(prefix, authApp);
@@ -1 +1 @@
1
- {"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,aAAa;AACb,iCAAgD;AAChD,kDAA0B;AAC1B,sEAAsC;AAGtC,iDAG6B;AAI7B,MAAM,KAAK,GAAG,eAAY,EAAE,CAAC;AAC7B,MAAM,KAAK,GAAG,eAAK,CAAC,0CAA0C,CAAC,CAAC;AAWhE,kBAAe,CAAC,OAA2B,EAAE,EAAE;IAC7C,OAAO,CAAC,WAAwB,EAAE,EAAE;QAClC,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAC9C,MAAM,GAAG,GAAG,WAAiC,CAAC;QAC9C,MAAM,MAAM,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAEhC,IAAI,CAAC,MAAM,EAAE;YACX,KAAK,CAAC,4DAA4D,CAAC,CAAC;YACpE,OAAO;SACR;QAED,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC;QACnC,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,yBAAO,CAAC;YACvD,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/C,iBAAiB,EAAE,IAAI;YACvB,MAAM,EAAE,IAAI;SACb,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAC/B,MAAM,OAAO,GAAG,kBAAO,EAAE,CAAC;QAE1B,OAAO,CAAC,GAAG,CAAC,cAAc,CAA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qBACX;oBAED,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;gBACnE,CAAC,CAAC,CAAC;gBAEH,KAAK,CAAC,WAAW,WAAW,wCAAwC,IAAI,EAAE,CAAC,CAAC;gBAE5E,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;gBAEhE,KAAK,CAAC,mDAAmD,CAAC,CAAC;gBAE3D,MAAM,YAAY,CAAC,UAAU,CAAC,CAAC;aAChC;YAAC,OAAO,KAAU,EAAE;gBACnB,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;gBAC1D,MAAM,YAAY,CAAC,KAAK,CAAC,CAAC;aAC3B;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QAEtB,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;QAClC,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3B,CAAC,CAAC;AACJ,CAAC,CAAC"}
package/lib/index.js CHANGED
@@ -4,15 +4,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.expressOauth = exports.express = exports.setup = exports.OAuthStrategy = void 0;
7
- const debug_1 = __importDefault(require("debug"));
8
7
  const merge_1 = __importDefault(require("lodash/merge"));
9
8
  const each_1 = __importDefault(require("lodash/each"));
10
9
  const omit_1 = __importDefault(require("lodash/omit"));
10
+ const commons_1 = require("@feathersjs/commons");
11
11
  const strategy_1 = require("./strategy");
12
12
  Object.defineProperty(exports, "OAuthStrategy", { enumerable: true, get: function () { return strategy_1.OAuthStrategy; } });
13
13
  const express_1 = __importDefault(require("./express"));
14
14
  const utils_1 = require("./utils");
15
- const debug = debug_1.default('@feathersjs/authentication-oauth');
15
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth');
16
16
  const setup = (options) => (app) => {
17
17
  const service = app.defaultAuthentication ? app.defaultAuthentication(options.authService) : null;
18
18
  if (!service) {
@@ -36,19 +36,19 @@ const setup = (options) => (app) => {
36
36
  host += `:${port}`;
37
37
  }
38
38
  }
39
- const grant = merge_1.default({
39
+ const grant = (0, merge_1.default)({
40
40
  defaults: {
41
41
  prefix,
42
42
  origin: `${protocol}://${host}`,
43
43
  transport: 'session',
44
44
  response: ['tokens', 'raw', 'profile']
45
45
  }
46
- }, omit_1.default(oauth, 'redirect'));
46
+ }, (0, omit_1.default)(oauth, 'redirect'));
47
47
  const getUrl = (url) => {
48
48
  const { defaults } = grant;
49
49
  return `${defaults.origin}${prefix}/${url}`;
50
50
  };
51
- each_1.default(grant, (value, name) => {
51
+ (0, each_1.default)(grant, (value, name) => {
52
52
  if (name !== 'defaults') {
53
53
  value.callback = value.callback || getUrl(`${name}/authenticate`);
54
54
  value.redirect_uri = value.redirect_uri || getUrl(`${name}/callback`);
@@ -62,9 +62,9 @@ const setup = (options) => (app) => {
62
62
  };
63
63
  exports.setup = setup;
64
64
  const express = (settings = {}) => (app) => {
65
- const options = utils_1.getDefaultSettings(app, settings);
66
- app.configure(exports.setup(options));
67
- app.configure(express_1.default(options));
65
+ const options = (0, utils_1.getDefaultSettings)(app, settings);
66
+ app.configure((0, exports.setup)(options));
67
+ app.configure((0, express_1.default)(options));
68
68
  };
69
69
  exports.express = express;
70
70
  exports.expressOauth = exports.express;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,yDAAiC;AACjC,uDAA+B;AAC/B,uDAA+B;AAE/B,yCAAyD;AAM5B,8FANp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AAK,SAyDhB;AAEK,MAAM,OAAO,GAAG,CAAC,WAAwC,EAAE,EAAE,EAAE,CAAC,CAAC,GAAgB,EAAE,EAAE;IAC1F,MAAM,OAAO,GAAG,IAAA,0BAAkB,EAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAElD,GAAG,CAAC,SAAS,CAAC,IAAA,aAAK,EAAC,OAAO,CAAC,CAAC,CAAC;IAC9B,GAAG,CAAC,SAAS,CAAC,IAAA,iBAAY,EAAC,OAAO,CAAC,CAAC,CAAC;AACvC,CAAC,CAAC;AALW,QAAA,OAAO,WAKlB;AAEW,QAAA,YAAY,GAAG,eAAO,CAAC"}
package/lib/strategy.d.ts CHANGED
@@ -15,6 +15,7 @@ export declare class OAuthStrategy extends AuthenticationBaseStrategy {
15
15
  }>;
16
16
  getProfile(data: AuthenticationRequest, _params: Params): Promise<any>;
17
17
  getCurrentEntity(params: Params): Promise<any>;
18
+ getAllowedOrigin(params?: Params): Promise<any>;
18
19
  getRedirect(data: AuthenticationResult | Error, params?: Params): Promise<string | null>;
19
20
  findEntity(profile: OAuthProfile, params: Params): Promise<any>;
20
21
  createEntity(profile: OAuthProfile, params: Params): Promise<any>;
package/lib/strategy.js CHANGED
@@ -1,24 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
23
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
24
4
  };
@@ -27,128 +7,130 @@ exports.OAuthStrategy = void 0;
27
7
  /* eslint-disable @typescript-eslint/no-unused-vars */
28
8
  // @ts-ignore
29
9
  const querystring_1 = __importDefault(require("querystring"));
30
- const debug_1 = __importDefault(require("debug"));
31
10
  const authentication_1 = require("@feathersjs/authentication");
32
11
  const errors_1 = require("@feathersjs/errors");
33
- const debug = debug_1.default('@feathersjs/authentication-oauth/strategy');
12
+ const commons_1 = require("@feathersjs/commons");
13
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth/strategy');
34
14
  class OAuthStrategy extends authentication_1.AuthenticationBaseStrategy {
35
15
  get configuration() {
36
16
  const { entity, service, entityId, oauth } = this.authentication.configuration;
37
17
  const config = oauth[this.name];
38
- return Object.assign({ entity,
18
+ return {
19
+ entity,
39
20
  service,
40
- entityId }, config);
21
+ entityId,
22
+ ...config
23
+ };
41
24
  }
42
25
  get entityId() {
43
26
  const { entityService } = this;
44
27
  return this.configuration.entityId || (entityService && entityService.id);
45
28
  }
46
- getEntityQuery(profile, _params) {
47
- return __awaiter(this, void 0, void 0, function* () {
48
- return {
49
- [`${this.name}Id`]: profile.sub || profile.id
50
- };
51
- });
29
+ async getEntityQuery(profile, _params) {
30
+ return {
31
+ [`${this.name}Id`]: profile.sub || profile.id
32
+ };
52
33
  }
53
- getEntityData(profile, _existingEntity, _params) {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- return {
56
- [`${this.name}Id`]: profile.sub || profile.id
57
- };
58
- });
34
+ async getEntityData(profile, _existingEntity, _params) {
35
+ return {
36
+ [`${this.name}Id`]: profile.sub || profile.id
37
+ };
59
38
  }
60
- getProfile(data, _params) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- return data.profile;
63
- });
39
+ async getProfile(data, _params) {
40
+ return data.profile;
64
41
  }
65
- getCurrentEntity(params) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const { authentication } = params;
68
- const { entity } = this.configuration;
69
- if (authentication && authentication.strategy) {
70
- debug('getCurrentEntity with authentication', authentication);
71
- const { strategy } = authentication;
72
- const authResult = yield this.authentication
73
- .authenticate(authentication, params, strategy);
74
- return authResult[entity];
75
- }
76
- return null;
77
- });
42
+ async getCurrentEntity(params) {
43
+ const { authentication } = params;
44
+ const { entity } = this.configuration;
45
+ if (authentication && authentication.strategy) {
46
+ debug('getCurrentEntity with authentication', authentication);
47
+ const { strategy } = authentication;
48
+ const authResult = await this.authentication
49
+ .authenticate(authentication, params, strategy);
50
+ return authResult[entity];
51
+ }
52
+ return null;
78
53
  }
79
- getRedirect(data, params) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- const queryRedirect = (params && params.redirect) || '';
82
- const { redirect } = this.authentication.configuration.oauth;
83
- if (!redirect) {
84
- return null;
54
+ async getAllowedOrigin(params) {
55
+ var _a;
56
+ const { redirect, origins } = this.authentication.configuration.oauth;
57
+ 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) || '';
59
+ const allowedOrigin = origins.find(current => referer.toLowerCase().startsWith(current.toLowerCase()));
60
+ if (!allowedOrigin) {
61
+ throw new errors_1.NotAuthenticated(`Referer "${referer || '[header not available]'}" not allowed.`);
85
62
  }
86
- const redirectUrl = `${redirect}${queryRedirect}`;
87
- const separator = redirect.endsWith('?') ? '' :
88
- (redirect.indexOf('#') !== -1 ? '?' : '#');
89
- const authResult = data;
90
- const query = authResult.accessToken ? {
91
- access_token: authResult.accessToken
92
- } : {
93
- error: data.message || 'OAuth Authentication not successful'
94
- };
95
- return `${redirectUrl}${separator}${querystring_1.default.stringify(query)}`;
96
- });
63
+ return allowedOrigin;
64
+ }
65
+ return redirect;
97
66
  }
98
- findEntity(profile, params) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- const query = yield this.getEntityQuery(profile, params);
101
- debug('findEntity with query', query);
102
- const result = yield this.entityService.find(Object.assign(Object.assign({}, params), { query }));
103
- const [entity = null] = result.data ? result.data : result;
104
- debug('findEntity returning', entity);
105
- return entity;
106
- });
67
+ async getRedirect(data, params) {
68
+ const queryRedirect = (params && params.redirect) || '';
69
+ const redirect = await this.getAllowedOrigin(params);
70
+ if (!redirect) {
71
+ return null;
72
+ }
73
+ const redirectUrl = `${redirect}${queryRedirect}`;
74
+ const separator = redirect.endsWith('?') ? '' :
75
+ (redirect.indexOf('#') !== -1 ? '?' : '#');
76
+ const authResult = data;
77
+ const query = authResult.accessToken ? {
78
+ access_token: authResult.accessToken
79
+ } : {
80
+ error: data.message || 'OAuth Authentication not successful'
81
+ };
82
+ return `${redirectUrl}${separator}${querystring_1.default.stringify(query)}`;
107
83
  }
108
- createEntity(profile, params) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- const data = yield this.getEntityData(profile, null, params);
111
- debug('createEntity with data', data);
112
- return this.entityService.create(data, params);
84
+ async findEntity(profile, params) {
85
+ const query = await this.getEntityQuery(profile, params);
86
+ debug('findEntity with query', query);
87
+ const result = await this.entityService.find({
88
+ ...params,
89
+ query
113
90
  });
91
+ const [entity = null] = result.data ? result.data : result;
92
+ debug('findEntity returning', entity);
93
+ return entity;
114
94
  }
115
- updateEntity(entity, profile, params) {
116
- return __awaiter(this, void 0, void 0, function* () {
117
- const id = entity[this.entityId];
118
- const data = yield this.getEntityData(profile, entity, params);
119
- debug(`updateEntity with id ${id} and data`, data);
120
- return this.entityService.patch(id, data, params);
121
- });
95
+ async createEntity(profile, params) {
96
+ const data = await this.getEntityData(profile, null, params);
97
+ debug('createEntity with data', data);
98
+ return this.entityService.create(data, commons_1._.omit(params, 'query'));
122
99
  }
123
- getEntity(result, params) {
124
- return __awaiter(this, void 0, void 0, function* () {
125
- const { entityService } = this;
126
- const { entityId = entityService.id, entity } = this.configuration;
127
- if (!entityId || result[entityId] === undefined) {
128
- throw new errors_1.NotAuthenticated('Could not get oAuth entity');
129
- }
130
- if (!params.provider) {
131
- return result;
132
- }
133
- return entityService.get(result[entityId], Object.assign(Object.assign({}, params), { [entity]: result }));
134
- });
100
+ async updateEntity(entity, profile, params) {
101
+ const id = entity[this.entityId];
102
+ const data = await this.getEntityData(profile, entity, params);
103
+ debug(`updateEntity with id ${id} and data`, data);
104
+ return this.entityService.patch(id, data, commons_1._.omit(params, 'query'));
135
105
  }
136
- authenticate(authentication, originalParams) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- const entity = this.configuration.entity;
139
- const { provider } = originalParams, params = __rest(originalParams, ["provider"]);
140
- const profile = yield this.getProfile(authentication, params);
141
- const existingEntity = (yield this.findEntity(profile, params))
142
- || (yield this.getCurrentEntity(params));
143
- debug('authenticate with (existing) entity', existingEntity);
144
- const authEntity = !existingEntity ? yield this.createEntity(profile, params)
145
- : yield this.updateEntity(existingEntity, profile, params);
146
- return {
147
- authentication: { strategy: this.name },
148
- [entity]: yield this.getEntity(authEntity, originalParams)
149
- };
106
+ async getEntity(result, params) {
107
+ const { entityService } = this;
108
+ const { entityId = entityService.id, entity } = this.configuration;
109
+ if (!entityId || result[entityId] === undefined) {
110
+ throw new errors_1.NotAuthenticated('Could not get oAuth entity');
111
+ }
112
+ if (!params.provider) {
113
+ return result;
114
+ }
115
+ return entityService.get(result[entityId], {
116
+ ...commons_1._.omit(params, 'query'),
117
+ [entity]: result
150
118
  });
151
119
  }
120
+ async authenticate(authentication, originalParams) {
121
+ const entity = this.configuration.entity;
122
+ const { provider, ...params } = originalParams;
123
+ const profile = await this.getProfile(authentication, params);
124
+ const existingEntity = await this.findEntity(profile, params)
125
+ || await this.getCurrentEntity(params);
126
+ debug('authenticate with (existing) entity', existingEntity);
127
+ const authEntity = !existingEntity ? await this.createEntity(profile, params)
128
+ : await this.updateEntity(existingEntity, profile, params);
129
+ return {
130
+ authentication: { strategy: this.name },
131
+ [entity]: await this.getEntity(authEntity, originalParams)
132
+ };
133
+ }
152
134
  }
153
135
  exports.OAuthStrategy = OAuthStrategy;
154
136
  //# sourceMappingURL=strategy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,aAAa;AACb,8DAAsC;AACtC,kDAA0B;AAC1B,+DAEoC;AAEpC,+CAAsD;AAEtD,MAAM,KAAK,GAAG,eAAK,CAAC,2CAA2C,CAAC,CAAC;AAOjE,MAAa,aAAc,SAAQ,2CAA0B;IAC3D,IAAI,aAAa;QACf,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC;QAC/E,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEhC,uBACE,MAAM;YACN,OAAO;YACP,QAAQ,IACL,MAAM,EACT;IACJ,CAAC;IAED,IAAI,QAAQ;QACV,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAE/B,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,IAAI,CAAC,aAAa,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IAEK,cAAc,CAAE,OAAqB,EAAE,OAAe;;YAC1D,OAAO;gBACL,CAAC,GAAG,IAAI,CAAC,IAAI,IAAI,CAAC,EAAE,OAAO,CAAC,GAAG,IAAI,OAAO,CAAC,EAAE;aAC9C,CAAC;QACJ,CAAC;KAAA;IAEK,aAAa,CAAE,OAAqB,EAAE,eAAoB,EAAE,OAAe;;YAC/E,OAAO;gBACL,CAAC,GAAG,IAAI,CA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AAC,YAAY,CAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;QAE7D,OAAO;YACL,cAAc,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE;YACvC,CAAC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,cAAc,CAAC;SAC3D,CAAC;IACJ,CAAC;CACF;AA9JD,sCA8JC"}
package/lib/utils.js CHANGED
@@ -2,7 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getDefaultSettings = void 0;
4
4
  const getDefaultSettings = (_app, other) => {
5
- const defaults = Object.assign({ linkStrategy: 'jwt' }, other);
5
+ const defaults = {
6
+ linkStrategy: 'jwt',
7
+ ...other
8
+ };
6
9
  return defaults;
7
10
  };
8
11
  exports.getDefaultSettings = getDefaultSettings;
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AASO,MAAM,kBAAkB,GAAG,CAAC,IAAiB,EAAE,KAAmC,EAAE,EAAE;IAC3F,MAAM,QAAQ,mBACZ,YAAY,EAAE,KAAK,IAChB,KAAK,CACT,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AASO,MAAM,kBAAkB,GAAG,CAAC,IAAiB,EAAE,KAAmC,EAAE,EAAE;IAC3F,MAAM,QAAQ,GAAuB;QACnC,YAAY,EAAE,KAAK;QACnB,GAAG,KAAK;KACT,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC;AAPW,QAAA,kBAAkB,sBAO7B"}
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.1",
4
+ "version": "5.0.0-pre.15",
5
5
  "homepage": "https://feathersjs.com",
6
6
  "main": "lib/",
7
7
  "types": "lib/",
@@ -28,7 +28,7 @@
28
28
  "url": "https://github.com/feathersjs/feathers/issues"
29
29
  },
30
30
  "engines": {
31
- "node": ">= 10"
31
+ "node": ">= 12"
32
32
  },
33
33
  "files": [
34
34
  "CHANGELOG.md",
@@ -52,28 +52,27 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@feathersjs/authentication": "^5.0.0-pre.1",
56
- "@feathersjs/errors": "^5.0.0-pre.1",
57
- "@feathersjs/express": "^5.0.0-pre.1",
58
- "@feathersjs/feathers": "^5.0.0-pre.1",
59
- "debug": "^4.3.1",
60
- "express-session": "^1.17.1",
61
- "grant": "^5.4.9",
62
- "lodash": "^4.17.20"
55
+ "@feathersjs/authentication": "^5.0.0-pre.15",
56
+ "@feathersjs/commons": "^5.0.0-pre.15",
57
+ "@feathersjs/errors": "^5.0.0-pre.15",
58
+ "@feathersjs/express": "^5.0.0-pre.15",
59
+ "@feathersjs/feathers": "^5.0.0-pre.15",
60
+ "express-session": "^1.17.2",
61
+ "grant": "^5.4.18",
62
+ "lodash": "^4.17.21"
63
63
  },
64
64
  "devDependencies": {
65
- "@feathersjs/adapter-memory": "^5.0.0-pre.1",
66
- "@types/debug": "^4.1.5",
67
- "@types/express": "^4.17.9",
68
- "@types/express-session": "^1.17.3",
69
- "@types/lodash": "^4.14.165",
70
- "@types/mocha": "^8.0.4",
71
- "@types/node": "^14.14.10",
72
- "axios": "^0.21.0",
73
- "mocha": "^8.2.1",
65
+ "@feathersjs/memory": "^5.0.0-pre.15",
66
+ "@types/express": "^4.17.13",
67
+ "@types/express-session": "^1.17.4",
68
+ "@types/lodash": "^4.14.176",
69
+ "@types/mocha": "^9.0.0",
70
+ "@types/node": "^16.11.6",
71
+ "axios": "^0.24.0",
72
+ "mocha": "^9.1.3",
74
73
  "shx": "^0.3.3",
75
- "ts-node": "^9.1.0",
76
- "typescript": "^4.1.2"
74
+ "ts-node": "^10.4.0",
75
+ "typescript": "^4.4.4"
77
76
  },
78
- "gitHead": "3756506935c520fc50d4be416ff649c2158afdac"
77
+ "gitHead": "8008bf4f8529a2a40b6a2f976c1f43ae13675693"
79
78
  }
package/src/express.ts CHANGED
@@ -1,18 +1,18 @@
1
- // @ts-ignore
2
- import { express as grantExpress } from 'grant';
3
- import Debug from 'debug';
1
+ import grant from 'grant';
4
2
  import session from 'express-session';
3
+ import { Request, Response, NextFunction } from 'express';
4
+ import { createDebug } from '@feathersjs/commons';
5
5
  import { Application } from '@feathersjs/feathers';
6
6
  import { AuthenticationResult } from '@feathersjs/authentication';
7
7
  import {
8
8
  Application as ExpressApplication,
9
- original as express
9
+ original as originalExpress
10
10
  } from '@feathersjs/express';
11
11
  import { OauthSetupSettings } from './utils';
12
12
  import { OAuthStrategy } from './strategy';
13
13
 
14
- const grant = grantExpress();
15
- const debug = Debug('@feathersjs/authentication-oauth/express');
14
+ const grantInstance = grant.express();
15
+ const debug = createDebug('@feathersjs/authentication-oauth/express');
16
16
 
17
17
  declare module 'express-session' {
18
18
  interface SessionData {
@@ -20,6 +20,7 @@ declare module 'express-session' {
20
20
  accessToken: string;
21
21
  query: { [key: string]: any };
22
22
  grant: { [key: string]: any };
23
+ headers: { [key: string]: any };
23
24
  }
24
25
  }
25
26
 
@@ -40,12 +41,12 @@ export default (options: OauthSetupSettings) => {
40
41
  saveUninitialized: true,
41
42
  resave: true
42
43
  });
43
- const grantApp = grant(config);
44
- const authApp = express();
44
+ const grantApp = grantInstance(config);
45
+ const authApp = originalExpress();
45
46
 
46
47
  authApp.use(expressSession);
47
48
 
48
- authApp.get('/:name', (req, _res, next) => {
49
+ authApp.get('/:name', (req: Request, _res: Response, next: NextFunction) => {
49
50
  const { feathers_token, redirect, ...query } = req.query;
50
51
 
51
52
  if (feathers_token) {
@@ -54,13 +55,14 @@ export default (options: OauthSetupSettings) => {
54
55
  }
55
56
  req.session.redirect = redirect as string;
56
57
  req.session.query = query;
58
+ req.session.headers = req.headers;
57
59
 
58
60
  next()
59
61
  });
60
62
 
61
- authApp.get('/:name/authenticate', async (req, res, next) => {
63
+ authApp.get('/:name/authenticate', async (req: Request, res: Response, next: NextFunction) => {
62
64
  const { name } = req.params ;
63
- const { accessToken, grant, query = {}, redirect } = req.session;
65
+ const { accessToken, grant, query = {}, redirect, headers } = req.session;
64
66
  const service = app.defaultAuthentication(authService);
65
67
  const [ strategy ] = service.getStrategies(name) as OAuthStrategy[];
66
68
  const params = {
@@ -71,7 +73,8 @@ export default (options: OauthSetupSettings) => {
71
73
  accessToken
72
74
  } : null,
73
75
  query,
74
- redirect
76
+ redirect,
77
+ headers
75
78
  };
76
79
  const sendResponse = async (data: AuthenticationResult|Error) => {
77
80
  try {
@@ -84,7 +87,7 @@ export default (options: OauthSetupSettings) => {
84
87
  } else {
85
88
  res.json(data);
86
89
  }
87
- } catch (error) {
90
+ } catch (error: any) {
88
91
  debug('oAuth error', error);
89
92
  next(error);
90
93
  }
@@ -104,7 +107,7 @@ export default (options: OauthSetupSettings) => {
104
107
  resolve();
105
108
  }
106
109
 
107
- req.session.destroy(err => err ? reject(err) : resolve());
110
+ req.session.destroy((err: any) => err ? reject(err) : resolve());
108
111
  });
109
112
 
110
113
  debug(`Calling ${authService}.create authentication with strategy ${name}`);
@@ -114,7 +117,7 @@ export default (options: OauthSetupSettings) => {
114
117
  debug('Successful oAuth authentication, sending response');
115
118
 
116
119
  await sendResponse(authResult);
117
- } catch (error) {
120
+ } catch (error: any) {
118
121
  debug('Received oAuth authentication error', error.stack);
119
122
  await sendResponse(error);
120
123
  }
package/src/index.ts CHANGED
@@ -1,13 +1,13 @@
1
- import Debug from 'debug';
2
1
  import merge from 'lodash/merge';
3
2
  import each from 'lodash/each';
4
3
  import omit from 'lodash/omit';
4
+ import { createDebug } from '@feathersjs/commons';
5
5
  import { Application } from '@feathersjs/feathers';
6
6
  import { OAuthStrategy, OAuthProfile } from './strategy';
7
7
  import { default as setupExpress } from './express';
8
8
  import { OauthSetupSettings, getDefaultSettings } from './utils';
9
9
 
10
- const debug = Debug('@feathersjs/authentication-oauth');
10
+ const debug = createDebug('@feathersjs/authentication-oauth');
11
11
 
12
12
  export { OauthSetupSettings, OAuthStrategy, OAuthProfile };
13
13
 
package/src/strategy.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  /* eslint-disable @typescript-eslint/no-unused-vars */
2
2
  // @ts-ignore
3
3
  import querystring from 'querystring';
4
- import Debug from 'debug';
5
4
  import {
6
5
  AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult
7
6
  } from '@feathersjs/authentication';
8
7
  import { Params } from '@feathersjs/feathers';
9
8
  import { NotAuthenticated } from '@feathersjs/errors';
9
+ import { createDebug, _ } from '@feathersjs/commons';
10
10
 
11
- const debug = Debug('@feathersjs/authentication-oauth/strategy');
11
+ const debug = createDebug('@feathersjs/authentication-oauth/strategy');
12
12
 
13
13
  export interface OAuthProfile {
14
14
  id?: string|number;
@@ -31,7 +31,7 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
31
31
  get entityId (): string {
32
32
  const { entityService } = this;
33
33
 
34
- return this.configuration.entityId || (entityService && entityService.id);
34
+ return this.configuration.entityId || (entityService && (entityService as any).id);
35
35
  }
36
36
 
37
37
  async getEntityQuery (profile: OAuthProfile, _params: Params) {
@@ -67,9 +67,26 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
67
67
  return null;
68
68
  }
69
69
 
70
+ async getAllowedOrigin (params?: Params) {
71
+ const { redirect, origins } = this.authentication.configuration.oauth;
72
+
73
+ if (Array.isArray(origins)) {
74
+ const referer = params?.headers?.referer || '';
75
+ const allowedOrigin = origins.find(current => referer.toLowerCase().startsWith(current.toLowerCase()));
76
+
77
+ if(!allowedOrigin) {
78
+ throw new NotAuthenticated(`Referer "${referer || '[header not available]'}" not allowed.`);
79
+ }
80
+
81
+ return allowedOrigin;
82
+ }
83
+
84
+ return redirect;
85
+ }
86
+
70
87
  async getRedirect (data: AuthenticationResult|Error, params?: Params): Promise<string | null> {
71
88
  const queryRedirect = (params && params.redirect) || '';
72
- const { redirect } = this.authentication.configuration.oauth;
89
+ const redirect = await this.getAllowedOrigin(params);
73
90
 
74
91
  if (!redirect) {
75
92
  return null;
@@ -109,7 +126,7 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
109
126
 
110
127
  debug('createEntity with data', data);
111
128
 
112
- return this.entityService.create(data, params);
129
+ return this.entityService.create(data, _.omit(params, 'query'));
113
130
  }
114
131
 
115
132
  async updateEntity (entity: any, profile: OAuthProfile, params: Params) {
@@ -118,12 +135,12 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
118
135
 
119
136
  debug(`updateEntity with id ${id} and data`, data);
120
137
 
121
- return this.entityService.patch(id, data, params);
138
+ return this.entityService.patch(id, data, _.omit(params, 'query'));
122
139
  }
123
140
 
124
141
  async getEntity (result: any, params: Params) {
125
142
  const { entityService } = this;
126
- const { entityId = entityService.id, entity } = this.configuration;
143
+ const { entityId = (entityService as any).id, entity } = this.configuration;
127
144
 
128
145
  if (!entityId || result[entityId] === undefined) {
129
146
  throw new NotAuthenticated('Could not get oAuth entity');
@@ -134,7 +151,7 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
134
151
  }
135
152
 
136
153
  return entityService.get(result[entityId], {
137
- ...params,
154
+ ..._.omit(params, 'query'),
138
155
  [entity]: result
139
156
  });
140
157
  }