@feathersjs/authentication-client 5.0.0-pre.33 → 5.0.0-pre.34
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 +8 -0
- package/lib/core.d.ts +50 -2
- package/lib/core.js +58 -12
- package/lib/core.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/package.json +16 -16
- package/src/core.ts +58 -14
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.34](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.33...v5.0.0-pre.34) (2022-12-14)
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
- **authentication-client:** Do not cache authentication errors ([#2892](https://github.com/feathersjs/feathers/issues/2892)) ([cc4e767](https://github.com/feathersjs/feathers/commit/cc4e76726fce1ac73252cfd92e22570d4bdeca20))
|
|
11
|
+
- **authentication-client:** Improve socket reauthentication handling ([#2895](https://github.com/feathersjs/feathers/issues/2895)) ([9db5e7a](https://github.com/feathersjs/feathers/commit/9db5e7adb0f6aea43d607f530d8258ade98b7362))
|
|
12
|
+
- **authentication-client:** Remove access token for fatal 400 errors ([#2894](https://github.com/feathersjs/feathers/issues/2894)) ([cfc6c7a](https://github.com/feathersjs/feathers/commit/cfc6c7a6b9dbc7fb60816e2b7f15897c38deb98d))
|
|
13
|
+
|
|
6
14
|
# [5.0.0-pre.33](https://github.com/feathersjs/feathers/compare/v5.0.0-pre.32...v5.0.0-pre.33) (2022-11-08)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @feathersjs/authentication-client
|
package/lib/core.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { FeathersError } from '@feathersjs/errors';
|
|
|
2
2
|
import { Application, Params } from '@feathersjs/feathers';
|
|
3
3
|
import { AuthenticationRequest, AuthenticationResult } from '@feathersjs/authentication';
|
|
4
4
|
import { Storage } from './storage';
|
|
5
|
-
export
|
|
5
|
+
export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
|
|
6
6
|
export interface AuthenticationClientOptions {
|
|
7
7
|
storage: Storage;
|
|
8
8
|
header: string;
|
|
@@ -19,16 +19,64 @@ export declare class AuthenticationClient {
|
|
|
19
19
|
authenticated: boolean;
|
|
20
20
|
options: AuthenticationClientOptions;
|
|
21
21
|
constructor(app: Application, options: AuthenticationClientOptions);
|
|
22
|
-
get service(): import("@feathersjs/feathers").FeathersService<Application<any, any>, import("@feathersjs/feathers").Service<any, Partial<any>, Params<import("@feathersjs/feathers").Query
|
|
22
|
+
get service(): import("@feathersjs/feathers").FeathersService<Application<any, any>, import("@feathersjs/feathers").Service<any, Partial<any>, Params<import("@feathersjs/feathers").Query>, Partial<Partial<any>>>>;
|
|
23
23
|
get storage(): Storage;
|
|
24
24
|
handleSocket(socket: any): void;
|
|
25
|
+
/**
|
|
26
|
+
* Parse the access token or authentication error from the window location hash. Will remove it from the hash
|
|
27
|
+
* if found.
|
|
28
|
+
*
|
|
29
|
+
* @param location The window location
|
|
30
|
+
* @returns The access token if available, will throw an error if found, otherwise null
|
|
31
|
+
*/
|
|
25
32
|
getFromLocation(location: Location): Promise<any>;
|
|
33
|
+
/**
|
|
34
|
+
* Set the access token in storage.
|
|
35
|
+
*
|
|
36
|
+
* @param accessToken The access token to set
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
26
39
|
setAccessToken(accessToken: string): any;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the access token from storage or the window location hash.
|
|
42
|
+
*
|
|
43
|
+
* @returns The access token from storage or location hash
|
|
44
|
+
*/
|
|
27
45
|
getAccessToken(): Promise<string | null>;
|
|
46
|
+
/**
|
|
47
|
+
* Remove the access token from storage
|
|
48
|
+
* @returns The removed access token
|
|
49
|
+
*/
|
|
28
50
|
removeAccessToken(): any;
|
|
51
|
+
/**
|
|
52
|
+
* Reset the internal authentication state. Usually not necessary to call directly.
|
|
53
|
+
*
|
|
54
|
+
* @returns null
|
|
55
|
+
*/
|
|
29
56
|
reset(): Promise<any>;
|
|
30
57
|
handleError(error: FeathersError, type: 'authenticate' | 'logout'): any;
|
|
58
|
+
/**
|
|
59
|
+
* Try to reauthenticate using the token from storage. Will do nothing if already authenticated unless
|
|
60
|
+
* `force` is true.
|
|
61
|
+
*
|
|
62
|
+
* @param force force reauthentication with the server
|
|
63
|
+
* @param strategy The name of the strategy to use. Defaults to `options.jwtStrategy`
|
|
64
|
+
* @returns The reauthentication result
|
|
65
|
+
*/
|
|
31
66
|
reAuthenticate(force?: boolean, strategy?: string): Promise<AuthenticationResult>;
|
|
67
|
+
/**
|
|
68
|
+
* Authenticate using a specific strategy and data.
|
|
69
|
+
*
|
|
70
|
+
* @param authentication The authentication data
|
|
71
|
+
* @param params Additional parameters
|
|
72
|
+
* @returns The authentication result
|
|
73
|
+
*/
|
|
32
74
|
authenticate(authentication?: AuthenticationRequest, params?: Params): Promise<AuthenticationResult>;
|
|
75
|
+
/**
|
|
76
|
+
* Log out the current user and remove their token. Will do nothing
|
|
77
|
+
* if not authenticated.
|
|
78
|
+
*
|
|
79
|
+
* @returns The log out result.
|
|
80
|
+
*/
|
|
33
81
|
logout(): Promise<AuthenticationResult | null>;
|
|
34
82
|
}
|
package/lib/core.js
CHANGED
|
@@ -36,18 +36,21 @@ class AuthenticationClient {
|
|
|
36
36
|
return this.app.get('storage');
|
|
37
37
|
}
|
|
38
38
|
handleSocket(socket) {
|
|
39
|
-
//
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
// has been called explicitly first
|
|
46
|
-
// Force reauthentication with the server
|
|
47
|
-
.then(() => (this.authenticated ? this.reAuthenticate(true) : null));
|
|
48
|
-
this.app.set('authentication', authPromise);
|
|
39
|
+
// When the socket disconnects and we are still authenticated, try to reauthenticate right away
|
|
40
|
+
// the websocket connection will handle timeouts and retries
|
|
41
|
+
socket.on('disconnect', () => {
|
|
42
|
+
if (this.authenticated) {
|
|
43
|
+
this.reAuthenticate(true);
|
|
44
|
+
}
|
|
49
45
|
});
|
|
50
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Parse the access token or authentication error from the window location hash. Will remove it from the hash
|
|
49
|
+
* if found.
|
|
50
|
+
*
|
|
51
|
+
* @param location The window location
|
|
52
|
+
* @returns The access token if available, will throw an error if found, otherwise null
|
|
53
|
+
*/
|
|
51
54
|
getFromLocation(location) {
|
|
52
55
|
const [accessToken, tokenRegex] = getMatch(location, this.options.locationKey);
|
|
53
56
|
if (accessToken !== null) {
|
|
@@ -61,9 +64,20 @@ class AuthenticationClient {
|
|
|
61
64
|
}
|
|
62
65
|
return Promise.resolve(null);
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Set the access token in storage.
|
|
69
|
+
*
|
|
70
|
+
* @param accessToken The access token to set
|
|
71
|
+
* @returns
|
|
72
|
+
*/
|
|
64
73
|
setAccessToken(accessToken) {
|
|
65
74
|
return this.storage.setItem(this.options.storageKey, accessToken);
|
|
66
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Returns the access token from storage or the window location hash.
|
|
78
|
+
*
|
|
79
|
+
* @returns The access token from storage or location hash
|
|
80
|
+
*/
|
|
67
81
|
getAccessToken() {
|
|
68
82
|
return this.storage.getItem(this.options.storageKey).then((accessToken) => {
|
|
69
83
|
if (!accessToken && typeof window !== 'undefined' && window.location) {
|
|
@@ -72,21 +86,40 @@ class AuthenticationClient {
|
|
|
72
86
|
return accessToken || null;
|
|
73
87
|
});
|
|
74
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Remove the access token from storage
|
|
91
|
+
* @returns The removed access token
|
|
92
|
+
*/
|
|
75
93
|
removeAccessToken() {
|
|
76
94
|
return this.storage.removeItem(this.options.storageKey);
|
|
77
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Reset the internal authentication state. Usually not necessary to call directly.
|
|
98
|
+
*
|
|
99
|
+
* @returns null
|
|
100
|
+
*/
|
|
78
101
|
reset() {
|
|
79
102
|
this.app.set('authentication', null);
|
|
80
103
|
this.authenticated = false;
|
|
81
104
|
return Promise.resolve(null);
|
|
82
105
|
}
|
|
83
106
|
handleError(error, type) {
|
|
84
|
-
|
|
107
|
+
// For NotAuthenticated, PaymentError, Forbidden, NotFound, MethodNotAllowed, NotAcceptable
|
|
108
|
+
// errors, remove the access token
|
|
109
|
+
if (error.code > 400 && error.code < 408) {
|
|
85
110
|
const promise = this.removeAccessToken().then(() => this.reset());
|
|
86
111
|
return type === 'logout' ? promise : promise.then(() => Promise.reject(error));
|
|
87
112
|
}
|
|
88
|
-
return Promise.reject(error);
|
|
113
|
+
return this.reset().then(() => Promise.reject(error));
|
|
89
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Try to reauthenticate using the token from storage. Will do nothing if already authenticated unless
|
|
117
|
+
* `force` is true.
|
|
118
|
+
*
|
|
119
|
+
* @param force force reauthentication with the server
|
|
120
|
+
* @param strategy The name of the strategy to use. Defaults to `options.jwtStrategy`
|
|
121
|
+
* @returns The reauthentication result
|
|
122
|
+
*/
|
|
90
123
|
reAuthenticate(force = false, strategy) {
|
|
91
124
|
// Either returns the authentication state or
|
|
92
125
|
// tries to re-authenticate with the stored JWT and strategy
|
|
@@ -105,6 +138,13 @@ class AuthenticationClient {
|
|
|
105
138
|
}
|
|
106
139
|
return authPromise;
|
|
107
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* Authenticate using a specific strategy and data.
|
|
143
|
+
*
|
|
144
|
+
* @param authentication The authentication data
|
|
145
|
+
* @param params Additional parameters
|
|
146
|
+
* @returns The authentication result
|
|
147
|
+
*/
|
|
108
148
|
authenticate(authentication, params) {
|
|
109
149
|
if (!authentication) {
|
|
110
150
|
return this.reAuthenticate();
|
|
@@ -122,6 +162,12 @@ class AuthenticationClient {
|
|
|
122
162
|
this.app.set('authentication', promise);
|
|
123
163
|
return promise;
|
|
124
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Log out the current user and remove their token. Will do nothing
|
|
167
|
+
* if not authenticated.
|
|
168
|
+
*
|
|
169
|
+
* @returns The log out result.
|
|
170
|
+
*/
|
|
125
171
|
logout() {
|
|
126
172
|
return Promise.resolve(this.app.get('authentication'))
|
|
127
173
|
.then(() => this.service.remove(null).then((authResult) => this.removeAccessToken()
|
package/lib/core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":";;;AAAA,+CAAoE;AAGpE,uCAAmD;AAEnD,MAAM,UAAW,SAAQ,sBAAa;IACpC,YAAY,OAAe,EAAE,IAAU;QACrC,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,aAAa,EAAE,IAAI,CAAC,CAAA;IACxD,CAAC;CACF;AAED,MAAM,QAAQ,GAAG,CAAC,QAAkB,EAAE,GAAW,EAAoB,EAAE;IACrE,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,UAAU,GAAG,UAAU,CAAC,CAAA;IACjD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAE/D,IAAI,KAAK,KAAK,IAAI,EAAE;QAClB,MAAM,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK,CAAA;QAEvB,OAAO,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;KACtB;IAED,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;AACtB,CAAC,CAAA;AAmBD,MAAa,oBAAoB;IAK/B,YAAY,GAAgB,EAAE,OAAoC;QAChE,MAAM,MAAM,GAAG,GAAG,CAAC,EAAE,CAAA;QACrB,MAAM,OAAO,GAAG,IAAI,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,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;aACnD,IAAI,CAAC,GAAG,EAAE,CACT,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,UAAgC,EAAE,EAAE,CAClE,IAAI,CAAC,iBAAiB,EAAE;aACrB,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;aACxB,IAAI,CAAC,GAAG,EAAE;YACT,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAA;YAEnC,OAAO,UAAU,CAAA;QACnB,CAAC,CAAC,CACL,CACF;aACA,KAAK,CAAC,CAAC,KAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAA;IACvE,CAAC;CACF;AA1MD,oDA0MC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare module '@feathersjs/feathers/lib/declarations' {
|
|
|
14
14
|
}
|
|
15
15
|
export declare const getDefaultStorage: () => MemoryStorage | StorageWrapper;
|
|
16
16
|
export { AuthenticationClient, AuthenticationClientOptions, Storage, MemoryStorage, hooks };
|
|
17
|
-
export
|
|
17
|
+
export type ClientConstructor = new (app: Application, options: AuthenticationClientOptions) => AuthenticationClient;
|
|
18
18
|
export declare const defaultStorage: Storage;
|
|
19
19
|
export declare const defaults: AuthenticationClientOptions;
|
|
20
20
|
declare const init: (_options?: Partial<AuthenticationClientOptions>) => (app: Application) => void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@feathersjs/authentication-client",
|
|
3
3
|
"description": "The authentication plugin for feathers-client",
|
|
4
|
-
"version": "5.0.0-pre.
|
|
4
|
+
"version": "5.0.0-pre.34",
|
|
5
5
|
"homepage": "https://feathersjs.com",
|
|
6
6
|
"main": "lib/",
|
|
7
7
|
"types": "lib/",
|
|
@@ -53,25 +53,25 @@
|
|
|
53
53
|
"access": "public"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@feathersjs/authentication": "^5.0.0-pre.
|
|
57
|
-
"@feathersjs/commons": "^5.0.0-pre.
|
|
58
|
-
"@feathersjs/errors": "^5.0.0-pre.
|
|
59
|
-
"@feathersjs/feathers": "^5.0.0-pre.
|
|
56
|
+
"@feathersjs/authentication": "^5.0.0-pre.34",
|
|
57
|
+
"@feathersjs/commons": "^5.0.0-pre.34",
|
|
58
|
+
"@feathersjs/errors": "^5.0.0-pre.34",
|
|
59
|
+
"@feathersjs/feathers": "^5.0.0-pre.34"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@feathersjs/authentication-local": "^5.0.0-pre.
|
|
63
|
-
"@feathersjs/express": "^5.0.0-pre.
|
|
64
|
-
"@feathersjs/memory": "^5.0.0-pre.
|
|
65
|
-
"@feathersjs/rest-client": "^5.0.0-pre.
|
|
66
|
-
"@feathersjs/socketio": "^5.0.0-pre.
|
|
67
|
-
"@feathersjs/socketio-client": "^5.0.0-pre.
|
|
68
|
-
"@types/mocha": "^10.0.
|
|
69
|
-
"@types/node": "^18.11.
|
|
70
|
-
"axios": "^1.
|
|
62
|
+
"@feathersjs/authentication-local": "^5.0.0-pre.34",
|
|
63
|
+
"@feathersjs/express": "^5.0.0-pre.34",
|
|
64
|
+
"@feathersjs/memory": "^5.0.0-pre.34",
|
|
65
|
+
"@feathersjs/rest-client": "^5.0.0-pre.34",
|
|
66
|
+
"@feathersjs/socketio": "^5.0.0-pre.34",
|
|
67
|
+
"@feathersjs/socketio-client": "^5.0.0-pre.34",
|
|
68
|
+
"@types/mocha": "^10.0.1",
|
|
69
|
+
"@types/node": "^18.11.10",
|
|
70
|
+
"axios": "^1.2.0",
|
|
71
71
|
"mocha": "^10.1.0",
|
|
72
72
|
"shx": "^0.3.4",
|
|
73
73
|
"ts-node": "^10.9.1",
|
|
74
|
-
"typescript": "^4.
|
|
74
|
+
"typescript": "^4.9.3"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "42cca600d00f0b3b9d89fa79be30fcd46bc50132"
|
|
77
77
|
}
|
package/src/core.ts
CHANGED
|
@@ -67,21 +67,22 @@ export class AuthenticationClient {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
handleSocket(socket: any) {
|
|
70
|
-
//
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Only reconnect when `reAuthenticate()` or `authenticate()`
|
|
77
|
-
// has been called explicitly first
|
|
78
|
-
// Force reauthentication with the server
|
|
79
|
-
.then(() => (this.authenticated ? this.reAuthenticate(true) : null))
|
|
80
|
-
|
|
81
|
-
this.app.set('authentication', authPromise)
|
|
70
|
+
// When the socket disconnects and we are still authenticated, try to reauthenticate right away
|
|
71
|
+
// the websocket connection will handle timeouts and retries
|
|
72
|
+
socket.on('disconnect', () => {
|
|
73
|
+
if (this.authenticated) {
|
|
74
|
+
this.reAuthenticate(true)
|
|
75
|
+
}
|
|
82
76
|
})
|
|
83
77
|
}
|
|
84
78
|
|
|
79
|
+
/**
|
|
80
|
+
* Parse the access token or authentication error from the window location hash. Will remove it from the hash
|
|
81
|
+
* if found.
|
|
82
|
+
*
|
|
83
|
+
* @param location The window location
|
|
84
|
+
* @returns The access token if available, will throw an error if found, otherwise null
|
|
85
|
+
*/
|
|
85
86
|
getFromLocation(location: Location) {
|
|
86
87
|
const [accessToken, tokenRegex] = getMatch(location, this.options.locationKey)
|
|
87
88
|
|
|
@@ -102,10 +103,21 @@ export class AuthenticationClient {
|
|
|
102
103
|
return Promise.resolve(null)
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Set the access token in storage.
|
|
108
|
+
*
|
|
109
|
+
* @param accessToken The access token to set
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
105
112
|
setAccessToken(accessToken: string) {
|
|
106
113
|
return this.storage.setItem(this.options.storageKey, accessToken)
|
|
107
114
|
}
|
|
108
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Returns the access token from storage or the window location hash.
|
|
118
|
+
*
|
|
119
|
+
* @returns The access token from storage or location hash
|
|
120
|
+
*/
|
|
109
121
|
getAccessToken(): Promise<string | null> {
|
|
110
122
|
return this.storage.getItem(this.options.storageKey).then((accessToken: string) => {
|
|
111
123
|
if (!accessToken && typeof window !== 'undefined' && window.location) {
|
|
@@ -116,10 +128,19 @@ export class AuthenticationClient {
|
|
|
116
128
|
})
|
|
117
129
|
}
|
|
118
130
|
|
|
131
|
+
/**
|
|
132
|
+
* Remove the access token from storage
|
|
133
|
+
* @returns The removed access token
|
|
134
|
+
*/
|
|
119
135
|
removeAccessToken() {
|
|
120
136
|
return this.storage.removeItem(this.options.storageKey)
|
|
121
137
|
}
|
|
122
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Reset the internal authentication state. Usually not necessary to call directly.
|
|
141
|
+
*
|
|
142
|
+
* @returns null
|
|
143
|
+
*/
|
|
123
144
|
reset() {
|
|
124
145
|
this.app.set('authentication', null)
|
|
125
146
|
this.authenticated = false
|
|
@@ -128,15 +149,25 @@ export class AuthenticationClient {
|
|
|
128
149
|
}
|
|
129
150
|
|
|
130
151
|
handleError(error: FeathersError, type: 'authenticate' | 'logout') {
|
|
131
|
-
|
|
152
|
+
// For NotAuthenticated, PaymentError, Forbidden, NotFound, MethodNotAllowed, NotAcceptable
|
|
153
|
+
// errors, remove the access token
|
|
154
|
+
if (error.code > 400 && error.code < 408) {
|
|
132
155
|
const promise = this.removeAccessToken().then(() => this.reset())
|
|
133
156
|
|
|
134
157
|
return type === 'logout' ? promise : promise.then(() => Promise.reject(error))
|
|
135
158
|
}
|
|
136
159
|
|
|
137
|
-
return Promise.reject(error)
|
|
160
|
+
return this.reset().then(() => Promise.reject(error))
|
|
138
161
|
}
|
|
139
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Try to reauthenticate using the token from storage. Will do nothing if already authenticated unless
|
|
165
|
+
* `force` is true.
|
|
166
|
+
*
|
|
167
|
+
* @param force force reauthentication with the server
|
|
168
|
+
* @param strategy The name of the strategy to use. Defaults to `options.jwtStrategy`
|
|
169
|
+
* @returns The reauthentication result
|
|
170
|
+
*/
|
|
140
171
|
reAuthenticate(force = false, strategy?: string): Promise<AuthenticationResult> {
|
|
141
172
|
// Either returns the authentication state or
|
|
142
173
|
// tries to re-authenticate with the stored JWT and strategy
|
|
@@ -159,6 +190,13 @@ export class AuthenticationClient {
|
|
|
159
190
|
return authPromise
|
|
160
191
|
}
|
|
161
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Authenticate using a specific strategy and data.
|
|
195
|
+
*
|
|
196
|
+
* @param authentication The authentication data
|
|
197
|
+
* @param params Additional parameters
|
|
198
|
+
* @returns The authentication result
|
|
199
|
+
*/
|
|
162
200
|
authenticate(authentication?: AuthenticationRequest, params?: Params): Promise<AuthenticationResult> {
|
|
163
201
|
if (!authentication) {
|
|
164
202
|
return this.reAuthenticate()
|
|
@@ -182,6 +220,12 @@ export class AuthenticationClient {
|
|
|
182
220
|
return promise
|
|
183
221
|
}
|
|
184
222
|
|
|
223
|
+
/**
|
|
224
|
+
* Log out the current user and remove their token. Will do nothing
|
|
225
|
+
* if not authenticated.
|
|
226
|
+
*
|
|
227
|
+
* @returns The log out result.
|
|
228
|
+
*/
|
|
185
229
|
logout(): Promise<AuthenticationResult | null> {
|
|
186
230
|
return Promise.resolve(this.app.get('authentication'))
|
|
187
231
|
.then(() =>
|