zavadil-ts-common 1.1.67 → 1.1.69
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 +1 -1
- 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/RestClientWithOAuth.d.ts +1 -1
- package/package.json +1 -1
- package/src/oauth/OAuthTokenManager.ts +4 -15
- package/src/oauth/RestClientWithOAuth.ts +17 -12
@@ -48,9 +48,17 @@ export class RestClientWithOAuth extends RestClient {
|
|
48
48
|
*/
|
49
49
|
initialize(): Promise<boolean> {
|
50
50
|
return this.initializeIdToken()
|
51
|
-
.then(
|
52
|
-
|
53
|
-
|
51
|
+
.then(
|
52
|
+
(success: boolean) => {
|
53
|
+
if (success) return this.checkAccessToken();
|
54
|
+
return Promise.reject("ID token initialization failed!");
|
55
|
+
}
|
56
|
+
).then(
|
57
|
+
(success: boolean) => {
|
58
|
+
if (!success) return Promise.reject("Access token initialization failed!");
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
).catch(
|
54
62
|
() => this.getServerInfo().then(
|
55
63
|
(si) => {
|
56
64
|
const documentlocation = `${si.oauthServerUrl}/login?app_name=${si.targetAudience}&redirect_url=${document.location}`;
|
@@ -132,9 +140,7 @@ export class RestClientWithOAuth extends RestClient {
|
|
132
140
|
}
|
133
141
|
|
134
142
|
setIdTokenRaw(token: string): Promise<boolean> {
|
135
|
-
|
136
|
-
return this.getTokenManager()
|
137
|
-
.then(m => m.verifyIdToken(token))
|
143
|
+
return this.getTokenManager().then(m => m.verifyIdToken(token))
|
138
144
|
}
|
139
145
|
|
140
146
|
getHeaders(url: string): Promise<RestClientHeaders> {
|
@@ -151,17 +157,16 @@ export class RestClientWithOAuth extends RestClient {
|
|
151
157
|
}
|
152
158
|
|
153
159
|
/**
|
154
|
-
* Try to obtain access token, then return true
|
160
|
+
* Try to obtain access token, then return true if everything is okay.
|
155
161
|
* This is basically only used when initializing and trying to determine whether we need to redirect user to login page
|
156
162
|
*/
|
157
163
|
checkAccessToken(privilege?: string): Promise<boolean> {
|
158
|
-
console.log('checking access token', privilege);
|
159
164
|
return this.getTokenManager()
|
160
165
|
.then(tm => tm.getAccessToken(StringUtil.getNonEmpty(privilege, this.defaultPrivilege)))
|
161
|
-
.then(
|
162
|
-
|
163
|
-
(
|
164
|
-
console.error('check failed',
|
166
|
+
.then((accessToken) => true)
|
167
|
+
.catch(
|
168
|
+
(e) => {
|
169
|
+
console.error('Access token check failed:', e);
|
165
170
|
return false;
|
166
171
|
}
|
167
172
|
);
|