@feathersjs/authentication 5.0.0-pre.3 → 5.0.0-pre.30

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/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
@@ -1,7 +1,9 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { SignOptions, Secret, VerifyOptions } from 'jsonwebtoken';
3
4
  import { Application, Params } from '@feathersjs/feathers';
4
5
  import { IncomingMessage, ServerResponse } from 'http';
6
+ import { AuthenticationConfiguration } from './options';
5
7
  export interface AuthenticationResult {
6
8
  [key: string]: any;
7
9
  }
@@ -9,6 +11,15 @@ export interface AuthenticationRequest {
9
11
  strategy?: string;
10
12
  [key: string]: any;
11
13
  }
14
+ export interface AuthenticationParams extends Params {
15
+ payload?: {
16
+ [key: string]: any;
17
+ };
18
+ jwtOptions?: SignOptions;
19
+ authStrategies?: string[];
20
+ secret?: string;
21
+ [key: string]: any;
22
+ }
12
23
  export declare type ConnectionEvent = 'login' | 'logout' | 'disconnect';
13
24
  export interface AuthenticationStrategy {
14
25
  /**
@@ -34,6 +45,12 @@ export interface AuthenticationStrategy {
34
45
  * and throw an error if it is invalid.
35
46
  */
36
47
  verifyConfiguration?(): void;
48
+ /**
49
+ * Implement this method to setup this strategy
50
+ * @param auth The AuthenticationService
51
+ * @param name The name of the strategy
52
+ */
53
+ setup?(auth: AuthenticationBase, name: string): Promise<void>;
37
54
  /**
38
55
  * Authenticate an authentication request with this strategy.
39
56
  * Should throw an error if the strategy did not succeed.
@@ -41,7 +58,7 @@ export interface AuthenticationStrategy {
41
58
  * @param authentication The authentication request
42
59
  * @param params The service call parameters
43
60
  */
44
- authenticate?(authentication: AuthenticationRequest, params: Params): Promise<AuthenticationResult>;
61
+ authenticate?(authentication: AuthenticationRequest, params: AuthenticationParams): Promise<AuthenticationResult>;
45
62
  /**
46
63
  * Update a real-time connection according to this strategy.
47
64
  *
@@ -65,10 +82,11 @@ export interface JwtVerifyOptions extends VerifyOptions {
65
82
  */
66
83
  export declare class AuthenticationBase {
67
84
  app: Application;
68
- configKey: string;
69
85
  strategies: {
70
86
  [key: string]: AuthenticationStrategy;
71
87
  };
88
+ configKey: string;
89
+ isReady: boolean;
72
90
  /**
73
91
  * Create a new authentication service.
74
92
  *
@@ -80,7 +98,7 @@ export declare class AuthenticationBase {
80
98
  /**
81
99
  * Return the current configuration from the application
82
100
  */
83
- get configuration(): any;
101
+ get configuration(): AuthenticationConfiguration;
84
102
  /**
85
103
  * A list of all registered strategy names
86
104
  */
@@ -98,6 +116,13 @@ export declare class AuthenticationBase {
98
116
  * @param names The list or strategy names
99
117
  */
100
118
  getStrategies(...names: string[]): AuthenticationStrategy[];
119
+ /**
120
+ * Returns a single strategy by name
121
+ *
122
+ * @param name The strategy name
123
+ * @returns The authentication strategy or undefined
124
+ */
125
+ getStrategy(name: string): AuthenticationStrategy;
101
126
  /**
102
127
  * Create a new access token with payload and options.
103
128
  *
@@ -121,7 +146,7 @@ export declare class AuthenticationBase {
121
146
  * @param params Service call parameters
122
147
  * @param allowed A list of allowed strategy names
123
148
  */
124
- authenticate(authentication: AuthenticationRequest, params: Params, ...allowed: string[]): Promise<AuthenticationResult>;
149
+ authenticate(authentication: AuthenticationRequest, params: AuthenticationParams, ...allowed: string[]): Promise<AuthenticationResult>;
125
150
  handleConnection(event: ConnectionEvent, connection: any, authResult?: AuthenticationResult): Promise<void>;
126
151
  /**
127
152
  * Parse an HTTP request and response for authentication request information.
@@ -131,4 +156,5 @@ export declare class AuthenticationBase {
131
156
  * @param names A list of strategies to use
132
157
  */
133
158
  parse(req: IncomingMessage, res: ServerResponse, ...names: string[]): Promise<AuthenticationRequest>;
159
+ setup(): Promise<void>;
134
160
  }
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
  };
@@ -18,8 +9,8 @@ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
18
9
  const uuid_1 = require("uuid");
19
10
  const errors_1 = require("@feathersjs/errors");
20
11
  const commons_1 = require("@feathersjs/commons");
21
- const options_1 = __importDefault(require("./options"));
22
- const debug = commons_1.createDebug('@feathersjs/authentication/base');
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.
@@ -83,8 +79,16 @@ class AuthenticationBase {
83
79
  * @param names The list or strategy names
84
80
  */
85
81
  getStrategies(...names) {
86
- return names.map(name => this.strategies[name])
87
- .filter(current => !!current);
82
+ return names.map((name) => this.strategies[name]).filter((current) => !!current);
83
+ }
84
+ /**
85
+ * Returns a single strategy by name
86
+ *
87
+ * @param name The strategy name
88
+ * @returns The authentication strategy or undefined
89
+ */
90
+ getStrategy(name) {
91
+ return this.strategies[name];
88
92
  }
89
93
  /**
90
94
  * Create a new access token with payload and options.
@@ -93,19 +97,17 @@ class AuthenticationBase {
93
97
  * @param optsOverride The options to extend the defaults (`configuration.jwtOptions`) with
94
98
  * @param secretOverride Use a different secret instead
95
99
  */
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
- });
100
+ async createAccessToken(payload, optsOverride, secretOverride) {
101
+ const { secret, jwtOptions } = this.configuration;
102
+ // Use configuration by default but allow overriding the secret
103
+ const jwtSecret = secretOverride || secret;
104
+ // Default jwt options merged with additional options
105
+ const options = (0, merge_1.default)({}, jwtOptions, optsOverride);
106
+ if (!options.jwtid) {
107
+ // Generate a UUID as JWT ID by default
108
+ options.jwtid = (0, uuid_1.v4)();
109
+ }
110
+ return jsonwebtoken_1.default.sign(payload, jwtSecret, options);
109
111
  }
