zavadil-ts-common 1.2.40 → 1.2.41
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/index.d.ts +9 -2
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/oauth/OAuthTokenManager.d.ts +6 -0
- package/dist/oauth/RestClientWithOAuth.d.ts +3 -2
- package/package.json +1 -1
- package/src/oauth/OAuthTokenManager.ts +6 -0
- package/src/oauth/RestClientWithOAuth.ts +8 -4
@@ -8,15 +8,16 @@ export type ServerOAuthInfoPayload = {
|
|
8
8
|
oauthServerUrl: string;
|
9
9
|
version: string;
|
10
10
|
};
|
11
|
-
export declare class RestClientWithOAuth extends RestClient {
|
11
|
+
export declare class RestClientWithOAuth extends RestClient implements OAuthIdTokenProvider {
|
12
12
|
private insecureClient;
|
13
13
|
private freshIdTokenProvider;
|
14
14
|
private tokenManager;
|
15
15
|
private serverInfo;
|
16
16
|
private defaultPrivilege;
|
17
17
|
constructor(url: string, freshIdTokenProvider?: OAuthIdTokenProvider, defaultPrivilege?: string);
|
18
|
+
getIdToken(): Promise<IdTokenPayload>;
|
18
19
|
/**
|
19
|
-
* Attempt to get ID token from
|
20
|
+
* Attempt to get ID token from token manager
|
20
21
|
*/
|
21
22
|
initialize(): Promise<any>;
|
22
23
|
logout(): Promise<any>;
|
package/package.json
CHANGED
@@ -69,6 +69,9 @@ export class OAuthTokenManager implements OAuthIdTokenProvider {
|
|
69
69
|
this.accessTokens.clear();
|
70
70
|
}
|
71
71
|
|
72
|
+
/**
|
73
|
+
* Get stored id token or ask the provider, this will trigger redirect to login screen in case of the default provider
|
74
|
+
*/
|
72
75
|
getIdTokenInternal(): Promise<IdTokenPayload> {
|
73
76
|
if (this.idToken === undefined || !this.hasValidIdToken()) {
|
74
77
|
return this.freshIdTokenProvider.getIdToken();
|
@@ -76,6 +79,9 @@ export class OAuthTokenManager implements OAuthIdTokenProvider {
|
|
76
79
|
return Promise.resolve(this.idToken);
|
77
80
|
}
|
78
81
|
|
82
|
+
/**
|
83
|
+
* Get id token, refresh it if needed
|
84
|
+
*/
|
79
85
|
getIdToken(): Promise<IdTokenPayload> {
|
80
86
|
return this.getIdTokenInternal()
|
81
87
|
.then(
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import {OAuthTokenManager} from "./OAuthTokenManager";
|
2
2
|
import {RestClient} from "../client";
|
3
|
-
import {IdTokenPayload} from "./OAuthRestClient";
|
3
|
+
import {IdTokenPayload, TokenResponsePayloadBase} from "./OAuthRestClient";
|
4
4
|
import {LazyAsync} from "../cache";
|
5
5
|
import {OAuthIdTokenProvider} from "./tokenprovider/OAuthIdTokenProvider";
|
6
6
|
import {IdTokenProviderDefault} from "./tokenprovider/IdTokenProviderDefault";
|
@@ -12,7 +12,7 @@ export type ServerOAuthInfoPayload = {
|
|
12
12
|
version: string;
|
13
13
|
}
|
14
14
|
|
15
|
-
export class RestClientWithOAuth extends RestClient {
|
15
|
+
export class RestClientWithOAuth extends RestClient implements OAuthIdTokenProvider {
|
16
16
|
|
17
17
|
private insecureClient: RestClient;
|
18
18
|
|
@@ -37,11 +37,15 @@ export class RestClientWithOAuth extends RestClient {
|
|
37
37
|
this.tokenManager = new LazyAsync<OAuthTokenManager>(() => this.getTokenManagerInternal());
|
38
38
|
}
|
39
39
|
|
40
|
+
getIdToken(): Promise<IdTokenPayload> {
|
41
|
+
return this.getTokenManager().then(t => t.getIdToken());
|
42
|
+
}
|
43
|
+
|
40
44
|
/**
|
41
|
-
* Attempt to get ID token from
|
45
|
+
* Attempt to get ID token from token manager
|
42
46
|
*/
|
43
47
|
initialize(): Promise<any> {
|
44
|
-
return this.
|
48
|
+
return this.getIdToken();
|
45
49
|
}
|
46
50
|
|
47
51
|
logout(): Promise<any> {
|