attlaz-client 1.17.0 → 1.17.2
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.
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { CursorPagination } from '../../Model/Pagination/CursorPagination.js';
|
|
2
2
|
import { State } from '../../Model/State.js';
|
|
3
3
|
export declare class QueryString {
|
|
4
|
-
private
|
|
4
|
+
private command;
|
|
5
5
|
private parameters;
|
|
6
|
-
constructor(command
|
|
6
|
+
constructor(command?: string);
|
|
7
|
+
setCommand(command: string): void;
|
|
7
8
|
set(parameter: string, value: string | number | boolean | string[]): void;
|
|
8
9
|
addPagination(pagination: CursorPagination | null): void;
|
|
9
10
|
addStateFilter(states: State[] | null): void;
|
|
@@ -2,6 +2,7 @@ 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';
|
|
5
6
|
export declare class OAuthClient {
|
|
6
7
|
private readonly options;
|
|
7
8
|
private debug;
|
|
@@ -22,10 +23,11 @@ export declare class OAuthClient {
|
|
|
22
23
|
enableDebug(): void;
|
|
23
24
|
disableDebug(): void;
|
|
24
25
|
isDebugEnabled(): boolean;
|
|
26
|
+
getAuthorizationUrl(options?: QueryString | null): string;
|
|
25
27
|
getDefaultHeaders(): Headers;
|
|
26
28
|
private isNodeEnvironment;
|
|
27
29
|
private tokenToOauthClientToken;
|
|
28
|
-
private
|
|
30
|
+
private getApiEndpointUrl;
|
|
29
31
|
private createRequestData;
|
|
30
32
|
private signRequest;
|
|
31
33
|
}
|
package/dist/Http/OAuthClient.js
CHANGED
|
@@ -7,6 +7,7 @@ import { HttpClientRequest } from './HttpClientRequest.js';
|
|
|
7
7
|
import { OAuthClientToken } from './OAuthClientToken.js';
|
|
8
8
|
import { JsonSerializable } from '../Model/JsonSerializable.js';
|
|
9
9
|
import { VERSION } from '../version.js';
|
|
10
|
+
import { QueryString } from './Data/QueryString.js';
|
|
10
11
|
export class OAuthClient {
|
|
11
12
|
options;
|
|
12
13
|
debug = false;
|
|
@@ -33,14 +34,14 @@ export class OAuthClient {
|
|
|
33
34
|
try {
|
|
34
35
|
if (username !== null && username !== undefined && password !== null && password !== undefined) {
|
|
35
36
|
// Password flow / Owner Credentials grant
|
|
36
|
-
const getOwnerCredentials = ownerCredentials(this.getAxiosInstance(), this.
|
|
37
|
+
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);
|
|
37
38
|
const rawAuthToken = await getOwnerCredentials(username, password, 'OPTIONAL_SCOPES');
|
|
38
39
|
this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
|
|
39
40
|
// accessToken = await this.oauthClient.owner.getToken(username, password);
|
|
40
41
|
return true;
|
|
41
42
|
}
|
|
42
43
|
// Client credentials flow
|
|
43
|
-
const getClientCredentials = clientCredentials(this.getAxiosInstance(), this.
|
|
44
|
+
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);
|
|
44
45
|
const rawAuthToken = await getClientCredentials('OPTIONAL_SCOPES');
|
|
45
46
|
this.oathClientToken = this.tokenToOauthClientToken(rawAuthToken);
|
|
46
47
|
// accessToken = await this.oauthClient.credentials.getToken();
|
|
@@ -67,7 +68,7 @@ export class OAuthClient {
|
|
|
67
68
|
throw new Error('unable to refresh token, refresh token not set');
|
|
68
69
|
}
|
|
69
70
|
try {
|
|
70
|
-
const getRefreshToken = refreshToken(this.getAxiosInstance(), this.
|
|
71
|
+
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);
|
|
71
72
|
const auth = await getRefreshToken(this.oathClientToken.refresh_token, 'OPTIONAL_SCOPES');
|
|
72
73
|
// this.oauthToken = await this.oauthToken.refresh();
|
|
73
74
|
this.oathClientToken = this.tokenToOauthClientToken(auth);
|
|
@@ -170,9 +171,13 @@ export class OAuthClient {
|
|
|
170
171
|
isDebugEnabled() {
|
|
171
172
|
return this.debug;
|
|
172
173
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
+
}
|
|
176
181
|
getDefaultHeaders() {
|
|
177
182
|
const userAgentInfo = {
|
|
178
183
|
version: VERSION,
|
|
@@ -204,14 +209,14 @@ export class OAuthClient {
|
|
|
204
209
|
token.expires = t;
|
|
205
210
|
return token;
|
|
206
211
|
}
|
|
207
|
-
|
|
212
|
+
getApiEndpointUrl(uri) {
|
|
208
213
|
if (uri.indexOf('http://') === 0 || uri.indexOf('https://') === 0) {
|
|
209
214
|
return uri;
|
|
210
215
|
}
|
|
211
216
|
return this.options.apiEndpoint.replace(/\/+$/, '') + '/' + uri.replace(/^\/+/g, '');
|
|
212
217
|
}
|
|
213
218
|
createRequestData(action, parameters = null, method = 'GET', signWithOauthToken = true) {
|
|
214
|
-
const url = this.
|
|
219
|
+
const url = this.getApiEndpointUrl(action);
|
|
215
220
|
let requestData = new HttpClientRequest(url, method);
|
|
216
221
|
requestData.headers = this.getDefaultHeaders();
|
|
217
222
|
if ((method === 'POST' || method === 'DELETE' || method === 'PUT') && parameters !== null && parameters !== undefined) {
|