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

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/lib/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -19,11 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
23
  return result;
20
24
  };
21
25
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.JWTStrategy = exports.AuthenticationService = exports.AuthenticationBaseStrategy = exports.AuthenticationBase = exports.authenticate = exports.hooks = void 0;
23
- const hooks = __importStar(require("./hooks"));
24
- exports.hooks = hooks;
25
- const { authenticate } = hooks;
26
- exports.authenticate = authenticate;
26
+ exports.authenticationSettingsSchema = exports.JWTStrategy = exports.AuthenticationService = exports.AuthenticationBaseStrategy = exports.AuthenticationBase = exports.authenticate = exports.hooks = void 0;
27
+ exports.hooks = __importStar(require("./hooks"));
28
+ var hooks_1 = require("./hooks");
29
+ Object.defineProperty(exports, "authenticate", { enumerable: true, get: function () { return hooks_1.authenticate; } });
27
30
  var core_1 = require("./core");
28
31
  Object.defineProperty(exports, "AuthenticationBase", { enumerable: true, get: function () { return core_1.AuthenticationBase; } });
29
32
  var strategy_1 = require("./strategy");
@@ -32,4 +35,6 @@ var service_1 = require("./service");
32
35
  Object.defineProperty(exports, "AuthenticationService", { enumerable: true, get: function () { return service_1.AuthenticationService; } });
33
36
  var jwt_1 = require("./jwt");
34
37
  Object.defineProperty(exports, "JWTStrategy", { enumerable: true, get: function () { return jwt_1.JWTStrategy; } });
38
+ var options_1 = require("./options");
39
+ Object.defineProperty(exports, "authenticationSettingsSchema", { enumerable: true, get: function () { return options_1.authenticationSettingsSchema; } });
35
40
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA,+CAAiC;AAIxB,sBAAK;AAFd,MAAM,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;AAGtB,oCAAY;AACrB,+BAMgB;AALd,0GAAA,kBAAkB,OAAA;AAMpB,uCAAwD;AAA/C,sHAAA,0BAA0B,OAAA;AACnC,qCAAkD;AAAzC,gHAAA,qBAAqB,OAAA;AAC9B,6BAAoC;AAA3B,kGAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAgC;AAChC,iCAAsC;AAA7B,qGAAA,YAAY,OAAA;AACrB,+BAOe;AANb,0GAAA,kBAAkB,OAAA;AAOpB,uCAAuD;AAA9C,sHAAA,0BAA0B,OAAA;AACnC,qCAAiD;AAAxC,gHAAA,qBAAqB,OAAA;AAC9B,6BAAmC;AAA1B,kGAAA,WAAW,OAAA;AACpB,qCAAqF;AAA5E,uHAAA,4BAA4B,OAAA"}
package/lib/jwt.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  import { IncomingMessage } from 'http';
3
3
  import { Params } from '@feathersjs/feathers';
4
4
  import { AuthenticationBaseStrategy } from './strategy';
