@feathersjs/authentication 5.0.0-pre.2 → 5.0.0-pre.22

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,205 @@
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.22](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.21...v5.0.0-pre.22) (2022-05-24)
7
+
8
+ **Note:** Version bump only for package @feathersjs/authentication
9
+
10
+
11
+
12
+
13
+
14
+ # [5.0.0-pre.21](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.20...v5.0.0-pre.21) (2022-05-23)
15
+
16
+ **Note:** Version bump only for package @feathersjs/authentication
17
+
18
+
19
+
20
+
21
+
22
+ # [5.0.0-pre.20](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.19...v5.0.0-pre.20) (2022-05-04)
23
+
24
+
25
+ ### Bug Fixes
26
+
27
+ * **dependencies:** Lock monorepo package version numbers ([#2623](https://github.com/feathersjs/feathers/issues/2623)) ([5640c10](https://github.com/feathersjs/feathers/commit/5640c1020cc139994e695d658c08bad3494db507))
28
+
29
+
30
+
31
+
32
+
33
+ # [5.0.0-pre.19](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.18...v5.0.0-pre.19) (2022-05-01)
34
+
35
+
36
+ ### Features
37
+
38
+ * **typescript:** Improve adapter typings ([#2605](https://github.com/feathersjs/feathers/issues/2605)) ([3b2ca0a](https://github.com/feathersjs/feathers/commit/3b2ca0a6a8e03e8390272c4d7e930b4bffdaacf5))
39
+ * **typescript:** Improve params and query typeability ([#2600](https://github.com/feathersjs/feathers/issues/2600)) ([df28b76](https://github.com/feathersjs/feathers/commit/df28b7619161f1df5e700326f52cca1a92dc5d28))
40
+
41
+
42
+
43
+
44
+
45
+ # [5.0.0-pre.18](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.17...v5.0.0-pre.18) (2022-04-11)
46
+
47
+
48
+ ### Features
49
+
50
+ * **authentication:** Add setup method for auth strategies ([#1611](https://github.com/feathersjs/feathers/issues/1611)) ([a3c3581](https://github.com/feathersjs/feathers/commit/a3c35814dccdbbf6de96f04f60b226ce206c6dbe))
51
+ * **configuration:** Allow app configuration to be validated against a schema ([#2590](https://github.com/feathersjs/feathers/issues/2590)) ([a268f86](https://github.com/feathersjs/feathers/commit/a268f86da92a8ada14ed11ab456aac0a4bba5bb0))
52
+
53
+
54
+
55
+
56
+
57
+ # [5.0.0-pre.17](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.16...v5.0.0-pre.17) (2022-02-15)
58
+
59
+ **Note:** Version bump only for package @feathersjs/authentication
60
+
61
+
62
+
63
+
64
+
65
+ # [5.0.0-pre.16](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.15...v5.0.0-pre.16) (2022-01-12)
66
+
67
+
68
+ ### Features
69
+
70
+ * **express, koa:** make transports similar ([#2486](https://github.com/feathersjs/feathers/issues/2486)) ([26aa937](https://github.com/feathersjs/feathers/commit/26aa937c114fb8596dfefc599b1f53cead69c159))
71
+
72
+
73
+
74
+
75
+
76
+ # [5.0.0-pre.15](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.14...v5.0.0-pre.15) (2021-11-27)
77
+
78
+
79
+ ### Bug Fixes
80
+
81
+ * **typescript:** Overall typing improvements ([#2478](https://github.com/feathersjs/feathers/issues/2478)) ([b8eb804](https://github.com/feathersjs/feathers/commit/b8eb804158556d9651a8607e3c3fda15e0bfd110))
82
+
83
+
84
+ ### Features
85
+
86
+ * **authentication-oauth:** Allow dynamic oAuth redirect ([#2469](https://github.com/feathersjs/feathers/issues/2469)) ([b7143d4](https://github.com/feathersjs/feathers/commit/b7143d4c0fbe961e714f79512be04449b9bbd7d9))
87
+
88
+
89
+
90
+
91
+
92
+ # [5.0.0-pre.14](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.13...v5.0.0-pre.14) (2021-10-13)
93
+
94
+ **Note:** Version bump only for package @feathersjs/authentication
95
+
96
+
97
+
98
+
99
+
100
+ # [5.0.0-pre.13](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.12...v5.0.0-pre.13) (2021-10-13)
101
+
102
+ **Note:** Version bump only for package @feathersjs/authentication
103
+
104
+
105
+
106
+
107
+
108
+ # [5.0.0-pre.12](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.11...v5.0.0-pre.12) (2021-10-12)
109
+
110
+ **Note:** Version bump only for package @feathersjs/authentication
111
+
112
+
113
+
114
+
115
+
116
+ # [5.0.0-pre.11](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.10...v5.0.0-pre.11) (2021-10-06)
117
+
118
+ **Note:** Version bump only for package @feathersjs/authentication
119
+
120
+
121
+
122
+
123
+
124
+ # [5.0.0-pre.10](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.9...v5.0.0-pre.10) (2021-09-19)
125
+
126
+ **Note:** Version bump only for package @feathersjs/authentication
127
+
128
+
129
+
130
+
131
+
132
+ # [5.0.0-pre.9](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.8...v5.0.0-pre.9) (2021-08-09)
133
+
134
+ **Note:** Version bump only for package @feathersjs/authentication
135
+
136
+
137
+
138
+
139
+
140
+ # [5.0.0-pre.8](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.7...v5.0.0-pre.8) (2021-08-09)
141
+
142
+ **Note:** Version bump only for package @feathersjs/authentication
143
+
144
+
145
+
146
+
147
+
148
+ # [5.0.0-pre.7](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.6...v5.0.0-pre.7) (2021-08-09)
149
+
150
+ **Note:** Version bump only for package @feathersjs/authentication
151
+
152
+
153
+
154
+
155
+
156
+ # [5.0.0-pre.6](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.5...v5.0.0-pre.6) (2021-08-08)
157
+
158
+ **Note:** Version bump only for package @feathersjs/authentication
159
+
160
+
161
+
162
+
163
+
164
+ # [5.0.0-pre.5](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.4...v5.0.0-pre.5) (2021-06-23)
165
+
166
+
167
+ ### Bug Fixes
168
+
169
+ * **hooks:** Migrate built-in hooks and allow backwards compatibility ([#2358](https://github.com/feathersjs/feathers/issues/2358)) ([759c5a1](https://github.com/feathersjs/feathers/commit/759c5a19327a731af965c3604119393b3d09a406))
170
+ * **koa:** Use extended query parser for compatibility ([#2397](https://github.com/feathersjs/feathers/issues/2397)) ([b2944ba](https://github.com/feathersjs/feathers/commit/b2944bac3ec6d5ecc80dc518cd4e58093692db74))
171
+
172
+
173
+ ### Features
174
+
175
+ * **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))
176
+
177
+
178
+
179
+
180
+
181
+ # [5.0.0-pre.4](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.3...v5.0.0-pre.4) (2021-05-13)
182
+
183
+ **Note:** Version bump only for package @feathersjs/authentication
184
+
185
+
186
+
187
+
188
+
189
+ # [5.0.0-pre.3](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.2...v5.0.0-pre.3) (2021-04-21)
190
+
191
+
192
+ ### Bug Fixes
193
+
194
+ * **typescript:** Improve TypeScript backwards compatibility ([#2310](https://github.com/feathersjs/feathers/issues/2310)) ([f33be73](https://github.com/feathersjs/feathers/commit/f33be73fc46a533efb15df9aab0658e3240d3897))
195
+
196
+
197
+ ### Features
198
+
199
+ * **dependencies:** Remove direct debug dependency ([#2296](https://github.com/feathersjs/feathers/issues/2296)) ([501d416](https://github.com/feathersjs/feathers/commit/501d4164d30c6a126906dc640cdfdc82207ba34a))
200
+
201
+
202
+
203
+
204
+
6
205
  # [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
206
 
8
207
  **Note:** Version bump only for package @feathersjs/authentication
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021 Feathers
3
+ Copyright (c) 2022 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
@@ -1,8 +1,8 @@
1
1
  # @feathersjs/authentication
2
2
 
3
3
  [![CI](https://github.com/feathersjs/feathers/workflows/CI/badge.svg)](https://github.com/feathersjs/feathers/actions?query=workflow%3ACI)
4
- [![Dependency Status](https://img.shields.io/david/feathersjs/feathers.svg?style=flat-square&path=packages/authentication)](https://david-dm.org/feathersjs/feathers?path=packages/authentication)
5
4
  [![Download Status](https://img.shields.io/npm/dm/@feathersjs/authentication.svg?style=flat-square)](https://www.npmjs.com/package/@feathersjs/authentication)
5
+ [![Discord](https://badgen.net/badge/icon/discord?icon=discord&label)](https://discord.gg/qa8kez8QBx)
6
6
 
7
7
  > Add Authentication to your FeathersJS app.
8
8
 
@@ -18,6 +18,6 @@ Refer to the [Feathers authentication API documentation](https://docs.feathersjs
18
18
 
19
19
  ## License
20
20
 
21
- Copyright (c) 2021 [Feathers contributors](https://github.com/feathersjs/feathers/graphs/contributors)
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/core.d.ts CHANGED
@@ -9,6 +9,15 @@ export interface AuthenticationRequest {
9
9
  strategy?: string;
10
10
  [key: string]: any;
11
11
  }
12
+ export interface AuthenticationParams extends Params {
13
+ payload?: {
14
+ [key: string]: any;
15
+ };
16
+ jwtOptions?: SignOptions;
17
+ authStrategies?: string[];
18
+ secret?: string;
19
+ [key: string]: any;
20
+ }
12
21
  export declare type ConnectionEvent = 'login' | 'logout' | 'disconnect';
13
22
  export interface AuthenticationStrategy {
14
23
  /**
@@ -34,6 +43,12 @@ export interface AuthenticationStrategy {
34
43
  * and throw an error if it is invalid.
35
44
  */
36
45
  verifyConfiguration?(): void;
46
+ /**
47
+ * Implement this method to setup this strategy
48
+ * @param auth The AuthenticationService
49
+ * @param name The name of the strategy
50
+ */
51
+ setup?(auth: AuthenticationBase, name: string): Promise<void>;
37
52
  /**
38
53
  * Authenticate an authentication request with this strategy.
39
54
  * Should throw an error if the strategy did not succeed.
@@ -41,7 +56,7 @@ export interface AuthenticationStrategy {
41
56
  * @param authentication The authentication request
42
57
  * @param params The service call parameters
43
58
  */
44
- authenticate?(authentication: AuthenticationRequest, params: Params): Promise<AuthenticationResult>;
59
+ authenticate?(authentication: AuthenticationRequest, params: AuthenticationParams): Promise<AuthenticationResult>;
45
60
  /**
46
61
  * Update a real-time connection according to this strategy.
47
62
  *
@@ -65,10 +80,11 @@ export interface JwtVerifyOptions extends VerifyOptions {
65
80
  */
66
81
  export declare class AuthenticationBase {
67
82
  app: Application;
68
- configKey: string;
69
83
  strategies: {
70
84
  [key: string]: AuthenticationStrategy;
71
85
  };
86
+ configKey: string;
87
+ isReady: boolean;
72
88
  /**
73
89
  * Create a new authentication service.
74
90
  *
@@ -98,6 +114,13 @@ export declare class AuthenticationBase {
98
114
  * @param names The list or strategy names
99
115
  */
100
116
  getStrategies(...names: string[]): AuthenticationStrategy[];
117
+ /**
118
+ * Returns a single strategy by name
119
+ *
120
+ * @param name The strategy name
121
+ * @returns The authentication strategy or undefined
122
+ */
123
+ getStrategy(name: string): AuthenticationStrategy;
101
124
  /**
102
125
  * Create a new access token with payload and options.
103
126
  *
@@ -121,7 +144,7 @@ export declare class AuthenticationBase {
121
144
  * @param params Service call parameters
122
145
  * @param allowed A list of allowed strategy names
123
146
  */
124
- authenticate(authentication: AuthenticationRequest, params: Params, ...allowed: string[]): Promise<AuthenticationResult>;
147
+ authenticate(authentication: AuthenticationRequest, params: AuthenticationParams, ...allowed: string[]): Promise<AuthenticationResult>;
125
148
  handleConnection(event: ConnectionEvent, connection: any, authResult?: AuthenticationResult): Promise<void>;
126
149
  /**
127
150
  * Parse an HTTP request and response for authentication request information.
@@ -131,4 +154,5 @@ export declare class AuthenticationBase {
131
154
  * @param names A list of strategies to use
132
155
  */
133
156
  parse(req: IncomingMessage, res: ServerResponse, ...names: string[]): Promise<AuthenticationRequest>;
157
+ setup(): Promise<void>;
134
158
  }
package/lib/core.js CHANGED
@@ -1,13 +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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -17,9 +8,9 @@ const merge_1 = __importDefault(require("lodash/merge"));
17
8
  const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
18
9
  const uuid_1 = require("uuid");
19
10
  const errors_1 = require("@feathersjs/errors");
20
- const debug_1 = __importDefault(require("debug"));
21
- const options_1 = __importDefault(require("./options"));
22
- const debug = debug_1.default('@feathersjs/authentication/base');
11
+ const commons_1 = require("@feathersjs/commons");
12
+ const options_1 = require("./options");
13
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication/base');
23
14
  /**
24
15
  * A base class for managing authentication strategies and creating and verifying JWTs
25
16
  */
@@ -38,15 +29,16 @@ class AuthenticationBase {
38
29
  this.app = app;
39
30
  this.strategies = {};
40
31
  this.configKey = configKey;
32
+ this.isReady = false;
41
33
  app.set('defaultAuthentication', app.get('defaultAuthentication') || configKey);
42
- app.set(configKey, merge_1.default({}, app.get(configKey), options));
34
+ app.set(configKey, (0, merge_1.default)({}, app.get(configKey), options));
43
35
  }
44
36
  /**
45
37
  * Return the current configuration from the application
46
38
  */
47
39
  get configuration() {
48
40
  // Always returns a copy of the authentication configuration
49
- return Object.assign({}, options_1.default, this.app.get(this.configKey));
41
+ return Object.assign({}, options_1.defaultOptions, this.app.get(this.configKey));
50
42
  }
51
43
  /**
52
44
  * A list of all registered strategy names
@@ -61,6 +53,7 @@ class AuthenticationBase {
61
53
  * @param strategy The authentication strategy instance
62
54
  */
63
55
  register(name, strategy) {
56
+ var _a;
64
57
  // Call the functions a strategy can implement
65
58
  if (typeof strategy.setName === 'function') {
66
59
  strategy.setName(name);
@@ -76,6 +69,9 @@ class AuthenticationBase {
76
69
  }
77
70
  // Register strategy as name
78
71
  this.strategies[name] = strategy;
72
+ if (this.isReady) {
73
+ (_a = strategy.setup) === null || _a === void 0 ? void 0 : _a.call(strategy, this, name);
74
+ }
79
75
  }
80
76
  /**
81
77
  * Get the registered authentication strategies for a list of names.
@@ -86,6 +82,15 @@ class AuthenticationBase {
86
82
  return names.map(name => this.strategies[name])
87
83
  .filter(current => !!current);
88
84
  }
85
+ /**
86
+ * Returns a single strategy by name
87
+ *
88
+ * @param name The strategy name
89
+ * @returns The authentication strategy or undefined
90
+ */
91
+ getStrategy(name) {
92
+ return this.strategies[name];
93
+ }
89
94
  /**
90
95
  * Create a new access token with payload and options.
91
96
  *
@@ -93,19 +98,17 @@ class AuthenticationBase {
93
98
  * @param optsOverride The options to extend the defaults (`configuration.jwtOptions`) with
94
99
  * @param secretOverride Use a different secret instead
95
100
  */
96
- createAccessToken(payload, optsOverride, secretOverride) {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- const { secret, jwtOptions } = this.configuration;
99
- // Use configuration by default but allow overriding the secret
100
- const jwtSecret = secretOverride || secret;
101
- // Default jwt options merged with additional options
102
- const options = merge_1.default({}, jwtOptions, optsOverride);
103
- if (!options.jwtid) {
104
- // Generate a UUID as JWT ID by default
105
- options.jwtid = uuid_1.v4();
106
- }
107
- return jsonwebtoken_1.default.sign(payload, jwtSecret, options);
108
- });
101
+ async createAccessToken(payload, optsOverride, secretOverride) {
102
+ const { secret, jwtOptions } = this.configuration;
103
+ // Use configuration by default but allow overriding the secret
104
+ const jwtSecret = secretOverride || secret;
105
+ // Default jwt options merged with additional options
106
+ const options = (0, merge_1.default)({}, jwtOptions, optsOverride);
107
+ if (!options.jwtid) {
108
+ // Generate a UUID as JWT ID by default
109
+ options.jwtid = (0, uuid_1.v4)();
110
+ }
111
+ return jsonwebtoken_1.default.sign(payload, jwtSecret, options);
109
112
  }
110
113
  /**
111
114
  * Verifies an access token.
@@ -114,25 +117,23 @@ class AuthenticationBase {
114
117
  * @param optsOverride The options to extend the defaults (`configuration.jwtOptions`) with
115
118
  * @param secretOverride Use a different secret instead
116
119
  */
117
- verifyAccessToken(accessToken, optsOverride, secretOverride) {
118
- return __awaiter(this, void 0, void 0, function* () {
119
- const { secret, jwtOptions } = this.configuration;
120
- const jwtSecret = secretOverride || secret;
121
- const options = merge_1.default({}, jwtOptions, optsOverride);
122
- const { algorithm } = options;
123
- // Normalize the `algorithm` setting into the algorithms array
124
- if (algorithm && !options.algorithms) {
125
- options.algorithms = Array.isArray(algorithm) ? algorithm : [algorithm];
126
- delete options.algorithm;
127
- }
128
- try {
129
- const verified = jsonwebtoken_1.default.verify(accessToken, jwtSecret, options);
130
- return verified;
131
- }
132
- catch (error) {
133
- throw new errors_1.NotAuthenticated(error.message, error);
134
- }
135
- });
120
+ async verifyAccessToken(accessToken, optsOverride, secretOverride) {
121
+ const { secret, jwtOptions } = this.configuration;
122
+ const jwtSecret = secretOverride || secret;
123
+ const options = (0, merge_1.default)({}, jwtOptions, optsOverride);
124
+ const { algorithm } = options;
125
+ // Normalize the `algorithm` setting into the algorithms array
126
+ if (algorithm && !options.algorithms) {
127
+ options.algorithms = Array.isArray(algorithm) ? algorithm : [algorithm];
128
+ delete options.algorithm;
129
+ }
130
+ try {
131
+ const verified = jsonwebtoken_1.default.verify(accessToken, jwtSecret, options);
132
+ return verified;
133
+ }
134
+ catch (error) {
135
+ throw new errors_1.NotAuthenticated(error.message, error);
136
+ }
136
137
  }
137
138
  /**
138
139
  * Authenticate a given authentication request against a list of strategies.
@@ -141,29 +142,28 @@ class AuthenticationBase {
141
142
  * @param params Service call parameters
142
143
  * @param allowed A list of allowed strategy names
143
144
  */
144
- authenticate(authentication, params, ...allowed) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- const { strategy } = authentication || {};
147
- const [authStrategy] = this.getStrategies(strategy);
148
- const strategyAllowed = allowed.includes(strategy);
149
- debug('Running authenticate for strategy', strategy, allowed);
150
- if (!authentication || !authStrategy || !strategyAllowed) {
151
- const additionalInfo = (!strategy && ' (no `strategy` set)') ||
152
- (!strategyAllowed && ' (strategy not allowed in authStrategies)') || '';
153
- // If there are no valid strategies or `authentication` is not an object
154
- throw new errors_1.NotAuthenticated('Invalid authentication information' + additionalInfo);
155
- }
156
- return authStrategy.authenticate(authentication, Object.assign(Object.assign({}, params), { authenticated: true }));
145
+ async authenticate(authentication, params, ...allowed) {
146
+ const { strategy } = authentication || {};
147
+ const [authStrategy] = this.getStrategies(strategy);
148
+ const strategyAllowed = allowed.includes(strategy);
149
+ debug('Running authenticate for strategy', strategy, allowed);
150
+ if (!authentication || !authStrategy || !strategyAllowed) {
151
+ const additionalInfo = (!strategy && ' (no `strategy` set)') ||
152
+ (!strategyAllowed && ' (strategy not allowed in authStrategies)') || '';
153
+ // If there are no valid strategies or `authentication` is not an object
154
+ throw new errors_1.NotAuthenticated('Invalid authentication information' + additionalInfo);
155
+ }
156
+ return authStrategy.authenticate(authentication, {
157
+ ...params,
158
+ authenticated: true
157
159
  });
158
160
  }
159
- handleConnection(event, connection, authResult) {
160
- return __awaiter(this, void 0, void 0, function* () {
161
- const strategies = this.getStrategies(...Object.keys(this.strategies))
162
- .filter(current => typeof current.handleConnection === 'function');
163
- for (const strategy of strategies) {
164
- yield strategy.handleConnection(event, connection, authResult);
165
- }
166
- });
161
+ async handleConnection(event, connection, authResult) {
162
+ const strategies = this.getStrategies(...Object.keys(this.strategies))
163
+ .filter(current => typeof current.handleConnection === 'function');
164
+ for (const strategy of strategies) {
165
+ await strategy.handleConnection(event, connection, authResult);
166
+ }
167
167
  }
168
168
  /**
169
169
  * Parse an HTTP request and response for authentication request information.
@@ -172,19 +172,25 @@ class AuthenticationBase {
172
172
  * @param res The HTTP response
173
173
  * @param names A list of strategies to use
174
174
  */
175
- parse(req, res, ...names) {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- const strategies = this.getStrategies(...names)
178
- .filter(current => typeof current.parse === 'function');
179
- debug('Strategies parsing HTTP header for authentication information', names);
180
- for (const authStrategy of strategies) {
181
- const value = yield authStrategy.parse(req, res);
182
- if (value !== null) {
183
- return value;
184
- }
175
+ async parse(req, res, ...names) {
176
+ const strategies = this.getStrategies(...names)
177
+ .filter(current => typeof current.parse === 'function');
178
+ debug('Strategies parsing HTTP header for authentication information', names);
179
+ for (const authStrategy of strategies) {
180
+ const value = await authStrategy.parse(req, res);
181
+ if (value !== null) {
182
+ return value;
185
183
  }
186
- return null;
187
- });
184
+ }
185
+ return null;
186
+ }
187
+ async setup() {
188
+ var _a;
189
+ this.isReady = true;
190
+ for (const name of Object.keys(this.strategies)) {
191
+ const strategy = this.strategies[name];
192
+ await ((_a = strategy.setup) === null || _a === void 0 ? void 0 : _a.call(strategy, this, name));
193
+ }
188
194
  }
189
195
  }
190
196
  exports.AuthenticationBase = AuthenticationBase;
package/lib/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,yDAAiC;AACjC,gEAAgF;AAChF,+BAAoC;AACpC,+CAAsD;AACtD,kDAA0B;AAG1B,wDAAuC;AAEvC,MAAM,KAAK,GAAG,eAAK,CAAC,iCAAiC,CAAC,CAAC;AAiEvD;;GAEG;AACH,MAAa,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E,KAAK,MAAM,YAAY,IAAI,UAAU,EAAE;YACrC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;YAEjD,IAAI,KAAK,KAAK,IAAI,EAAE;gBAClB,OAAO,KAAK,CAAC;aACd;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,KAAK,CAAC,KAAK;;QACT,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;YAEvC,MAAM,CAAA,MAAA,QAAQ,CAAC,KAAK,yDAAG,IAAI,EAAE,IAAI,CAAC,CAAA,CAAC;SACpC;IACH,CAAC;CACF;AAtND,gDAsNC"}
@@ -1,7 +1,7 @@
1
- import { HookContext } from '@feathersjs/feathers';
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
2
  export interface AuthenticateHookSettings {
3
3
  service?: string;
4
- strategies: string[];
4
+ strategies?: string[];
5
5
  }
6
- declare const _default: (originalSettings: string | AuthenticateHookSettings, ...originalStrategies: string[]) => (context: HookContext<any, any>) => Promise<HookContext<any, any>>;
6
+ declare const _default: (originalSettings: string | AuthenticateHookSettings, ...originalStrategies: string[]) => (context: HookContext, _next?: NextFunction) => Promise<any>;
7
7
  export default _default;
@@ -1,13 +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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -15,16 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
6
  const flatten_1 = __importDefault(require("lodash/flatten"));
16
7
  const omit_1 = __importDefault(require("lodash/omit"));
17
8
  const errors_1 = require("@feathersjs/errors");
18
- const debug_1 = __importDefault(require("debug"));
19
- const debug = debug_1.default('@feathersjs/authentication/hooks/authenticate');
9
+ const commons_1 = require("@feathersjs/commons");
10
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication/hooks/authenticate');
20
11
  exports.default = (originalSettings, ...originalStrategies) => {
21
12
  const settings = typeof originalSettings === 'string'
22
- ? { strategies: flatten_1.default([originalSettings, ...originalStrategies]) }
13
+ ? { strategies: (0, flatten_1.default)([originalSettings, ...originalStrategies]) }
23
14
  : originalSettings;
24
15
  if (!originalSettings || settings.strategies.length === 0) {
25
16
  throw new Error('The authenticate hook needs at least one allowed strategy');
26
17
  }
27
- return (context) => __awaiter(void 0, void 0, void 0, function* () {
18
+ return async (context, _next) => {
19
+ const next = typeof _next === 'function' ? _next : async () => context;
28
20
  const { app, params, type, path, service } = context;
29
21
  const { strategies } = settings;
30
22
  const { provider, authentication } = params;
@@ -41,19 +33,18 @@ exports.default = (originalSettings, ...originalStrategies) => {
41
33
  throw new errors_1.NotAuthenticated('The authenticate hook does not need to be used on the authentication service');
42
34
  }
43
35
  if (params.authenticated === true) {
44
- return context;
36
+ return next();
45
37
  }
46
38
  if (authentication) {
47
- const authParams = omit_1.default(params, 'provider', 'authentication');
39
+ const authParams = (0, omit_1.default)(params, 'provider', 'authentication');
48
40
  debug('Authenticating with', authentication, strategies);
49
- const authResult = yield authService.authenticate(authentication, authParams, ...strategies);
50
- context.params = Object.assign({}, params, omit_1.default(authResult, 'accessToken'), { authenticated: true });
51
- return context;
41
+ const authResult = await authService.authenticate(authentication, authParams, ...strategies);
42
+ context.params = Object.assign({}, params, (0, omit_1.default)(authResult, 'accessToken'), { authenticated: true });
52
43
  }
53
44
  else if (provider) {
54
45
  throw new errors_1.NotAuthenticated('Not authenticated');
55
46
  }
56
- return context;
57
- });
47
+ return next();
48
+ };
58
49
  };
59
50
  //# sourceMappingURL=authenticate.js.map