110
112
  /**
111
113
  * Verifies an access token.
@@ -114,25 +116,23 @@ class AuthenticationBase {
114
116
  * @param optsOverride The options to extend the defaults (`configuration.jwtOptions`) with
115
117
  * @param secretOverride Use a different secret instead
116
118
  */
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
- });
119
+ async verifyAccessToken(accessToken, optsOverride, secretOverride) {
120
+ const { secret, jwtOptions } = this.configuration;
121
+ const jwtSecret = secretOverride || secret;
122
+ const options = (0, merge_1.default)({}, jwtOptions, optsOverride);
123
+ const { algorithm } = options;
124
+ // Normalize the `algorithm` setting into the algorithms array
125
+ if (algorithm && !options.algorithms) {
126
+ options.algorithms = (Array.isArray(algorithm) ? algorithm : [algorithm]);
127
+ delete options.algorithm;
128
+ }
129
+ try {
130
+ const verified = jsonwebtoken_1.default.verify(accessToken, jwtSecret, options);
131
+ return verified;
132
+ }
133
+ catch (error) {
134
+ throw new errors_1.NotAuthenticated(error.message, error);
135
+ }
136
136
  }
137
137
  /**
138
138
  * Authenticate a given authentication request against a list of strategies.
@@ -141,29 +141,28 @@ class AuthenticationBase {
141
141
  * @param params Service call parameters
142
142
  * @param allowed A list of allowed strategy names
143
143
  */
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 }));
144
+ async authenticate(authentication, params, ...allowed) {
145
+ const { strategy } = authentication || {};
146
+ const [authStrategy] = this.getStrategies(strategy);
147
+ const strategyAllowed = allowed.includes(strategy);
148
+ debug('Running authenticate for strategy', strategy, allowed);
149
+ if (!authentication || !authStrategy || !strategyAllowed) {
150
+ const additionalInfo = (!strategy && ' (no `strategy` set)') ||
151
+ (!strategyAllowed && ' (strategy not allowed in authStrategies)') ||
152
+ '';
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)).filter((current) => typeof current.handleConnection === 'function');
163
+ for (const strategy of strategies) {
164
+ await strategy.handleConnection(event, connection, authResult);
165
+ }
167
166
  }