5
- import { AuthenticationRequest, AuthenticationResult, ConnectionEvent } from './core';
5
+ import { AuthenticationParams, AuthenticationRequest, AuthenticationResult, ConnectionEvent } from './core';
6
6
  export declare class JWTStrategy extends AuthenticationBaseStrategy {
7
7
  expirationTimers: WeakMap<object, any>;
8
8
  get configuration(): any;
@@ -17,7 +17,7 @@ export declare class JWTStrategy extends AuthenticationBaseStrategy {
17
17
  */
18
18
  getEntity(id: string, params: Params): Promise<any>;
19
19
  getEntityId(authResult: AuthenticationResult, _params: Params): Promise<any>;
20
- authenticate(authentication: AuthenticationRequest, params: Params): Promise<{
20
+ authenticate(authentication: AuthenticationRequest, params: AuthenticationParams): Promise<{
21
21
  accessToken: any;
22
22
  authentication: {
23
23
  strategy: string;
@@ -28,5 +28,5 @@ export declare class JWTStrategy extends AuthenticationBaseStrategy {
28
28
  parse(req: IncomingMessage): Promise<{
29
29
  strategy: string;
30
30
  accessToken: string;
31
- }>;
31
+ } | null>;
32
32
  }
package/lib/jwt.js CHANGED
@@ -1,26 +1,17 @@
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
  exports.JWTStrategy = void 0;
16
- /* eslint-disable @typescript-eslint/no-unused-vars */
7
+ /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/ban-ts-comment */
17
8
  const omit_1 = __importDefault(require("lodash/omit"));
18
9
  const errors_1 = require("@feathersjs/errors");
19
10
  const commons_1 = require("@feathersjs/commons");
20
11
  // @ts-ignore
21
12
  const long_timeout_1 = __importDefault(require("long-timeout"));
22
13
  const strategy_1 = require("./strategy");
23
- const debug = commons_1.createDebug('@feathersjs/authentication/jwt');
14
+ const debug = (0, commons_1.createDebug)('@feathersjs/authentication/jwt');
24
15
  const SPLIT_HEADER = /(\S+)\s+(\S+)/;
25
16
  class JWTStrategy extends strategy_1.AuthenticationBaseStrategy {
26
17
  constructor() {
@@ -30,39 +21,46 @@ class JWTStrategy extends strategy_1.AuthenticationBaseStrategy {
30
21
  get configuration() {
31
22
  const authConfig = this.authentication.configuration;
32
23
  const config = super.configuration;
33
- return Object.assign({ service: authConfig.service, entity: authConfig.entity, entityId: authConfig.entityId, header: 'Authorization', schemes: ['Bearer', 'JWT'] }, config);
24
+ return {
25
+ service: authConfig.service,
26
+ entity: authConfig.entity,
27
+ entityId: authConfig.entityId,
28
+ header: 'Authorization',
29
+ schemes: ['Bearer', 'JWT'],
30
+ ...config
31
+ };
34
32
  }
35
- handleConnection(event, connection, authResult) {
36
- return __awaiter(this, void 0, void 0, function* () {
37
- const isValidLogout = event === 'logout' && connection.authentication && authResult &&
38
- connection.authentication.accessToken === authResult.accessToken;
39
- const { accessToken } = authResult || {};
40
- if (accessToken && event === 'login') {
41
- debug('Adding authentication information to connection');
42
- const { exp } = yield this.authentication.verifyAccessToken(accessToken);
43
- // The time (in ms) until the token expires
44
- const duration = (exp * 1000) - Date.now();
45
- // This may have to be a `logout` event but right now we don't want
46
- // the whole context object lingering around until the timer is gone
47
- const timer = long_timeout_1.default.setTimeout(() => this.app.emit('disconnect', connection), duration);
48
- debug(`Registering connection expiration timer for ${duration}ms`);
49
- long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
50
- this.expirationTimers.set(connection, timer);
51
- debug('Adding authentication information to connection');
52
- connection.authentication = {
53
- strategy: this.name,
54
- accessToken
55
- };
56
- }
57
- else if (event === 'disconnect' || isValidLogout) {
58
- debug('Removing authentication information and expiration timer from connection');
59
- const { entity } = this.configuration;
60
- delete connection[entity];
61
- delete connection.authentication;
62
- long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
63
- this.expirationTimers.delete(connection);
64
- }
65
- });
33
+ async handleConnection(event, connection, authResult) {
34
+ const isValidLogout = event === 'logout' &&
35
+ connection.authentication &&
36
+ authResult &&
37
+ connection.authentication.accessToken === authResult.accessToken;
38
+ const { accessToken } = authResult || {};
39
+ if (accessToken && event === 'login') {
40
+ debug('Adding authentication information to connection');
41
+ const { exp } = await this.authentication.verifyAccessToken(accessToken);
42
+ // The time (in ms) until the token expires
43
+ const duration = exp * 1000 - Date.now();
44
+ // This may have to be a `logout` event but right now we don't want
45
+ // the whole context object lingering around until the timer is gone
46
+ const timer = long_timeout_1.default.setTimeout(() => this.app.emit('disconnect', connection), duration);
47
+ debug(`Registering connection expiration timer for ${duration}ms`);
48
+ long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
49
+ this.expirationTimers.set(connection, timer);
50
+ debug('Adding authentication information to connection');
51
+ connection.authentication = {
52
+ strategy: this.name,
53
+ accessToken
54
+ };
55
+ }
56
+ else if (event === 'disconnect' || isValidLogout) {
57
+ debug('Removing authentication information and expiration timer from connection');
58
+ const { entity } = this.configuration;
59
+ delete connection[entity];
60
+ delete connection.authentication;
61
+ long_timeout_1.default.clearTimeout(this.expirationTimers.get(connection));
62
+ this.expirationTimers.delete(connection);
63
+ }
66
64
  }
67
65
  verifyConfiguration() {
68
66
  const allowedKeys = ['entity', 'entityId', 'service', 'header', 'schemes'];
@@ -75,10 +73,8 @@ class JWTStrategy extends strategy_1.AuthenticationBaseStrategy {
75
73
  throw new Error(`The 'header' option for the ${this.name} strategy must be a string`);
76
74
  }
77
75
  }
78
- getEntityQuery(_params) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- return {};
81
- });
76
+ async getEntityQuery(_params) {
77
+ return {};
82
78
  }
83
79
  /**
84
80
  * Return the entity for a given id
@@ -86,70 +82,65 @@ class JWTStrategy extends strategy_1.AuthenticationBaseStrategy {
86
82
  * @param id The id to use
87
83
  * @param params Service call parameters
88
84
  */
89
- getEntity(id, params) {
90
- return __awaiter(this, void 0, void 0, function* () {
91
- const entityService = this.entityService;
92
- const { entity } = this.configuration;
93
- debug('Getting entity', id);
94
- if (entityService === null) {
95
- throw new errors_1.NotAuthenticated('Could not find entity service');
96
- }
97
- const query = yield this.getEntityQuery(params);
98
- const getParams = Object.assign({}, omit_1.default(params, 'provider'), { query });
99
- const result = yield entityService.get(id, getParams);
100
- if (!params.provider) {
101
- return result;
102
- }
103
- return entityService.get(id, Object.assign(Object.assign({}, params), { [entity]: result }));
104
- });
85
+ async getEntity(id, params) {
86
+ const entityService = this.entityService;
87
+ const { entity } = this.configuration;
88
+ debug('Getting entity', id);
89
+ if (entityService === null) {
90
+ throw new errors_1.NotAuthenticated('Could not find entity service');
91
+ }
92
+ const query = await this.getEntityQuery(params);
93
+ const getParams = Object.assign({}, (0, omit_1.default)(params, 'provider'), { query });
94
+ const result = await entityService.get(id, getParams);
95
+ if (!params.provider) {
96
+ return result;
97
+ }
98
+ return entityService.get(id, { ...params, [entity]: result });
105
99
  }
106
- getEntityId(authResult, _params) {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- return authResult.authentication.payload.sub;
109
- });
100
+ async getEntityId(authResult, _params) {
101
+ return authResult.authentication.payload.sub;
110
102
  }
111
- authenticate(authentication, params) {
112
- return __awaiter(this, void 0, void 0, function* () {
113
- const { accessToken } = authentication;
114
- const { entity } = this.configuration;
115
- if (!accessToken) {
116
- throw new errors_1.NotAuthenticated('No access token');
117
- }
118
- const payload = yield this.authentication.verifyAccessToken(accessToken, params.jwt);
119
- const result = {
103
+ async authenticate(authentication, params) {
104
+ const { accessToken } = authentication;
105
+ const { entity } = this.configuration;
106
+ if (!accessToken) {
107
+ throw new errors_1.NotAuthenticated('No access token');
108
+ }
109
+ const payload = await this.authentication.verifyAccessToken(accessToken, params.jwt);
110
+ const result = {
111
+ accessToken,
112
+ authentication: {
113
+ strategy: 'jwt',
120
114
  accessToken,
121
- authentication: {
122
- strategy: 'jwt',
123
- accessToken,
124
- payload
125
- }
126
- };
127
- if (entity === null) {
128
- return result;
115
+ payload
129
116
  }
130
- const entityId = yield this.getEntityId(result, params);
131
- const value = yield this.getEntity(entityId, params);
132
- return Object.assign(Object.assign({}, result), { [entity]: value });
133
- });
117
+ };
118
+ if (entity === null) {
119
+ return result;
120
+ }
121
+ const entityId = await this.getEntityId(result, params);
122
+ const value = await this.getEntity(entityId, params);
123
+ return {
124
+ ...result,
125
+ [entity]: value
126
+ };
134
127
  }
135
- parse(req) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- const { header, schemes } = this.configuration;
138
- const headerValue = req.headers && req.headers[header.toLowerCase()];
139
- if (!headerValue || typeof headerValue !== 'string') {
140
- return null;
141
- }
142
- debug('Found parsed header value');
143
- const [, scheme, schemeValue] = headerValue.match(SPLIT_HEADER) || [];
144
- const hasScheme = scheme && schemes.some(current => new RegExp(current, 'i').test(scheme));
145
- if (scheme && !hasScheme) {
146
- return null;
147
- }
148
- return {
149
- strategy: this.name,
150
- accessToken: hasScheme ? schemeValue : headerValue
151
- };
152
- });
128
+ async parse(req) {
129
+ const { header, schemes } = this.configuration;
130
+ const headerValue = req.headers && req.headers[header.toLowerCase()];
131
+ if (!headerValue || typeof headerValue !== 'string') {
132
+ return null;
133
+ }
134
+ debug('Found parsed header value');
135
+ const [, scheme, schemeValue] = headerValue.match(SPLIT_HEADER) || [];
136
+ const hasScheme = scheme && schemes.some((current) => new RegExp(current, 'i').test(scheme));
137
+ if (scheme && !hasScheme) {
138
+ return null;
139
+ }
140
+ return {
141
+ strategy: this.name,
142
+ accessToken: hasScheme ? schemeValue : headerValue
143
+ };
153
144
  }
154
145
  }
155
146
  exports.JWTStrategy = JWTStrategy;
package/lib/jwt.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"jwt.js","sourceRoot":"","sources":["../src/jwt.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,sDAAsD;AACtD,uDAA+B;AAE/B,+CAAsD;AAEt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K,CAAC,GAAoB;QAI9B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAA0C,IAAI,CAAC,aAAa,CAAA;QACrF,MAAM,WAAW,GAAG,GAAG,CAAC,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAA;QAEpE,IAAI,CAAC,WAAW,IAAI,OAAO,WAAW,KAAK,QAAQ,EAAE;YACnD,OAAO,IAAI,CAAA;SACZ;QAED,KAAK,CAAC,2BAA2B,CAAC,CAAA;QAElC,MAAM,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,GAAG,WAAW,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,CAAA;QACrE,MAAM,SAAS,GAAG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAA;QAE5F,IAAI,MAAM,IAAI,CAAC,SAAS,EAAE;YACxB,OAAO,IAAI,CAAA;SACZ;QAED,OAAO;YACL,QAAQ,EAAE,IAAI,CAAC,IAAI;YACnB,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW;SACnD,CAAA;IACH,CAAC;CACF;AAxKD,kCAwKC"}
package/lib/options.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- declare const _default: {
2
- authStrategies: any[];
1
+ import { FromSchema, authenticationSettingsSchema } from '@feathersjs/schema';
2
+ export declare const defaultOptions: {
3
+ authStrategies: string[];
3
4
  jwtOptions: {
4
5
  header: {
5
6
  typ: string;
@@ -10,4 +11,5 @@ declare const _default: {
10
11
  expiresIn: string;
11
12
  };
12
13
  };
13
- export default _default;
14
+ export { authenticationSettingsSchema };
15
+ export declare type AuthenticationConfiguration = FromSchema<typeof authenticationSettingsSchema>;
package/lib/options.js CHANGED
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {
3
+ exports.authenticationSettingsSchema = exports.defaultOptions = void 0;
4
+ const schema_1 = require("@feathersjs/schema");
5
+ Object.defineProperty(exports, "authenticationSettingsSchema", { enumerable: true, get: function () { return schema_1.authenticationSettingsSchema; } });
6
+ exports.defaultOptions = {
4
7
  authStrategies: [],
5
8
  jwtOptions: {
6
9
  header: { typ: 'access' },
@@ -1 +1 @@
1
- {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;AAAA,kBAAe;IACb,cAAc,EAAE,EAAE;IAClB,UAAU,EAAE;QACV,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;QACzB,QAAQ,EAAE,wBAAwB;QAClC,MAAM,EAAE,UAAU;QAClB,SAAS,EAAE,OAAO;QAClB,SAAS,EAAE,IAAI;KAChB;CACF,CAAC"}
1
+ {"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":";;;AAAA,+CAA6E;AAapE,6GAbY,qCAA4B,OAaZ;AAXxB,QAAA,cAAc,GAAG;IAC5B,cAAc,EAAE,EAAc;IAC9B,UAAU,EAAE;QACV,MAAM,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE;QACzB,QAAQ,EAAE,wBAAwB;QAClC,MAAM,EAAE,UAAU;QAClB,SAAS,EAAE,OAAO;QAClB,SAAS,EAAE,IAAI;KAChB;CACF,CAAA"}
package/lib/service.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { AuthenticationBase, AuthenticationResult, AuthenticationRequest } from './core';
2
1
  import '@feathersjs/transport-commons';
3
- import { Params, ServiceMethods, ServiceAddons } from '@feathersjs/feathers';
2
+ import { ServiceMethods, ServiceAddons } from '@feathersjs/feathers';
3
+ import { AuthenticationBase, AuthenticationResult, AuthenticationRequest, AuthenticationParams } from './core';
4
4
  declare module '@feathersjs/feathers/lib/declarations' {
5
- interface FeathersApplication<ServiceTypes, AppSettings> {
5
+ interface FeathersApplication<Services, Settings> {
6
6
  /**
7
7
  * Returns the default authentication service or the
8
8
  * authentication service for a given path.
@@ -18,7 +18,7 @@ declare module '@feathersjs/feathers/lib/declarations' {
18
18
  }
19
19
  export interface AuthenticationService extends ServiceAddons<AuthenticationResult, AuthenticationResult> {
20
20
  }
21
- export declare class AuthenticationService extends AuthenticationBase implements Partial<ServiceMethods<AuthenticationResult>> {
21
+ export declare class AuthenticationService extends AuthenticationBase implements Partial<ServiceMethods<AuthenticationResult, AuthenticationRequest, AuthenticationParams>> {
22
22
  constructor(app: any, configKey?: string, options?: {});
23
23
  /**
24
24
  * Return the payload for a JWT based on the authentication result.
@@ -27,7 +27,9 @@ export declare class AuthenticationService extends AuthenticationBase implements
27
27
  * @param _authResult The current authentication result
28
28
  * @param params The service call parameters
29
29
  */
30
- getPayload(_authResult: AuthenticationResult, params: Params): Promise<any>;
30
+ getPayload(_authResult: AuthenticationResult, params: AuthenticationParams): Promise<{
31
+ [key: string]: any;
32
+ }>;
31
33
  /**
32
34
  * Returns the JWT options based on an authentication result.
33
35
  * By default sets the JWT subject to the entity id.
@@ -35,7 +37,7 @@ export declare class AuthenticationService extends AuthenticationBase implements
35
37
  * @param authResult The authentication result
36
38
  * @param params Service call parameters
37
39
  */
38
- getTokenOptions(authResult: AuthenticationResult, params: Params): Promise<any>;
40
+ getTokenOptions(authResult: AuthenticationResult, params: AuthenticationParams): Promise<any>;
39
41
  /**
40
42
  * Create and return a new JWT for a given authentication request.
41
43
  * Will trigger the `login` event.
@@ -43,7 +45,7 @@ export declare class AuthenticationService extends AuthenticationBase implements
43
45
  * @param data The authentication request (should include `strategy` key)
44
46
  * @param params Service call parameters
45
47
  */
46
- create(data: AuthenticationRequest, params?: Params): Promise<AuthenticationResult>;
48
+ create(data: AuthenticationRequest, params?: AuthenticationParams): Promise<AuthenticationResult>;
47
49
  /**
48
50
  * Mark a JWT as removed. By default only verifies the JWT and returns the result.
49
51
  * Triggers the `logout` event.
@@ -51,7 +53,7 @@ export declare class AuthenticationService extends AuthenticationBase implements
51
53
  * @param id The JWT to remove or null
52
54
  * @param params Service call parameters
53
55
  */
54
- remove(id: string | null, params?: Params): Promise<AuthenticationResult>;
56
+ remove(id: string | null, params?: AuthenticationParams): Promise<AuthenticationResult>;
55
57
  /**
56
58
  * Validates the service configuration.
57
59
  */