attlaz-client 1.17.3 → 1.17.4
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.
|
@@ -2,7 +2,6 @@ import { OAuthClientOptions } from './OAuthClientOptions.js';
|
|
|
2
2
|
import { OAuthClientToken } from './OAuthClientToken.js';
|
|
3
3
|
import { Parameters } from './Data/Parameters.js';
|
|
4
4
|
import { Headers } from './Data/Headers.js';
|
|
5
|
-
import { QueryString } from './Data/QueryString.js';
|
|
6
5
|
export declare class OAuthClient {
|
|
7
6
|
private readonly options;
|
|
8
7
|
private debug;
|
|
@@ -23,7 +22,6 @@ export declare class OAuthClient {
|
|
|
23
22
|
enableDebug(): void;
|
|
24
23
|
disableDebug(): void;
|
|
25
24
|
isDebugEnabled(): boolean;
|
|
26
|
-
getAuthorizationUrl(options?: QueryString | null): string;
|
|
27
25
|
getDefaultHeaders(): Headers;
|
|
28
26
|
private isNodeEnvironment;
|
|
29
27
|
private tokenToOauthClientToken;
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// import ClientOAuth2, {Token} from 'client-oauth2';
|
|
2
1
|
import { clientCredentials, ownerCredentials, refreshToken } from 'axios-oauth-client';
|
|
3
2
|
import axios from 'axios';
|
|
4
3
|
import { ClientError } from './ClientError.js';
|
|
@@ -7,27 +6,14 @@ import { HttpClientRequest } from './HttpClientRequest.js';
|
|
|
7
6
|
import { OAuthClientToken } from './OAuthClientToken.js';
|
|
8
7
|
import { JsonSerializable } from '../Model/JsonSerializable.js';
|
|
9
8
|
import { VERSION } from '../version.js';
|
|
10
|
-
import { QueryString } from './Data/QueryString.js';
|
|
11
9
|
export class OAuthClient {
|
|
12
10
|
options;
|
|
13
11
|
debug = false;
|
|
14
12
|
axiosInstance = null;
|
|
15
|
-
// private oauthClient: ClientOAuth2;
|
|
16
|
-
// private oauthToken: Token | null = null;
|
|
17
13
|
oathClientToken = null;
|
|
18
14
|
refreshTokenPromise = null;
|
|
19
15
|
constructor(options) {
|
|
20
16
|
this.options = options;
|
|
21
|
-
// this.oauthClient = new ClientOAuth2({
|
|
22
|
-
// clientId: options.clientId === null ? undefined : options.clientId,
|
|
23
|
-
// clientSecret: options.clientSecret === null ? undefined : options.clientSecret,
|
|
24
|
-
// accessTokenUri: this.getUri(options.accessTokenUri),
|
|
25
|
-
// authorizationUri: this.getUri(options.authorizationUri),
|
|
26
|
-
// redirectUri: options.redirectUri,
|
|
27
|
-
// scopes: options.scopes,
|
|
28
|
-
// state: options.state,
|
|
29
|
-
// headers: this.getDefaultHeaders(),
|
|
30
|
-
// });
|
|
31
17
|
}
|
|
32
18
|
async authenticate(username = null, password = null) {
|
|
33
19
|
// TODO: should we encrypt the password in the client (or is https save enough)?
|
|
@@ -35,20 +21,15 @@ export class OAuthClient {
|
|
|
35
21
|
if (username !== null && username !== undefined && password !== null && password !== undefined) {
|
|
36
22
|
// Password flow / Owner Credentials grant
|
|
37
23
|
const getOwnerCredentials = ownerCredentials(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
|
|
38
|
-
const rawAuthToken = await getOwnerCredentials(username, password, '
|
|
24
|
+
const rawAuthToken = await getOwnerCredentials(username, password, this.options.scopes.join(' '));
|
|
39
25
|
this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
|
|
40
|
-
// accessToken = await this.oauthClient.owner.getToken(username, password);
|
|
41
26
|
return true;
|
|
42
27
|
}
|
|
43
28
|
// Client credentials flow
|
|
44
29
|
const getClientCredentials = clientCredentials(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
|
|
45
|
-
const rawAuthToken = await getClientCredentials('
|
|
30
|
+
const rawAuthToken = await getClientCredentials(this.options.scopes.join(' '));
|
|
46
31
|
this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
|
|
47
|
-
// accessToken = await this.oauthClient.credentials.getToken();
|
|
48
32
|
return true;
|
|
49
|
-
// this.oauthToken = accessToken;
|
|
50
|
-
// this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
|
|
51
|
-
// return true;
|
|
52
33
|
}
|
|
53
34
|
catch (e) {
|
|
54
35
|
if (this.debug) {
|
|
@@ -69,8 +50,7 @@ export class OAuthClient {
|
|
|
69
50
|
}
|
|
70
51
|
try {
|
|
71
52
|
const getRefreshToken = refreshToken(this.getAxiosInstance(), this.getApiEndpointUrl(this.options.accessTokenUri), this.options.clientId === null ? undefined : this.options.clientId, this.options.clientSecret === null ? undefined : this.options.clientSecret);
|
|
72
|
-
const auth = await getRefreshToken(this.oathClientToken.refresh_token, '
|
|
73
|
-
// this.oauthToken = await this.oauthToken.refresh();
|
|
53
|
+
const auth = await getRefreshToken(this.oathClientToken.refresh_token, this.options.scopes.join(' '));
|
|
74
54
|
this.oathClientToken = this.tokenToOauthClientToken(auth);
|
|
75
55
|
}
|
|
76
56
|
catch (e) {
|
|
@@ -144,22 +124,9 @@ export class OAuthClient {
|
|
|
144
124
|
return this.oathClientToken;
|
|
145
125
|
}
|
|
146
126
|
setToken(token) {
|
|
147
|
-
// const data: {} = {
|
|
148
|
-
// access_token: token.access_token,
|
|
149
|
-
// token_type: token.token_type,
|
|
150
|
-
// refresh_token: token.refresh_token,
|
|
151
|
-
// scope: token.scope,
|
|
152
|
-
//
|
|
153
|
-
// };
|
|
154
|
-
// const oauthToken: Token = this.oauthClient.createToken(data);
|
|
155
|
-
// if (token.expires !== null && token.expires !== undefined) {
|
|
156
|
-
// oauthToken.expiresIn(token.expires);
|
|
157
|
-
// }
|
|
158
|
-
// this.oauthToken = oauthToken;
|
|
159
127
|
this.oathClientToken = token;
|
|
160
128
|
}
|
|
161
129
|
unsetToken() {
|
|
162
|
-
// this.oauthToken = null;
|
|
163
130
|
this.oathClientToken = null;
|
|
164
131
|
}
|
|
165
132
|
enableDebug() {
|
|
@@ -171,13 +138,6 @@ export class OAuthClient {
|
|
|
171
138
|
isDebugEnabled() {
|
|
172
139
|
return this.debug;
|
|
173
140
|
}
|
|
174
|
-
getAuthorizationUrl(options = null) {
|
|
175
|
-
if (options === null) {
|
|
176
|
-
options = new QueryString();
|
|
177
|
-
}
|
|
178
|
-
options.setCommand(this.getApiEndpointUrl(this.options.authorizationUri));
|
|
179
|
-
return options.build();
|
|
180
|
-
}
|
|
181
141
|
getDefaultHeaders() {
|
|
182
142
|
const userAgentInfo = {
|
|
183
143
|
version: VERSION,
|