attlaz-client 1.8.12 → 1.8.13
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.
|
@@ -9,6 +9,7 @@ export declare class OAuthClient {
|
|
|
9
9
|
constructor(options: OAuthClientOptions);
|
|
10
10
|
authenticate(username: string, password: string): Promise<boolean>;
|
|
11
11
|
authenticate(): Promise<boolean>;
|
|
12
|
+
private refreshTokenPromise;
|
|
12
13
|
refreshToken(): Promise<void>;
|
|
13
14
|
isTokenExpires(): boolean;
|
|
14
15
|
request(action: string, parameters?: any, method?: string, signWithOauthToken?: boolean): Promise<any>;
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -15,6 +15,7 @@ class OAuthClient {
|
|
|
15
15
|
this.debug = false;
|
|
16
16
|
this.oauthToken = null;
|
|
17
17
|
this.oathClientToken = null;
|
|
18
|
+
this.refreshTokenPromise = null;
|
|
18
19
|
this.options = options;
|
|
19
20
|
//
|
|
20
21
|
this.oauthClient = new client_oauth2_1.default({
|
|
@@ -29,6 +30,7 @@ class OAuthClient {
|
|
|
29
30
|
}
|
|
30
31
|
async authenticate(username = null, password = null) {
|
|
31
32
|
//TODO: should we encrypt the password in the client (or is https save enough)?
|
|
33
|
+
console.log('Authenticate');
|
|
32
34
|
try {
|
|
33
35
|
let accessToken;
|
|
34
36
|
if (username !== null && username !== undefined && password !== null && password !== undefined) {
|
|
@@ -44,11 +46,14 @@ class OAuthClient {
|
|
|
44
46
|
return true;
|
|
45
47
|
}
|
|
46
48
|
catch (e) {
|
|
47
|
-
|
|
49
|
+
if (this.debug) {
|
|
50
|
+
console.debug('[Client] Error during authentication', e);
|
|
51
|
+
}
|
|
48
52
|
throw ClientError_1.ClientError.fromError(e);
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
async refreshToken() {
|
|
56
|
+
console.log('Get refresh token');
|
|
52
57
|
if (this.oauthToken === null) {
|
|
53
58
|
throw new Error('unable to refresh token, auth token not set');
|
|
54
59
|
}
|
|
@@ -58,8 +63,8 @@ class OAuthClient {
|
|
|
58
63
|
this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
|
|
59
64
|
}
|
|
60
65
|
catch (e) {
|
|
61
|
-
|
|
62
|
-
throw
|
|
66
|
+
console.log('Error during refresh token', e);
|
|
67
|
+
throw ClientError_1.ClientError.fromError(e);
|
|
63
68
|
}
|
|
64
69
|
}
|
|
65
70
|
else {
|
|
@@ -82,7 +87,19 @@ class OAuthClient {
|
|
|
82
87
|
throw new ClientError_1.ClientError('Unable to perform request, access token not provided');
|
|
83
88
|
}
|
|
84
89
|
if (signWithOauthToken && this.oauthToken.expired()) {
|
|
85
|
-
|
|
90
|
+
if (this.refreshTokenPromise === null) {
|
|
91
|
+
this.refreshTokenPromise = this.refreshToken();
|
|
92
|
+
await this.refreshTokenPromise;
|
|
93
|
+
// this.refreshTokenPromise.then(() => {
|
|
94
|
+
this.refreshTokenPromise = null;
|
|
95
|
+
console.log('Refresh token done');
|
|
96
|
+
// });
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
console.log('Waiting for refresh token promise');
|
|
100
|
+
await this.refreshTokenPromise;
|
|
101
|
+
console.log('Refresh token promise resolved');
|
|
102
|
+
}
|
|
86
103
|
}
|
|
87
104
|
}
|
|
88
105
|
const requestData = this.createRequestData(action, parameters, method, signWithOauthToken);
|
|
@@ -9,7 +9,15 @@ class ClientError {
|
|
|
9
9
|
this.code = code;
|
|
10
10
|
}
|
|
11
11
|
static fromError(error) {
|
|
12
|
-
|
|
12
|
+
console.log('Incoming error', error);
|
|
13
|
+
if (error.body !== undefined && error.body !== null && error.body.error !== undefined && error.body.error !== null) {
|
|
14
|
+
error = error.body.error;
|
|
15
|
+
}
|
|
16
|
+
let message = error;
|
|
17
|
+
if (error.message !== undefined && error.message !== null) {
|
|
18
|
+
message = error.message;
|
|
19
|
+
}
|
|
20
|
+
let clientError = new ClientError(message);
|
|
13
21
|
//console.error(error);
|
|
14
22
|
if (error.status !== null && error.status !== undefined) {
|
|
15
23
|
const statusCode = error.status;
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "1.8.
|
|
1
|
+
export declare const VERSION = "1.8.13";
|
package/dist/version.js
CHANGED