@feathersjs/authentication 5.0.0-pre.1 → 5.0.0-pre.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +162 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/lib/core.d.ts +7 -0
- package/lib/core.js +70 -77
- package/lib/core.js.map +1 -1
- package/lib/hooks/authenticate.d.ts +2 -2
- package/lib/hooks/authenticate.js +11 -20
- package/lib/hooks/authenticate.js.map +1 -1
- package/lib/hooks/connection.d.ts +2 -2
- package/lib/hooks/connection.js +7 -17
- package/lib/hooks/connection.js.map +1 -1
- package/lib/hooks/event.d.ts +2 -2
- package/lib/hooks/event.js +5 -17
- package/lib/hooks/event.js.map +1 -1
- package/lib/index.d.ts +2 -4
- package/lib/index.js +3 -4
- package/lib/index.js.map +1 -1
- package/lib/jwt.d.ts +1 -1
- package/lib/jwt.js +95 -106
- package/lib/jwt.js.map +1 -1
- package/lib/service.d.ts +8 -8
- package/lib/service.js +54 -73
- package/lib/service.js.map +1 -1
- package/lib/strategy.d.ts +1 -1
- package/package.json +18 -19
- package/src/core.ts +13 -3
- package/src/hooks/authenticate.ts +7 -8
- package/src/hooks/connection.ts +9 -11
- package/src/hooks/event.ts +6 -6
- package/src/index.ts +2 -6
- package/src/jwt.ts +6 -3
- package/src/service.ts +13 -16
- package/src/strategy.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/authentication",
|
|
3
3
|
"description": "Add Authentication to your FeathersJS app.",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.15",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"url": "https://github.com/feathersjs/feathers/issues"
|
|
38
38
|
},
|
|
39
39
|
"engines": {
|
|
40
|
-
"node": ">=
|
|
40
|
+
"node": ">= 12"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
43
|
"prepublish": "npm run compile",
|
|
@@ -52,27 +52,26 @@
|
|
|
52
52
|
"access": "public"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@feathersjs/
|
|
56
|
-
"@feathersjs/
|
|
57
|
-
"@feathersjs/
|
|
58
|
-
"@
|
|
59
|
-
"
|
|
55
|
+
"@feathersjs/commons": "^5.0.0-pre.15",
|
|
56
|
+
"@feathersjs/errors": "^5.0.0-pre.15",
|
|
57
|
+
"@feathersjs/feathers": "^5.0.0-pre.15",
|
|
58
|
+
"@feathersjs/transport-commons": "^5.0.0-pre.15",
|
|
59
|
+
"@types/jsonwebtoken": "^8.5.5",
|
|
60
60
|
"jsonwebtoken": "^8.5.1",
|
|
61
|
-
"lodash": "^4.17.
|
|
61
|
+
"lodash": "^4.17.21",
|
|
62
62
|
"long-timeout": "^0.1.1",
|
|
63
|
-
"uuid": "^8.3.
|
|
63
|
+
"uuid": "^8.3.2"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@feathersjs/
|
|
67
|
-
"@types/
|
|
68
|
-
"@types/
|
|
69
|
-
"@types/
|
|
70
|
-
"@types/
|
|
71
|
-
"
|
|
72
|
-
"mocha": "^8.2.1",
|
|
66
|
+
"@feathersjs/memory": "^5.0.0-pre.15",
|
|
67
|
+
"@types/lodash": "^4.14.176",
|
|
68
|
+
"@types/mocha": "^9.0.0",
|
|
69
|
+
"@types/node": "^16.11.6",
|
|
70
|
+
"@types/uuid": "^8.3.1",
|
|
71
|
+
"mocha": "^9.1.3",
|
|
73
72
|
"shx": "^0.3.3",
|
|
74
|
-
"ts-node": "^
|
|
75
|
-
"typescript": "^4.
|
|
73
|
+
"ts-node": "^10.4.0",
|
|
74
|
+
"typescript": "^4.4.4"
|
|
76
75
|
},
|
|
77
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "8008bf4f8529a2a40b6a2f976c1f43ae13675693"
|
|
78
77
|
}
|
package/src/core.ts
CHANGED
|
@@ -2,12 +2,12 @@ import merge from 'lodash/merge';
|
|
|
2
2
|
import jsonwebtoken, { SignOptions, Secret, VerifyOptions } from 'jsonwebtoken';
|
|
3
3
|
import { v4 as uuidv4 } from 'uuid';
|
|
4
4
|
import { NotAuthenticated } from '@feathersjs/errors';
|
|
5
|
-
import
|
|
5
|
+
import { createDebug } from '@feathersjs/commons';
|
|
6
6
|
import { Application, Params } from '@feathersjs/feathers';
|
|
7
7
|
import { IncomingMessage, ServerResponse } from 'http';
|
|
8
8
|
import defaultOptions from './options';
|
|
9
9
|
|
|
10
|
-
const debug =
|
|
10
|
+
const debug = createDebug('@feathersjs/authentication/base');
|
|
11
11
|
|
|
12
12
|
export interface AuthenticationResult {
|
|
13
13
|
[key: string]: any;
|
|
@@ -155,6 +155,16 @@ export class AuthenticationBase {
|
|
|
155
155
|
.filter(current => !!current);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Returns a single strategy by name
|
|
160
|
+
*
|
|
161
|
+
* @param name The strategy name
|
|
162
|
+
* @returns The authentication strategy or undefined
|
|
163
|
+
*/
|
|
164
|
+
getStrategy (name: string) {
|
|
165
|
+
return this.strategies[name];
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
/**
|
|
159
169
|
* Create a new access token with payload and options.
|
|
160
170
|
*
|
|
@@ -200,7 +210,7 @@ export class AuthenticationBase {
|
|
|
200
210
|
const verified = jsonwebtoken.verify(accessToken, jwtSecret, options);
|
|
201
211
|
|
|
202
212
|
return verified as any;
|
|
203
|
-
} catch (error) {
|
|
213
|
+
} catch (error: any) {
|
|
204
214
|
throw new NotAuthenticated(error.message, error);
|
|
205
215
|
}
|
|
206
216
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import flatten from 'lodash/flatten';
|
|
2
2
|
import omit from 'lodash/omit';
|
|
3
|
-
import { HookContext } from '@feathersjs/feathers';
|
|
3
|
+
import { HookContext, NextFunction } from '@feathersjs/feathers';
|
|
4
4
|
import { NotAuthenticated } from '@feathersjs/errors';
|
|
5
|
-
import
|
|
5
|
+
import { createDebug } from '@feathersjs/commons';
|
|
6
6
|
|
|
7
|
-
const debug =
|
|
7
|
+
const debug = createDebug('@feathersjs/authentication/hooks/authenticate');
|
|
8
8
|
|
|
9
9
|
export interface AuthenticateHookSettings {
|
|
10
10
|
service?: string;
|
|
@@ -20,7 +20,8 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original
|
|
|
20
20
|
throw new Error('The authenticate hook needs at least one allowed strategy');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
return async (context: HookContext) => {
|
|
23
|
+
return async (context: HookContext, _next?: NextFunction) => {
|
|
24
|
+
const next = typeof _next === 'function' ? _next : async () => context;
|
|
24
25
|
const { app, params, type, path, service } = context;
|
|
25
26
|
const { strategies } = settings;
|
|
26
27
|
const { provider, authentication } = params;
|
|
@@ -42,7 +43,7 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
if (params.authenticated === true) {
|
|
45
|
-
return
|
|
46
|
+
return next();
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
if (authentication) {
|
|
@@ -53,12 +54,10 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original
|
|
|
53
54
|
const authResult = await authService.authenticate(authentication, authParams, ...strategies);
|
|
54
55
|
|
|
55
56
|
context.params = Object.assign({}, params, omit(authResult, 'accessToken'), { authenticated: true });
|
|
56
|
-
|
|
57
|
-
return context;
|
|
58
57
|
} else if (provider) {
|
|
59
58
|
throw new NotAuthenticated('Not authenticated');
|
|
60
59
|
}
|
|
61
60
|
|
|
62
|
-
return
|
|
61
|
+
return next();
|
|
63
62
|
};
|
|
64
63
|
};
|
package/src/hooks/connection.ts
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { HookContext } from '@feathersjs/feathers';
|
|
1
|
+
import { HookContext, NextFunction } from '@feathersjs/feathers';
|
|
2
2
|
import omit from 'lodash/omit';
|
|
3
3
|
import { AuthenticationBase, ConnectionEvent } from '../core';
|
|
4
4
|
|
|
5
|
-
export default (event: ConnectionEvent) => async (context: HookContext) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (!connection) {
|
|
9
|
-
return context;
|
|
10
|
-
}
|
|
5
|
+
export default (event: ConnectionEvent) => async (context: HookContext, next: NextFunction) => {
|
|
6
|
+
await next();
|
|
11
7
|
|
|
12
|
-
const
|
|
8
|
+
const { result, params: { connection } } = context;
|
|
13
9
|
|
|
14
|
-
|
|
10
|
+
if (connection) {
|
|
11
|
+
const service = context.service as unknown as AuthenticationBase;
|
|
15
12
|
|
|
16
|
-
|
|
13
|
+
Object.assign(connection, omit(result, 'accessToken', 'authentication'));
|
|
17
14
|
|
|
18
|
-
|
|
15
|
+
await service.handleConnection(event, connection, result);
|
|
16
|
+
}
|
|
19
17
|
};
|
package/src/hooks/event.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { HookContext, NextFunction } from '@feathersjs/feathers';
|
|
2
|
+
import { createDebug } from '@feathersjs/commons';
|
|
3
3
|
import { ConnectionEvent } from '../core';
|
|
4
4
|
|
|
5
|
-
const debug =
|
|
5
|
+
const debug = createDebug('@feathersjs/authentication/hooks/connection');
|
|
6
|
+
|
|
7
|
+
export default (event: ConnectionEvent) => async (context: HookContext, next: NextFunction) => {
|
|
8
|
+
await next();
|
|
6
9
|
|
|
7
|
-
export default (event: ConnectionEvent) => async (context: HookContext) => {
|
|
8
10
|
const { app, result, params } = context;
|
|
9
11
|
|
|
10
12
|
if (params.provider && result) {
|
|
11
13
|
debug(`Sending authentication event '${event}'`);
|
|
12
14
|
app.emit(event, result, params, context);
|
|
13
15
|
}
|
|
14
|
-
|
|
15
|
-
return context;
|
|
16
16
|
};
|
package/src/index.ts
CHANGED
package/src/jwt.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
-
import Debug from 'debug';
|
|
3
2
|
import omit from 'lodash/omit';
|
|
4
3
|
import { IncomingMessage } from 'http';
|
|
5
4
|
import { NotAuthenticated } from '@feathersjs/errors';
|
|
6
5
|
import { Params } from '@feathersjs/feathers';
|
|
6
|
+
import { createDebug } from '@feathersjs/commons';
|
|
7
7
|
// @ts-ignore
|
|
8
8
|
import lt from 'long-timeout';
|
|
9
9
|
|
|
10
10
|
import { AuthenticationBaseStrategy } from './strategy';
|
|
11
11
|
import { AuthenticationRequest, AuthenticationResult, ConnectionEvent } from './core';
|
|
12
12
|
|
|
13
|
-
const debug =
|
|
13
|
+
const debug = createDebug('@feathersjs/authentication/jwt');
|
|
14
14
|
const SPLIT_HEADER = /(\S+)\s+(\S+)/;
|
|
15
15
|
|
|
16
16
|
export class JWTStrategy extends AuthenticationBaseStrategy {
|
|
@@ -147,7 +147,10 @@ export class JWTStrategy extends AuthenticationBaseStrategy {
|
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
async parse (req: IncomingMessage) {
|
|
150
|
+
async parse (req: IncomingMessage): Promise<{
|
|
151
|
+
strategy: string;
|
|
152
|
+
accessToken: string;
|
|
153
|
+
} | null> {
|
|
151
154
|
const { header, schemes }: { header: string, schemes: string[] } = this.configuration;
|
|
152
155
|
const headerValue = req.headers && req.headers[header.toLowerCase()];
|
|
153
156
|
|
package/src/service.ts
CHANGED
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import Debug from 'debug';
|
|
2
1
|
import merge from 'lodash/merge';
|
|
3
2
|
import { NotAuthenticated } from '@feathersjs/errors';
|
|
4
3
|
import { AuthenticationBase, AuthenticationResult, AuthenticationRequest } from './core';
|
|
5
4
|
import { connection, event } from './hooks';
|
|
6
5
|
import '@feathersjs/transport-commons';
|
|
7
|
-
import {
|
|
6
|
+
import { createDebug } from '@feathersjs/commons';
|
|
7
|
+
import { Params, ServiceMethods, ServiceAddons } from '@feathersjs/feathers';
|
|
8
8
|
import jsonwebtoken from 'jsonwebtoken';
|
|
9
9
|
|
|
10
|
-
const debug =
|
|
10
|
+
const debug = createDebug('@feathersjs/authentication/service');
|
|
11
11
|
|
|
12
12
|
declare module '@feathersjs/feathers/lib/declarations' {
|
|
13
|
-
interface
|
|
14
|
-
|
|
13
|
+
interface FeathersApplication<Services, Settings> { // eslint-disable-line
|
|
15
14
|
/**
|
|
16
15
|
* Returns the default authentication service or the
|
|
17
16
|
* authentication service for a given path.
|
|
18
17
|
*
|
|
19
18
|
* @param location The service path to use (optional)
|
|
20
19
|
*/
|
|
21
|
-
defaultAuthentication (location?: string): AuthenticationService;
|
|
20
|
+
defaultAuthentication? (location?: string): AuthenticationService;
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
interface Params {
|
|
@@ -28,10 +27,10 @@ declare module '@feathersjs/feathers/lib/declarations' {
|
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
// eslint-disable-next-line
|
|
31
|
-
export interface AuthenticationService extends ServiceAddons<AuthenticationResult> {}
|
|
30
|
+
export interface AuthenticationService extends ServiceAddons<AuthenticationResult, AuthenticationResult> {}
|
|
32
31
|
|
|
33
32
|
export class AuthenticationService extends AuthenticationBase implements Partial<ServiceMethods<AuthenticationResult>> {
|
|
34
|
-
constructor (app:
|
|
33
|
+
constructor (app: any, configKey = 'authentication', options = {}) {
|
|
35
34
|
super(app, configKey, options);
|
|
36
35
|
|
|
37
36
|
if (typeof app.defaultAuthentication !== 'function') {
|
|
@@ -93,7 +92,7 @@ export class AuthenticationService extends AuthenticationBase implements Partial
|
|
|
93
92
|
* @param data The authentication request (should include `strategy` key)
|
|
94
93
|
* @param params Service call parameters
|
|
95
94
|
*/
|
|
96
|
-
async create (data: AuthenticationRequest, params
|
|
95
|
+
async create (data: AuthenticationRequest, params?: Params) {
|
|
97
96
|
const authStrategies = params.authStrategies || this.configuration.authStrategies;
|
|
98
97
|
|
|
99
98
|
if (!authStrategies.length) {
|
|
@@ -132,7 +131,7 @@ export class AuthenticationService extends AuthenticationBase implements Partial
|
|
|
132
131
|
* @param id The JWT to remove or null
|
|
133
132
|
* @param params Service call parameters
|
|
134
133
|
*/
|
|
135
|
-
async remove (id: string | null, params
|
|
134
|
+
async remove (id: string | null, params?: Params) {
|
|
136
135
|
const { authentication } = params;
|
|
137
136
|
const { authStrategies } = this.configuration;
|
|
138
137
|
|
|
@@ -149,7 +148,7 @@ export class AuthenticationService extends AuthenticationBase implements Partial
|
|
|
149
148
|
/**
|
|
150
149
|
* Validates the service configuration.
|
|
151
150
|
*/
|
|
152
|
-
setup () {
|
|
151
|
+
async setup () {
|
|
153
152
|
// The setup method checks for valid settings and registers the
|
|
154
153
|
// connection and event (login, logout) hooks
|
|
155
154
|
const { secret, service, entity, entityId } = this.configuration;
|
|
@@ -172,11 +171,9 @@ export class AuthenticationService extends AuthenticationBase implements Partial
|
|
|
172
171
|
}
|
|
173
172
|
}
|
|
174
173
|
|
|
175
|
-
this.hooks({
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
remove: [ connection('logout'), event('logout') ]
|
|
179
|
-
}
|
|
174
|
+
(this as any).hooks({
|
|
175
|
+
create: [ connection('login'), event('login') ],
|
|
176
|
+
remove: [ connection('logout'), event('logout') ]
|
|
180
177
|
});
|
|
181
178
|
|
|
182
179
|
this.app.on('disconnect', async (connection) => {
|
package/src/strategy.ts
CHANGED
|
@@ -22,7 +22,7 @@ export class AuthenticationBaseStrategy implements AuthenticationStrategy {
|
|
|
22
22
|
return this.authentication.configuration[this.name];
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
get entityService (): Service
|
|
25
|
+
get entityService (): Service {
|
|
26
26
|
const { service } = this.configuration;
|
|
27
27
|
|
|
28
28
|
if (!service) {
|