168
167
  /**
169
168
  * Parse an HTTP request and response for authentication request information.
@@ -172,19 +171,24 @@ class AuthenticationBase {
172
171
  * @param res The HTTP response
173
172
  * @param names A list of strategies to use
174
173
  */
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
- }
174
+ async parse(req, res, ...names) {
175
+ const strategies = this.getStrategies(...names).filter((current) => typeof current.parse === 'function');
176
+ debug('Strategies parsing HTTP header for authentication information', names);
177
+ for (const authStrategy of strategies) {
178
+ const value = await authStrategy.parse(req, res);
179
+ if (value !== null) {
180
+ return value;
185
181
  }
186
- return null;
187
- });
182
+ }
183
+ return null;
184
+ }
185
+ async setup() {
186
+ var _a;
187
+ this.isReady = true;
188
+ for (const name of Object.keys(this.strategies)) {
189
+ const strategy = this.strategies[name];
190
+ await ((_a = strategy.setup) === null || _a === void 0 ? void 0 : _a.call(strategy, this, name));
191
+ }
188
192
  }
189
193
  }
190
194
  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,iDAAkD;AAGlD,wDAAuC;AAEvC,MAAM,KAAK,GAAG,qBAAW,CAAC,iCAAiC,CAAC,CAAC;AAiE7D;;GAEG;AACH,MAAa,kBAAkB;IAO7B;;;;;;OAMG;IACH,YAAa,GAAgB,EAAE,SAAS,GAAG,gBAAgB,EAAE,OAAO,GAAG,EAAE;QACvE,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,CAAC,GAAG,KAAK,UAAU,EAAE;YACzC,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;SAC3F;QAED,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAE3B,GAAG,CAAC,GAAG,CAAC,uBAAuB,EAAE,GAAG,CAAC,GAAG,CAAC,uBAAuB,CAAC,IAAI,SAAS,CAAC,CAAC;QAChF,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,eAAK,CAAC,EAAE,EAAE,GAAG,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC;IAC7D,CAAC;IAED;;OAEG;IACH,IAAI,aAAa;QACf,4DAA4D;QAC5D,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,iBAAc,EAAE,IAAI,CAAC,G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AC,CAAC,MAAM,CAC3E,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,CAAC,gBAAgB,KAAK,UAAU,CAC5D,CAAA;QAED,KAAK,MAAM,QAAQ,IAAI,UAAU,EAAE;YACjC,MAAM,QAAQ,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;SAC/D;IACH,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,CAAC,GAAoB,EAAE,GAAmB,EAAE,GAAG,KAAe;QACvE,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,OAAO,CAAC,KAAK,KAAK,UAAU,CAAC,CAAA;QAExG,KAAK,CAAC,+DAA+D,EAAE,KAAK,CAAC,CAAA;QAE7E,KAAK,MAAM,YAAY,IAAI,UAAU,EAAE;YACrC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;YAEhD,IAAI,KAAK,KAAK,IAAI,EAAE;gBAClB,OAAO,KAAK,CAAA;aACb;SACF;QAED,OAAO,IAAI,CAAA;IACb,CAAC;IAED,KAAK,CAAC,KAAK;;QACT,IAAI,CAAC,OAAO,GAAG,IAAI,CAAA;QAEnB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;YAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;YAEtC,MAAM,CAAA,MAAA,QAAQ,CAAC,KAAK,yDAAG,IAAI,EAAE,IAAI,CAAC,CAAA,CAAA;SACnC;IACH,CAAC;CACF;AA/ND,gDA+NC"}
@@ -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
  };
@@ -16,15 +7,16 @@ 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
9
  const commons_1 = require("@feathersjs/commons");
19
- const debug = commons_1.createDebug('@feathersjs/authentication/hooks/authenticate');
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;
@@ -36,24 +28,24 @@ exports.default = (originalSettings, ...originalStrategies) => {
36
28
  if (!authService || typeof authService.authenticate !== 'function') {
37
29
  throw new errors_1.NotAuthenticated('Could not find a valid authentication service');
38
30
  }
39
- // @ts-ignore
40
31
  if (service === authService) {
41
32
  throw new errors_1.NotAuthenticated('The authenticate hook does not need to be used on the authentication service');
42
33
  }
43
34
  if (params.authenticated === true) {
44
- return context;
35
+ return next();
45
36
  }
46
37
  if (authentication) {
47
- const authParams = omit_1.default(params, 'provider', 'authentication');
38
+ const authParams = (0, omit_1.default)(params, 'provider', 'authentication');
48
39
  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;
40
+ const authResult = await authService.authenticate(authentication, authParams, ...strategies);
41
+ context.params = Object.assign({}, params, (0, omit_1.default)(authResult, 'accessToken'), {
42
+ authenticated: true
43
+ });
52
44
  }
53
45
  else if (provider) {
54
46
  throw new errors_1.NotAuthenticated('Not authenticated');
55
47
  }
56
- return context;
57
- });
48
+ return next();
49
+ };
58
50
  };
