zavadil-ts-common 1.2.78 → 2.0.0
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 +27 -23
- 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/OAuthRestClient.d.ts +9 -6
- package/dist/oauth/OAuthTokenManager.d.ts +11 -11
- package/dist/oauth/RestClientWithOAuth.d.ts +4 -4
- package/dist/oauth/tokenprovider/OAuthRefreshTokenProvider.d.ts +5 -0
- package/dist/oauth/tokenprovider/RefreshTokenProviderDefault.d.ts +14 -0
- package/dist/oauth/tokenprovider/RefreshTokenProviderLogin.d.ts +12 -0
- package/dist/oauth/tokenprovider/RefreshTokenProviderStorage.d.ts +10 -0
- package/dist/oauth/tokenprovider/RefreshTokenProviderUrl.d.ts +12 -0
- package/dist/util/NumberUtil.d.ts +2 -2
- package/dist/util/ObjectUtil.d.ts +1 -1
- package/package.json +1 -1
- package/src/oauth/OAuthRestClient.ts +20 -9
- package/src/oauth/OAuthTokenManager.ts +29 -29
- package/src/oauth/RestClientWithOAuth.ts +11 -11
- package/src/oauth/tokenprovider/OAuthRefreshTokenProvider.ts +6 -0
- package/src/oauth/tokenprovider/RefreshTokenProviderDefault.ts +52 -0
- package/src/oauth/tokenprovider/{IdTokenProviderLogin.ts → RefreshTokenProviderLogin.ts} +3 -3
- package/src/oauth/tokenprovider/{IdTokenProviderStorage.ts → RefreshTokenProviderStorage.ts} +9 -9
- package/src/oauth/tokenprovider/{IdTokenProviderUrl.ts → RefreshTokenProviderUrl.ts} +7 -7
- package/src/util/NumberUtil.ts +5 -1
- package/src/util/OAuthUtil.ts +2 -1
- package/src/util/ObjectUtil.ts +1 -1
- package/src/oauth/tokenprovider/IdTokenProviderDefault.ts +0 -52
- package/src/oauth/tokenprovider/OAuthIdTokenProvider.ts +0 -6
package/src/util/OAuthUtil.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {TokenResponsePayloadBase} from "../oauth";
|
|
2
2
|
import {StringUtil} from "./StringUtil";
|
|
3
|
+
import {ObjectUtil} from "./ObjectUtil";
|
|
3
4
|
|
|
4
5
|
export class OAuthUtil {
|
|
5
6
|
|
|
6
7
|
static isValidToken(token?: TokenResponsePayloadBase | null): boolean {
|
|
7
|
-
return token
|
|
8
|
+
return ObjectUtil.notEmpty(token) && StringUtil.notBlank(token.token) && !OAuthUtil.isTokenExpired(token);
|
|
8
9
|
}
|
|
9
10
|
|
|
10
11
|
static isTokenExpired(token?: TokenResponsePayloadBase | null): boolean {
|
package/src/util/ObjectUtil.ts
CHANGED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import {OAuthIdTokenProvider} from "./OAuthIdTokenProvider";
|
|
2
|
-
import {IdTokenPayload} from "../OAuthRestClient";
|
|
3
|
-
import {IdTokenProviderLogin} from "./IdTokenProviderLogin";
|
|
4
|
-
import {RestClientWithOAuth} from "../RestClientWithOAuth";
|
|
5
|
-
import {IdTokenProviderUrl} from "./IdTokenProviderUrl";
|
|
6
|
-
import {IdTokenProviderStorage} from "./IdTokenProviderStorage";
|
|
7
|
-
|
|
8
|
-
export class IdTokenProviderDefault implements OAuthIdTokenProvider {
|
|
9
|
-
|
|
10
|
-
login: IdTokenProviderLogin;
|
|
11
|
-
|
|
12
|
-
url: IdTokenProviderUrl;
|
|
13
|
-
|
|
14
|
-
storage: IdTokenProviderStorage;
|
|
15
|
-
|
|
16
|
-
constructor(client: RestClientWithOAuth, tokenStorageKey?: string, tokenUrlName?: string) {
|
|
17
|
-
this.login = new IdTokenProviderLogin(client, tokenUrlName);
|
|
18
|
-
this.url = new IdTokenProviderUrl(client, tokenUrlName);
|
|
19
|
-
this.storage = new IdTokenProviderStorage(tokenStorageKey);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
getIdToken(): Promise<IdTokenPayload> {
|
|
23
|
-
return this.url
|
|
24
|
-
.getIdToken()
|
|
25
|
-
.catch(
|
|
26
|
-
(err) => {
|
|
27
|
-
console.log("No token in url, loading from storage:", err);
|
|
28
|
-
return this.storage
|
|
29
|
-
.getIdToken()
|
|
30
|
-
.catch(
|
|
31
|
-
(err) => {
|
|
32
|
-
console.log("No token in storage, redirecting to login page:", err);
|
|
33
|
-
return this.login.getIdToken();
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
)
|
|
38
|
-
.then(
|
|
39
|
-
(t) => {
|
|
40
|
-
console.log("Token found, saving to storage...");
|
|
41
|
-
this.storage.saveIdTokenToLocalStorage(t);
|
|
42
|
-
// redirect if token is in url
|
|
43
|
-
return this.url.reset().then(() => t);
|
|
44
|
-
}
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
reset(): Promise<any> {
|
|
49
|
-
return this.storage.reset().then(() => this.url.reset());
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
}
|