attlaz-client 1.5.5 → 1.5.6
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/dist/Http/OAuthClient.d.ts +2 -0
- package/dist/Http/OAuthClient.js +19 -17
- package/package.json +1 -1
|
@@ -5,6 +5,7 @@ export declare class OAuthClient {
|
|
|
5
5
|
private debug;
|
|
6
6
|
private oauthClient;
|
|
7
7
|
private oauthToken;
|
|
8
|
+
private oathClientToken;
|
|
8
9
|
constructor(options: OAuthClientOptions);
|
|
9
10
|
authenticate(username: string, password: string): Promise<boolean>;
|
|
10
11
|
authenticate(): Promise<boolean>;
|
|
@@ -23,6 +24,7 @@ export declare class OAuthClient {
|
|
|
23
24
|
[key: string]: string | string[];
|
|
24
25
|
};
|
|
25
26
|
} | null): string;
|
|
27
|
+
private tokenToOauthClientToken;
|
|
26
28
|
private getUri;
|
|
27
29
|
private createRequestData;
|
|
28
30
|
private signRequest;
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -11,6 +11,7 @@ class OAuthClient {
|
|
|
11
11
|
constructor(options) {
|
|
12
12
|
this.debug = false;
|
|
13
13
|
this.oauthToken = null;
|
|
14
|
+
this.oathClientToken = null;
|
|
14
15
|
this.options = options;
|
|
15
16
|
//
|
|
16
17
|
this.oauthClient = new ClientOAuth2({
|
|
@@ -50,6 +51,7 @@ class OAuthClient {
|
|
|
50
51
|
if (this.oauthToken.refreshToken !== undefined && this.oauthToken.refreshToken !== null && this.oauthToken.refreshToken !== '') {
|
|
51
52
|
try {
|
|
52
53
|
this.oauthToken = await this.oauthToken.refresh();
|
|
54
|
+
this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
|
|
53
55
|
}
|
|
54
56
|
catch (e) {
|
|
55
57
|
const error = ClientError_1.ClientError.fromError(e);
|
|
@@ -94,26 +96,16 @@ class OAuthClient {
|
|
|
94
96
|
}
|
|
95
97
|
isAuthenticated() {
|
|
96
98
|
//TODO: other ways to determine if the client is authenticated?
|
|
97
|
-
return this.
|
|
99
|
+
return this.oathClientToken !== null && this.oathClientToken !== undefined;
|
|
98
100
|
}
|
|
99
101
|
getToken() {
|
|
100
102
|
if (this.oauthToken === null) {
|
|
101
103
|
return null;
|
|
102
104
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const rawTokenExpires = this.oauthToken.expires;
|
|
106
|
-
if (rawTokenExpires !== null && rawTokenExpires !== undefined) {
|
|
107
|
-
token.expires = rawTokenExpires;
|
|
105
|
+
if (this.oathClientToken === null) {
|
|
106
|
+
this.oathClientToken = this.tokenToOauthClientToken(this.oauthToken);
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
// access_token: this.oauthToken.accessToken,
|
|
111
|
-
// token_type: this.oauthToken.tokenType,
|
|
112
|
-
// refresh_token: this.oauthToken.refreshToken,
|
|
113
|
-
// expires: (this.oauthToken as any as { expires: Date }).expires,
|
|
114
|
-
// scope: this.oauthToken.data.scope
|
|
115
|
-
// };
|
|
116
|
-
return token;
|
|
108
|
+
return this.oathClientToken;
|
|
117
109
|
}
|
|
118
110
|
setToken(token) {
|
|
119
111
|
const data = {
|
|
@@ -127,9 +119,11 @@ class OAuthClient {
|
|
|
127
119
|
oauthToken.expiresIn(token.expires);
|
|
128
120
|
}
|
|
129
121
|
this.oauthToken = oauthToken;
|
|
122
|
+
this.oathClientToken = token;
|
|
130
123
|
}
|
|
131
124
|
unsetToken() {
|
|
132
125
|
this.oauthToken = null;
|
|
126
|
+
this.oathClientToken = null;
|
|
133
127
|
}
|
|
134
128
|
enableDebug() {
|
|
135
129
|
this.debug = true;
|
|
@@ -143,6 +137,14 @@ class OAuthClient {
|
|
|
143
137
|
getTokenFlowUrl(options = null) {
|
|
144
138
|
return this.oauthClient.token.getUri(options === null ? undefined : options);
|
|
145
139
|
}
|
|
140
|
+
tokenToOauthClientToken(oauthToken) {
|
|
141
|
+
const token = new OAuthClientToken_1.OAuthClientToken(oauthToken.accessToken, oauthToken.tokenType, oauthToken.refreshToken, oauthToken.data.scopes);
|
|
142
|
+
const rawTokenExpires = oauthToken.expires;
|
|
143
|
+
if (rawTokenExpires !== null && rawTokenExpires !== undefined) {
|
|
144
|
+
token.expires = rawTokenExpires;
|
|
145
|
+
}
|
|
146
|
+
return token;
|
|
147
|
+
}
|
|
146
148
|
getUri(uri) {
|
|
147
149
|
if (uri.indexOf("http://") == 0 || uri.indexOf("https://") == 0) {
|
|
148
150
|
return uri;
|
|
@@ -184,11 +186,11 @@ class OAuthClient {
|
|
|
184
186
|
return requestData;
|
|
185
187
|
}
|
|
186
188
|
signRequest(requestObject) {
|
|
187
|
-
if (this.
|
|
189
|
+
if (this.oathClientToken === null) {
|
|
188
190
|
throw new ClientError_1.ClientError('Unable to sign request, access token not provided');
|
|
189
191
|
}
|
|
190
|
-
const tokenType = this.
|
|
191
|
-
const accessToken = this.
|
|
192
|
+
const tokenType = this.oathClientToken.token_type;
|
|
193
|
+
const accessToken = this.oathClientToken.access_token;
|
|
192
194
|
if (tokenType !== undefined && tokenType.toLowerCase() === 'bearer') {
|
|
193
195
|
requestObject.setHeader('Authorization', 'Bearer ' + accessToken);
|
|
194
196
|
}
|