59
51
  //# sourceMappingURL=authenticate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/hooks/authenticate.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6DAAqC;AACrC,uDAA+B;AAE/B,+CAAsD;AACtD,iDAAkD;AAElD,MAAM,KAAK,GAAG,qBAAW,CAAC,+CAA+C,CAAC,CAAC;AAO3E,kBAAe,CAAC,gBAAmD,EAAE,GAAG,kBAA4B,EAAE,EAAE;IACtG,MAAM,QAAQ,GAAG,OAAO,gBAAgB,KAAK,QAAQ;QACnD,CAAC,CAAC,EAAE,UAAU,EAAE,iBAAO,CAA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CAAC,mBAAmB,CAAC,CAAA;SAChD;QAED,OAAO,IAAI,EAAE,CAAA;IACf,CAAC,CAAA;AACH,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { HookContext } from '@feathersjs/feathers';
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
2
  import { ConnectionEvent } from '../core';
3
- declare const _default: (event: ConnectionEvent) => (context: HookContext) => Promise<HookContext<import("@feathersjs/feathers").Application<any, any>, any>>;
3
+ declare const _default: (event: ConnectionEvent) => (context: HookContext, next: NextFunction) => Promise<void>;
4
4
  export default _default;
@@ -1,26 +1,16 @@
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
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  const omit_1 = __importDefault(require("lodash/omit"));
16
- exports.default = (event) => (context) => __awaiter(void 0, void 0, void 0, function* () {
7
+ exports.default = (event) => async (context, next) => {
8
+ await next();
17
9
  const { result, params: { connection } } = context;
18
- if (!connection) {
19
- return context;
10
+ if (connection) {
11
+ const service = context.service;
12
+ Object.assign(connection, (0, omit_1.default)(result, 'accessToken', 'authentication'));
13
+ await service.handleConnection(event, connection, result);
20
14
  }
21
- const service = context.service;
22
- Object.assign(connection, omit_1.default(result, 'accessToken', 'authentication'));
23
- yield service.handleConnection(event, connection, result);
24
- return context;
25
- });
15
+ };
26
16
  //# sourceMappingURL=connection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/hooks/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AACA,uDAA+B;AAG/B,kBAAe,CAAC,KAAsB,EAAE,EAAE,CAAC,CAAO,OAAoB,EAAE,EAAE;IACxE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,EAAE,GAAG,OAAO,CAAC;IAEnD,IAAI,CAAC,UAAU,EAAE;QACf,OAAO,OAAO,CAAC;KAChB;IAED,MAAM,OAAO,GAAG,OAAO,CAAC,OAAwC,CAAC;IAEjE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,cAAI,CAAC,MAAM,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC,CAAC;IAEzE,MAAM,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC;IAE1D,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA,CAAC"}
1
+ {"version":3,"file":"connection.js","sourceRoot":"","sources":["../../src/hooks/connection.ts"],"names":[],"mappings":";;;;;AACA,uDAA8B;AAG9B,kBAAe,CAAC,KAAsB,EAAE,EAAE,CAAC,KAAK,EAAE,OAAoB,EAAE,IAAkB,EAAE,EAAE;IAC5F,MAAM,IAAI,EAAE,CAAA;IAEZ,MAAM,EACJ,MAAM,EACN,MAAM,EAAE,EAAE,UAAU,EAAE,EACvB,GAAG,OAAO,CAAA;IAEX,IAAI,UAAU,EAAE;QACd,MAAM,OAAO,GAAG,OAAO,CAAC,OAAwC,CAAA;QAEhE,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,IAAA,cAAI,EAAC,MAAM,EAAE,aAAa,EAAE,gBAAgB,CAAC,CAAC,CAAA;QAExE,MAAM,OAAO,CAAC,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,CAAA;KAC1D;AACH,CAAC,CAAA"}
@@ -1,4 +1,4 @@
1
- import { HookContext } from '@feathersjs/feathers';
1
+ import { HookContext, NextFunction } from '@feathersjs/feathers';
2
2
  import { ConnectionEvent } from '../core';
3
- declare const _default: (event: ConnectionEvent) => (context: HookContext) => Promise<HookContext<import("@feathersjs/feathers").Application<any, any>, any>>;
3
+ declare const _default: (event: ConnectionEvent) => (context: HookContext, next: NextFunction) => Promise<void>;
4
4
  export default _default;
@@ -1,22 +1,13 @@
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
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const commons_1 = require("@feathersjs/commons");
13
- const debug = commons_1.createDebug('@feathersjs/authentication/hooks/connection');
14
- exports.default = (event) => (context) => __awaiter(void 0, void 0, void 0, function* () {
4
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication/hooks/connection');
5
+ exports.default = (event) => async (context, next) => {
6
+ await next();
15
7
  const { app, result, params } = context;
16
8
  if (params.provider && result) {
17
9
  debug(`Sending authentication event '${event}'`);
18
10
  app.emit(event, result, params, context);
19
11
  }
20
- return context;
21
- });
12
+ };
22
13
  //# sourceMappingURL=event.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/hooks/event.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,iDAAkD;AAGlD,MAAM,KAAK,GAAG,qBAAW,CAAC,6CAA6C,CAAC,CAAC;AAEzE,kBAAe,CAAC,KAAsB,EAAE,EAAE,CAAC,CAAO,OAAoB,EAAE,EAAE;IACxE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAExC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,EAAE;QAC7B,KAAK,CAAC,iCAAiC,KAAK,GAAG,CAAC,CAAC;QACjD,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;KAC1C;IAED,OAAO,OAAO,CAAC;AACjB,CAAC,CAAA,CAAC"}
1
+ {"version":3,"file":"event.js","sourceRoot":"","sources":["../../src/hooks/event.ts"],"names":[],"mappings":";;AACA,iDAAiD;AAGjD,MAAM,KAAK,GAAG,IAAA,qBAAW,EAAC,6CAA6C,CAAC,CAAA;AAExE,kBAAe,CAAC,KAAsB,EAAE,EAAE,CAAC,KAAK,EAAE,OAAoB,EAAE,IAAkB,EAAE,EAAE;IAC5F,MAAM,IAAI,EAAE,CAAA;IAEZ,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAEvC,IAAI,MAAM,CAAC,QAAQ,IAAI,MAAM,EAAE;QAC7B,KAAK,CAAC,iCAAiC,KAAK,GAAG,CAAC,CAAA;QAChD,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;KACzC;AACH,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAyD;AAAhD,6HAAA,OAAO,OAAgB;AAChC,2CAAqD;AAA5C,yHAAA,OAAO,OAAc;AAC9B,iCAA2C;AAAlC,+GAAA,OAAO,OAAS"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAwD;AAA/C,6HAAA,OAAO,OAAgB;AAChC,2CAAoD;AAA3C,yHAAA,OAAO,OAAc;AAC9B,iCAA0C;AAAjC,+GAAA,OAAO,OAAS"}
package/lib/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import * as hooks from './hooks';
2
- declare const authenticate: (originalSettings: string | import("./hooks/authenticate").AuthenticateHookSettings, ...originalStrategies: string[]) => (context: import("@feathersjs/feathers/lib").HookContext<any, any>) => Promise<import("@feathersjs/feathers/lib").HookContext<any, any>>;
3
- export { hooks };
4
- export { authenticate };
5
- export { AuthenticationBase, AuthenticationRequest, AuthenticationResult, AuthenticationStrategy, ConnectionEvent } from './core';
1
+ export * as hooks from './hooks';
2
+ export { authenticate } from './hooks';
3
+ export { AuthenticationBase, AuthenticationRequest, AuthenticationResult, AuthenticationStrategy, AuthenticationParams, ConnectionEvent } from './core';
6
4
  export { AuthenticationBaseStrategy } from './strategy';
7
5
  export { AuthenticationService } from './service';
8
6
  export { JWTStrategy } from './jwt';
7
+ export { authenticationSettingsSchema, AuthenticationConfiguration } from './options';