@feathersjs/authentication-oauth 5.0.0-pre.2 → 5.0.0-pre.20
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 +180 -0
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/express.d.ts +3 -0
- package/lib/express.js +46 -42
- package/lib/express.js.map +1 -1
- package/lib/index.js +9 -9
- package/lib/index.js.map +1 -1
- package/lib/strategy.d.ts +4 -3
- package/lib/strategy.js +99 -117
- package/lib/strategy.js.map +1 -1
- package/lib/utils.js +4 -1
- package/lib/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/express.ts +28 -13
- package/src/index.ts +5 -5
- package/src/strategy.ts +26 -9
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,186 @@
|
|
|
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.20](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.19...v5.0.0-pre.20) (2022-05-04)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **authentication-oauth:** Don't send origins in Grant's config, as it will be considered another provider ([#2617](https://github.com/feathersjs/feathers/issues/2617)) ([ae3dddd](https://github.com/feathersjs/feathers/commit/ae3dddd8a654924465512d56b4651413912c6932))
|
|
12
|
+
* **dependencies:** Lock monorepo package version numbers ([#2623](https://github.com/feathersjs/feathers/issues/2623)) ([5640c10](https://github.com/feathersjs/feathers/commit/5640c1020cc139994e695d658c08bad3494db507))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# [5.0.0-pre.19](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.18...v5.0.0-pre.19) (2022-05-01)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Bug Fixes
|
|
22
|
+
|
|
23
|
+
* **authentication-oauth:** Fix issue with overriding the default Grant configuration ([#2615](https://github.com/feathersjs/feathers/issues/2615)) ([b345857](https://github.com/feathersjs/feathers/commit/b3458578532f9750de2940aeb8afdc75cb0b46f2))
|
|
24
|
+
* **authentication-oauth:** Make oAuth authentication work with cookie-session ([#2614](https://github.com/feathersjs/feathers/issues/2614)) ([9f10bfc](https://github.com/feathersjs/feathers/commit/9f10bfc75083d5bcabea77cfb385aa3965cdf6d6))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### Features
|
|
28
|
+
|
|
29
|
+
* **typescript:** Improve params and query typeability ([#2600](https://github.com/feathersjs/feathers/issues/2600)) ([df28b76](https://github.com/feathersjs/feathers/commit/df28b7619161f1df5e700326f52cca1a92dc5d28))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# [5.0.0-pre.18](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.17...v5.0.0-pre.18) (2022-04-11)
|
|
36
|
+
|
|
37
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
# [5.0.0-pre.17](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.16...v5.0.0-pre.17) (2022-02-15)
|
|
44
|
+
|
|
45
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# [5.0.0-pre.16](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.15...v5.0.0-pre.16) (2022-01-12)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Bug Fixes
|
|
55
|
+
|
|
56
|
+
* **authentication-oauth:** OAuth redirect lost sometimes due to session store race ([#2514](https://github.com/feathersjs/feathers/issues/2514)) ([#2515](https://github.com/feathersjs/feathers/issues/2515)) ([6109c44](https://github.com/feathersjs/feathers/commit/6109c44428c6b8f6bb4e089be760ea1a4ef3d01e))
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# [5.0.0-pre.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Features
|
|
66
|
+
|
|
67
|
+
* **authentication-oauth:** Allow dynamic oAuth redirect ([#2469](https://github.com/feathersjs/feathers/issues/2469)) ([b7143d4](https://github.com/feathersjs/feathers/commit/b7143d4c0fbe961e714f79512be04449b9bbd7d9))
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# [5.0.0-pre.14](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.13...v5.0.0-pre.14) (2021-10-13)
|
|
74
|
+
|
|
75
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# [5.0.0-pre.13](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.12...v5.0.0-pre.13) (2021-10-13)
|
|
82
|
+
|
|
83
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# [5.0.0-pre.12](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.11...v5.0.0-pre.12) (2021-10-12)
|
|
90
|
+
|
|
91
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
# [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06)
|
|
98
|
+
|
|
99
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
# [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19)
|
|
106
|
+
|
|
107
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# [5.0.0-pre.9](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.8...v5.0.0-pre.9) (2021-08-09)
|
|
114
|
+
|
|
115
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
# [5.0.0-pre.8](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.7...v5.0.0-pre.8) (2021-08-09)
|
|
122
|
+
|
|
123
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
# [5.0.0-pre.7](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.6...v5.0.0-pre.7) (2021-08-09)
|
|
130
|
+
|
|
131
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# [5.0.0-pre.6](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.5...v5.0.0-pre.6) (2021-08-08)
|
|
138
|
+
|
|
139
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
# [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### Bug Fixes
|
|
149
|
+
|
|
150
|
+
* **authentication-oauth:** Omit query from internal calls ([#2398](https://github.com/feathersjs/feathers/issues/2398)) ([04c7c83](https://github.com/feathersjs/feathers/commit/04c7c83eeaa6a7466c84b958071b468ed42f0b0f))
|
|
151
|
+
* **koa:** Use extended query parser for compatibility ([#2397](https://github.com/feathersjs/feathers/issues/2397)) ([b2944ba](https://github.com/feathersjs/feathers/commit/b2944bac3ec6d5ecc80dc518cd4e58093692db74))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
### Features
|
|
155
|
+
|
|
156
|
+
* **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))
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
# [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13)
|
|
163
|
+
|
|
164
|
+
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
# [5.0.0-pre.3](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.2...v5.0.0-pre.3) (2021-04-21)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
### Bug Fixes
|
|
174
|
+
|
|
175
|
+
* **typescript:** Improve TypeScript backwards compatibility ([#2310](https://github.com/feathersjs/feathers/issues/2310)) ([f33be73](https://github.com/feathersjs/feathers/commit/f33be73fc46a533efb15df9aab0658e3240d3897))
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
### Features
|
|
179
|
+
|
|
180
|
+
* **dependencies:** Remove direct debug dependency ([#2296](https://github.com/feathersjs/feathers/issues/2296)) ([501d416](https://github.com/feathersjs/feathers/commit/501d4164d30c6a126906dc640cdfdc82207ba34a))
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
6
186
|
# [5.0.0-pre.2](https://github.com/feathersjs/feathers/compare/v5.0.0-beta.1...v5.0.0-pre.2) (2021-04-06)
|
|
7
187
|
|
|
8
188
|
**Note:** Version bump only for package @feathersjs/authentication-oauth
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# @feathersjs/authentication-oauth
|
|
2
2
|
|
|
3
3
|
[](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
|
|
4
|
-
[](https://david-dm.org/feathersjs/feathers?path=packages/authentication-oauth)
|
|
5
4
|
[](https://www.npmjs.com/package/@feathersjs/authentication-oauth)
|
|
5
|
+
[](https://discord.gg/qa8kez8QBx)
|
|
6
6
|
|
|
7
7
|
> OAuth 1 and 2 authentication for Feathers. Powered by Grant.
|
|
8
8
|
|
|
@@ -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)
|
|
21
|
+
Copyright (c) 2022 [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
package/lib/express.js
CHANGED
|
@@ -1,34 +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
6
|
const grant_1 = __importDefault(require("grant"));
|
|
27
|
-
const debug_1 = __importDefault(require("debug"));
|
|
28
7
|
const express_session_1 = __importDefault(require("express-session"));
|
|
8
|
+
const commons_1 = require("@feathersjs/commons");
|
|
29
9
|
const express_1 = require("@feathersjs/express");
|
|
30
10
|
const grantInstance = grant_1.default.express();
|
|
31
|
-
const debug =
|
|
11
|
+
const debug = (0, commons_1.createDebug)('@feathersjs/authentication-oauth/express');
|
|
32
12
|
exports.default = (options) => {
|
|
33
13
|
return (feathersApp) => {
|
|
34
14
|
const { authService, linkStrategy } = options;
|
|
@@ -39,37 +19,56 @@ exports.default = (options) => {
|
|
|
39
19
|
return;
|
|
40
20
|
}
|
|
41
21
|
const { prefix } = config.defaults;
|
|
42
|
-
const expressSession = options.expressSession || express_session_1.default({
|
|
22
|
+
const expressSession = options.expressSession || (0, express_session_1.default)({
|
|
43
23
|
secret: Math.random().toString(36).substring(7),
|
|
44
24
|
saveUninitialized: true,
|
|
45
25
|
resave: true
|
|
46
26
|
});
|
|
47
27
|
const grantApp = grantInstance(config);
|
|
48
|
-
const authApp = express_1.original();
|
|
28
|
+
const authApp = (0, express_1.original)();
|
|
49
29
|
authApp.use(expressSession);
|
|
50
30
|
authApp.get('/:name', (req, _res, next) => {
|
|
51
|
-
const
|
|
31
|
+
const { feathers_token, redirect, ...query } = req.query;
|
|
52
32
|
if (feathers_token) {
|
|
53
33
|
debug('Got feathers_token query parameter to link accounts', feathers_token);
|
|
54
34
|
req.session.accessToken = feathers_token;
|
|
55
35
|
}
|
|
56
36
|
req.session.redirect = redirect;
|
|
57
37
|
req.session.query = query;
|
|
58
|
-
|
|
38
|
+
req.session.headers = req.headers;
|
|
39
|
+
if (typeof (req.session.save) === 'function') {
|
|
40
|
+
req.session.save((err) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
next(`Error storing session: ${err}`);
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
next();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
next();
|
|
51
|
+
}
|
|
59
52
|
});
|
|
60
|
-
authApp.get('/:name/authenticate', (req, res, next) =>
|
|
53
|
+
authApp.get('/:name/authenticate', async (req, res, next) => {
|
|
61
54
|
const { name } = req.params;
|
|
62
|
-
const { accessToken, grant, query = {}, redirect } = req.session;
|
|
55
|
+
const { accessToken, grant, query = {}, redirect, headers } = req.session;
|
|
63
56
|
const service = app.defaultAuthentication(authService);
|
|
64
57
|
const [strategy] = service.getStrategies(name);
|
|
65
|
-
const params =
|
|
58
|
+
const params = {
|
|
59
|
+
...req.feathers,
|
|
60
|
+
authStrategies: [name],
|
|
61
|
+
authentication: accessToken ? {
|
|
66
62
|
strategy: linkStrategy,
|
|
67
63
|
accessToken
|
|
68
|
-
} : null,
|
|
69
|
-
|
|
70
|
-
|
|
64
|
+
} : null,
|
|
65
|
+
query,
|
|
66
|
+
redirect,
|
|
67
|
+
headers
|
|
68
|
+
};
|
|
69
|
+
const sendResponse = async (data) => {
|
|
71
70
|
try {
|
|
72
|
-
const redirect =
|
|
71
|
+
const redirect = await strategy.getRedirect(data, params);
|
|
73
72
|
if (redirect !== null) {
|
|
74
73
|
res.redirect(redirect);
|
|
75
74
|
}
|
|
@@ -84,28 +83,33 @@ exports.default = (options) => {
|
|
|
84
83
|
debug('oAuth error', error);
|
|
85
84
|
next(error);
|
|
86
85
|
}
|
|
87
|
-
}
|
|
86
|
+
};
|
|
88
87
|
try {
|
|
89
88
|
const payload = config.defaults.transport === 'session' ?
|
|
90
89
|
grant.response : req.query;
|
|
91
|
-
const authentication =
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
const authentication = {
|
|
91
|
+
strategy: name,
|
|
92
|
+
...payload
|
|
93
|
+
};
|
|
94
|
+
await new Promise((resolve, reject) => {
|
|
95
|
+
if (req.session.destroy) {
|
|
96
|
+
req.session.destroy((err) => err ? reject(err) : resolve());
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
94
99
|
req.session = null;
|
|
95
100
|
resolve();
|
|
96
101
|
}
|
|
97
|
-
req.session.destroy(err => err ? reject(err) : resolve());
|
|
98
102
|
});
|
|
99
103
|
debug(`Calling ${authService}.create authentication with strategy ${name}`);
|
|
100
|
-
const authResult =
|
|
104
|
+
const authResult = await service.create(authentication, params);
|
|
101
105
|
debug('Successful oAuth authentication, sending response');
|
|
102
|
-
|
|
106
|
+
await sendResponse(authResult);
|
|
103
107
|
}
|
|
104
108
|
catch (error) {
|
|
105
109
|
debug('Received oAuth authentication error', error.stack);
|
|
106
|
-
|
|
110
|
+
await sendResponse(error);
|
|
107
111
|
}
|
|
108
|
-
})
|
|
112
|
+
});
|
|
109
113
|
authApp.use(grantApp);
|
|
110
114
|
app.set('grant', grantApp.config);
|
|
111
115
|
app.use(prefix, authApp);
|
package/lib/express.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"express.js","sourceRoot":"","sources":["../src/express.ts"],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,IAAI,CAAC;wBACnB,OAAO,EAAE,CAAC;qBACX;gBACH,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
|
|
8
|
-
const merge_1 = __importDefault(require("lodash/merge"));
|
|
7
|
+
const defaultsDeep_1 = __importDefault(require("lodash/defaultsDeep"));
|
|
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 =
|
|
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 =
|
|
39
|
+
const grant = (0, defaultsDeep_1.default)({}, (0, omit_1.default)(oauth, ['redirect', 'origins']), {
|
|
40
40
|
defaults: {
|
|
41
41
|
prefix,
|
|
42
42
|
origin: `${protocol}://${host}`,
|
|
43
43
|
transport: 'session',
|
|
44
44
|
response: ['tokens', 'raw', 'profile']
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
});
|
|
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,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,uEAA+C;AAC/C,uDAA+B;AAC/B,uDAA+B;AAC/B,iDAAkD;AAElD,yCAAyD;AAM5B,8FANpB,wBAAa,OAMoB;AAL1C,wDAAoD;AACpD,mCAAiE;AAEjE,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,kCAAkC,CAAC,CAAC;AAIvD,MAAM,KAAK,GAAG,CAAC,OAA2B,EAAE,EAAE,CAAC,CAAC,GAAgB,EAAE,EAAE;IACzE,MAAM,OAAO,GAAG,GAAG,CAAC,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IAElG,IAAI,CAAC,OAAO,EAAE;QACZ,MAAM,IAAI,KAAK,CAAC,0FAA0F,CAAC,CAAC;KAC7G;IAED,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,aAAa,CAAC;IAExC,IAAI,CAAC,KAAK,EAAE;QACV,KAAK,CAAC,qFAAqF,CAAC,CAAC;QAC7F,OAAO;KACR;IAED,MAAM,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC;IAElC,0BAA0B;IAC1B,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,GAAG,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;IACnD,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC7B,IAAI,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC3B,IAAI,QAAQ,GAAG,OAAO,CAAC;IAEvB,sEAAsE;IACtE,I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AC;IAEH,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;AAC1B,CAAC,CAAC;AAzDW,QAAA,KAAK,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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult } from '@feathersjs/authentication';
|
|
1
|
+
import { AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult, AuthenticationParams } from '@feathersjs/authentication';
|
|
2
2
|
import { Params } from '@feathersjs/feathers';
|
|
3
3
|
export interface OAuthProfile {
|
|
4
4
|
id?: string | number;
|
|
@@ -15,12 +15,13 @@ 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
|
-
|
|
18
|
+
getAllowedOrigin(params?: Params): Promise<any>;
|
|
19
|
+
getRedirect(data: AuthenticationResult | Error, params?: AuthenticationParams): Promise<string | null>;
|
|
19
20
|
findEntity(profile: OAuthProfile, params: Params): Promise<any>;
|
|
20
21
|
createEntity(profile: OAuthProfile, params: Params): Promise<any>;
|
|
21
22
|
updateEntity(entity: any, profile: OAuthProfile, params: Params): Promise<any[]>;
|
|
22
23
|
getEntity(result: any, params: Params): Promise<any>;
|
|
23
|
-
authenticate(authentication: AuthenticationRequest, originalParams:
|
|
24
|
+
authenticate(authentication: AuthenticationRequest, originalParams: AuthenticationParams): Promise<{
|
|
24
25
|
[x: string]: any;
|
|
25
26
|
authentication: {
|
|
26
27
|
strategy: string;
|
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
|
|
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
|
|
18
|
+
return {
|
|
19
|
+
entity,
|
|
39
20
|
service,
|
|
40
|
-
entityId
|
|
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
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
62
|
-
return data.profile;
|
|
63
|
-
});
|
|
39
|
+
async getProfile(data, _params) {
|
|
40
|
+
return data.profile;
|
|
64
41
|
}
|
|
65
|
-
getCurrentEntity(params) {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
package/lib/strategy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"strategy.js","sourceRoot":"","sources":["../src/strategy.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAsD;AACtD,aAAa;AACb,8DAAsC;AACtC,+DAEoC;AAEpC,+CAAsD;AACtD,iDAAqD;AAErD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,2CAA2C,CAAC,CAAC;AAOvE,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,OAAO;YACL,MAAM;YACN,OAAO;YACP,QAAQ;YACR,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAED,IAAI,QAAQ;QACV,MAAM,EAAE,aAAa,EAAE,GAAG,IAAI,CAAC;QAE/B,OAAO,IAAI,CAAC,aAAa,CAAC,QAAQ,IAAI,CAAC,aAAa,IAAK,aAAqB,CAAC,EAAE,CAAC,CAAC;IACrF,CAAC;IAED,KAAK,CAAC,cAAc,CAAE,OAAqB,EAAE,OAAe;QAC1D,OAAO;YACL,C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AAO,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 =
|
|
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,
|
|
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.
|
|
4
|
+
"version": "5.0.0-pre.20",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git://github.com/feathersjs/feathers.git"
|
|
19
|
+
"url": "git://github.com/feathersjs/feathers.git",
|
|
20
|
+
"directory": "packages/authentication-oauth"
|
|
20
21
|
},
|
|
21
22
|
"author": {
|
|
22
23
|
"name": "Feathers contributors",
|
|
@@ -52,28 +53,27 @@
|
|
|
52
53
|
"access": "public"
|
|
53
54
|
},
|
|
54
55
|
"dependencies": {
|
|
55
|
-
"@feathersjs/authentication": "^5.0.0-pre.
|
|
56
|
-
"@feathersjs/
|
|
57
|
-
"@feathersjs/
|
|
58
|
-
"@feathersjs/
|
|
59
|
-
"
|
|
60
|
-
"express-session": "^1.17.
|
|
61
|
-
"grant": "^5.4.
|
|
56
|
+
"@feathersjs/authentication": "^5.0.0-pre.20",
|
|
57
|
+
"@feathersjs/commons": "^5.0.0-pre.20",
|
|
58
|
+
"@feathersjs/errors": "^5.0.0-pre.20",
|
|
59
|
+
"@feathersjs/express": "^5.0.0-pre.20",
|
|
60
|
+
"@feathersjs/feathers": "^5.0.0-pre.20",
|
|
61
|
+
"express-session": "^1.17.2",
|
|
62
|
+
"grant": "^5.4.21",
|
|
62
63
|
"lodash": "^4.17.21"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@feathersjs/
|
|
66
|
-
"@types/
|
|
67
|
-
"@types/express": "^
|
|
68
|
-
"@types/
|
|
69
|
-
"@types/
|
|
70
|
-
"@types/
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"typescript": "^4.2.3"
|
|
66
|
+
"@feathersjs/memory": "^5.0.0-pre.20",
|
|
67
|
+
"@types/express": "^4.17.13",
|
|
68
|
+
"@types/express-session": "^1.17.4",
|
|
69
|
+
"@types/lodash": "^4.14.182",
|
|
70
|
+
"@types/mocha": "^9.1.1",
|
|
71
|
+
"@types/node": "^17.0.31",
|
|
72
|
+
"axios": "^0.27.2",
|
|
73
|
+
"mocha": "^10.0.0",
|
|
74
|
+
"shx": "^0.3.4",
|
|
75
|
+
"ts-node": "^10.7.0",
|
|
76
|
+
"typescript": "^4.6.4"
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "54de749a0b392c7da726c668002b50cafaca530c"
|
|
79
79
|
}
|
package/src/express.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import grant from 'grant';
|
|
2
|
-
import Debug from 'debug';
|
|
3
2
|
import session from 'express-session';
|
|
3
|
+
import { Request, Response, NextFunction } from 'express';
|
|
4
|
+
import { createDebug } from '@feathersjs/commons';
|
|
4
5
|
import { Application } from '@feathersjs/feathers';
|
|
5
6
|
import { AuthenticationResult } from '@feathersjs/authentication';
|
|
6
7
|
import {
|
|
@@ -11,7 +12,7 @@ import { OauthSetupSettings } from './utils';
|
|
|
11
12
|
import { OAuthStrategy } from './strategy';
|
|
12
13
|
|
|
13
14
|
const grantInstance = grant.express();
|
|
14
|
-
const debug =
|
|
15
|
+
const debug = createDebug('@feathersjs/authentication-oauth/express');
|
|
15
16
|
|
|
16
17
|
declare module 'express-session' {
|
|
17
18
|
interface SessionData {
|
|
@@ -19,6 +20,7 @@ declare module 'express-session' {
|
|
|
19
20
|
accessToken: string;
|
|
20
21
|
query: { [key: string]: any };
|
|
21
22
|
grant: { [key: string]: any };
|
|
23
|
+
headers: { [key: string]: any };
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -44,7 +46,7 @@ export default (options: OauthSetupSettings) => {
|
|
|
44
46
|
|
|
45
47
|
authApp.use(expressSession);
|
|
46
48
|
|
|
47
|
-
authApp.get('/:name', (req, _res, next) => {
|
|
49
|
+
authApp.get('/:name', (req: Request, _res: Response, next: NextFunction) => {
|
|
48
50
|
const { feathers_token, redirect, ...query } = req.query;
|
|
49
51
|
|
|
50
52
|
if (feathers_token) {
|
|
@@ -53,13 +55,24 @@ export default (options: OauthSetupSettings) => {
|
|
|
53
55
|
}
|
|
54
56
|
req.session.redirect = redirect as string;
|
|
55
57
|
req.session.query = query;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
req.session.headers = req.headers;
|
|
59
|
+
if (typeof(req.session.save) === 'function') {
|
|
60
|
+
req.session.save((err: any) => {
|
|
61
|
+
if (err) {
|
|
62
|
+
next(`Error storing session: ${err}`);
|
|
63
|
+
} else {
|
|
64
|
+
next();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
next();
|
|
70
|
+
}
|
|
58
71
|
});
|
|
59
72
|
|
|
60
|
-
authApp.get('/:name/authenticate', async (req, res, next) => {
|
|
73
|
+
authApp.get('/:name/authenticate', async (req: Request, res: Response, next: NextFunction) => {
|
|
61
74
|
const { name } = req.params ;
|
|
62
|
-
const { accessToken, grant, query = {}, redirect } = req.session;
|
|
75
|
+
const { accessToken, grant, query = {}, redirect, headers } = req.session;
|
|
63
76
|
const service = app.defaultAuthentication(authService);
|
|
64
77
|
const [ strategy ] = service.getStrategies(name) as OAuthStrategy[];
|
|
65
78
|
const params = {
|
|
@@ -70,7 +83,8 @@ export default (options: OauthSetupSettings) => {
|
|
|
70
83
|
accessToken
|
|
71
84
|
} : null,
|
|
72
85
|
query,
|
|
73
|
-
redirect
|
|
86
|
+
redirect,
|
|
87
|
+
headers
|
|
74
88
|
};
|
|
75
89
|
const sendResponse = async (data: AuthenticationResult|Error) => {
|
|
76
90
|
try {
|
|
@@ -83,7 +97,7 @@ export default (options: OauthSetupSettings) => {
|
|
|
83
97
|
} else {
|
|
84
98
|
res.json(data);
|
|
85
99
|
}
|
|
86
|
-
} catch (error) {
|
|
100
|
+
} catch (error: any) {
|
|
87
101
|
debug('oAuth error', error);
|
|
88
102
|
next(error);
|
|
89
103
|
}
|
|
@@ -98,12 +112,13 @@ export default (options: OauthSetupSettings) => {
|
|
|
98
112
|
};
|
|
99
113
|
|
|
100
114
|
await new Promise<void>((resolve, reject) => {
|
|
101
|
-
if (
|
|
115
|
+
if (req.session.destroy) {
|
|
116
|
+
req.session.destroy((err: any) => err ? reject(err) : resolve());
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
102
119
|
req.session = null;
|
|
103
120
|
resolve();
|
|
104
121
|
}
|
|
105
|
-
|
|
106
|
-
req.session.destroy(err => err ? reject(err) : resolve());
|
|
107
122
|
});
|
|
108
123
|
|
|
109
124
|
debug(`Calling ${authService}.create authentication with strategy ${name}`);
|
|
@@ -113,7 +128,7 @@ export default (options: OauthSetupSettings) => {
|
|
|
113
128
|
debug('Successful oAuth authentication, sending response');
|
|
114
129
|
|
|
115
130
|
await sendResponse(authResult);
|
|
116
|
-
} catch (error) {
|
|
131
|
+
} catch (error: any) {
|
|
117
132
|
debug('Received oAuth authentication error', error.stack);
|
|
118
133
|
await sendResponse(error);
|
|
119
134
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import
|
|
2
|
-
import merge from 'lodash/merge';
|
|
1
|
+
import defaultsDeep from 'lodash/defaultsDeep';
|
|
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 =
|
|
10
|
+
const debug = createDebug('@feathersjs/authentication-oauth');
|
|
11
11
|
|
|
12
12
|
export { OauthSetupSettings, OAuthStrategy, OAuthProfile };
|
|
13
13
|
|
|
@@ -41,14 +41,14 @@ export const setup = (options: OauthSetupSettings) => (app: Application) => {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
const grant =
|
|
44
|
+
const grant = defaultsDeep({}, omit(oauth, ['redirect', 'origins']), {
|
|
45
45
|
defaults: {
|
|
46
46
|
prefix,
|
|
47
47
|
origin: `${protocol}://${host}`,
|
|
48
48
|
transport: 'session',
|
|
49
49
|
response: ['tokens', 'raw', 'profile']
|
|
50
50
|
}
|
|
51
|
-
}
|
|
51
|
+
});
|
|
52
52
|
|
|
53
53
|
const getUrl = (url: string) => {
|
|
54
54
|
const { defaults } = grant;
|
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
|
-
AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult
|
|
5
|
+
AuthenticationRequest, AuthenticationBaseStrategy, AuthenticationResult, AuthenticationParams
|
|
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 =
|
|
11
|
+
const debug = createDebug('@feathersjs/authentication-oauth/strategy');
|
|
12
12
|
|
|
13
13
|
export interface OAuthProfile {
|
|
14
14
|
id?: string|number;
|
|
@@ -67,9 +67,26 @@ export class OAuthStrategy extends AuthenticationBaseStrategy {
|
|
|
67
67
|
return null;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async
|
|
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
|
+
|
|
87
|
+
async getRedirect (data: AuthenticationResult|Error, params?: AuthenticationParams): Promise<string | null> {
|
|
71
88
|
const queryRedirect = (params && params.redirect) || '';
|
|
72
|
-
const
|
|
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,7 +135,7 @@ 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) {
|
|
@@ -134,12 +151,12 @@ 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
|
}
|
|
141
158
|
|
|
142
|
-
async authenticate (authentication: AuthenticationRequest, originalParams:
|
|
159
|
+
async authenticate (authentication: AuthenticationRequest, originalParams: AuthenticationParams) {
|
|
143
160
|
const entity: string = this.configuration.entity;
|
|
144
161
|
const { provider, ...params } = originalParams;
|
|
145
162
|
const profile = await this.getProfile(authentication, params);
|