@asgardeo/auth-spa 0.2.13 → 0.2.17
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/README.md +9 -4
- package/dist/asgardeo-spa.production.esm.js +10 -10
- package/dist/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/asgardeo-spa.production.js +7 -7
- package/dist/asgardeo-spa.production.js.map +1 -1
- package/dist/asgardeo-spa.production.min.js +1 -1
- package/dist/asgardeo-spa.production.min.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.esm.js +35 -35
- package/dist/polyfilled/asgardeo-spa.production.esm.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.js +35 -35
- package/dist/polyfilled/asgardeo-spa.production.js.map +1 -1
- package/dist/polyfilled/asgardeo-spa.production.min.js +1 -1
- package/dist/polyfilled/asgardeo-spa.production.min.js.map +1 -1
- package/dist/src/client.js.map +1 -1
- package/dist/src/clients/main-thread-client.d.ts.map +1 -1
- package/dist/src/clients/main-thread-client.js +131 -54
- package/dist/src/clients/main-thread-client.js.map +1 -1
- package/dist/src/clients/web-worker-client.d.ts.map +1 -1
- package/dist/src/clients/web-worker-client.js +42 -19
- package/dist/src/clients/web-worker-client.js.map +1 -1
- package/dist/src/constants/parameters.d.ts +1 -0
- package/dist/src/constants/parameters.d.ts.map +1 -1
- package/dist/src/constants/parameters.js +1 -0
- package/dist/src/constants/parameters.js.map +1 -1
- package/dist/src/models/client.d.ts +2 -2
- package/dist/src/models/client.d.ts.map +1 -1
- package/dist/src/models/http-client.d.ts +1 -1
- package/dist/src/models/http-client.d.ts.map +1 -1
- package/dist/src/models/web-worker.d.ts +1 -2
- package/dist/src/models/web-worker.d.ts.map +1 -1
- package/dist/src/worker/client.worker.d.ts.map +1 -1
- package/dist/src/worker/client.worker.js +1 -7
- package/dist/src/worker/client.worker.js.map +1 -1
- package/dist/src/worker/worker-core.d.ts.map +1 -1
- package/dist/src/worker/worker-core.js +20 -7
- package/dist/src/worker/worker-core.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/client.ts +1 -1
- package/src/clients/main-thread-client.ts +156 -77
- package/src/clients/web-worker-client.ts +50 -24
- package/src/constants/parameters.ts +1 -0
- package/src/models/client.ts +2 -2
- package/src/models/http-client.ts +1 -1
- package/src/models/web-worker.ts +1 -2
- package/src/worker/client.worker.ts +3 -12
- package/src/worker/worker-core.ts +20 -8
|
@@ -33,6 +33,7 @@ import {
|
|
|
33
33
|
import {
|
|
34
34
|
CHECK_SESSION_SIGNED_IN,
|
|
35
35
|
CHECK_SESSION_SIGNED_OUT,
|
|
36
|
+
CUSTOM_GRANT_CONFIG,
|
|
36
37
|
ERROR,
|
|
37
38
|
ERROR_DESCRIPTION,
|
|
38
39
|
PROMPT_NONE_IFRAME,
|
|
@@ -86,13 +87,16 @@ export const MainThreadClient = async (
|
|
|
86
87
|
);
|
|
87
88
|
|
|
88
89
|
const _httpClient: HttpClientInstance = HttpClient.getInstance();
|
|
90
|
+
let _isHttpHandlerEnabled: boolean = true;
|
|
91
|
+
let _httpErrorCallback: (error: HttpError) => void | Promise<void>;
|
|
92
|
+
let _httpFinishCallback: () => void;
|
|
89
93
|
|
|
90
94
|
const attachToken = async (request: HttpRequestConfig): Promise<void> => {
|
|
91
95
|
const requestConfig = { attachToken: true, ...request };
|
|
92
96
|
if (requestConfig.attachToken) {
|
|
93
97
|
request.headers = {
|
|
94
98
|
...request.headers,
|
|
95
|
-
Authorization: `Bearer ${
|
|
99
|
+
Authorization: `Bearer ${await _authenticationClient.getAccessToken()}`
|
|
96
100
|
};
|
|
97
101
|
}
|
|
98
102
|
};
|
|
@@ -109,17 +113,18 @@ export const MainThreadClient = async (
|
|
|
109
113
|
|
|
110
114
|
const setHttpRequestFinishCallback = (callback: () => void): void => {
|
|
111
115
|
_httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
|
|
116
|
+
_httpFinishCallback = callback;
|
|
112
117
|
};
|
|
113
118
|
|
|
114
|
-
const setHttpRequestErrorCallback = (callback: (error: HttpError) => void): void => {
|
|
115
|
-
|
|
119
|
+
const setHttpRequestErrorCallback = (callback: (error: HttpError) => void | Promise<void>): void => {
|
|
120
|
+
_httpErrorCallback = callback;
|
|
116
121
|
};
|
|
117
122
|
|
|
118
123
|
const httpRequest = async (requestConfig: HttpRequestConfig): Promise<HttpResponse> => {
|
|
119
124
|
let matches = false;
|
|
120
125
|
const config = await _dataLayer.getConfigData();
|
|
121
126
|
|
|
122
|
-
for (const baseUrl of [
|
|
127
|
+
for (const baseUrl of [...((await config?.resourceServerURLs) ?? []), config?.serverOrigin]) {
|
|
123
128
|
if (requestConfig?.url?.startsWith(baseUrl)) {
|
|
124
129
|
matches = true;
|
|
125
130
|
|
|
@@ -133,32 +138,61 @@ export const MainThreadClient = async (
|
|
|
133
138
|
.then((response: HttpResponse) => {
|
|
134
139
|
return Promise.resolve(response);
|
|
135
140
|
})
|
|
136
|
-
.catch((error: HttpError) => {
|
|
137
|
-
if (error?.response?.status === 401) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
)
|
|
161
|
-
|
|
141
|
+
.catch(async (error: HttpError) => {
|
|
142
|
+
if (error?.response?.status === 401 || !error?.response) {
|
|
143
|
+
// Try to refresh the token
|
|
144
|
+
let refreshTokenResponse;
|
|
145
|
+
try {
|
|
146
|
+
refreshTokenResponse = await refreshAccessToken();
|
|
147
|
+
} catch (refreshError: any) {
|
|
148
|
+
if (_isHttpHandlerEnabled) {
|
|
149
|
+
if (typeof _httpErrorCallback === "function") {
|
|
150
|
+
await _httpErrorCallback(error);
|
|
151
|
+
}
|
|
152
|
+
if (typeof _httpFinishCallback === "function") {
|
|
153
|
+
_httpFinishCallback();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return Promise.reject(
|
|
158
|
+
new AsgardeoSPAException(
|
|
159
|
+
"MAIN_THREAD_CLIENT-HR-ES01",
|
|
160
|
+
"main-thread-client",
|
|
161
|
+
"httpRequest",
|
|
162
|
+
"",
|
|
163
|
+
"",
|
|
164
|
+
refreshError
|
|
165
|
+
)
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Retry the request after refreshing the token
|
|
170
|
+
if (refreshTokenResponse) {
|
|
171
|
+
try {
|
|
172
|
+
const httpResponse = await _httpClient.request(requestConfig);
|
|
173
|
+
return Promise.resolve(httpResponse);
|
|
174
|
+
} catch (error: any) {
|
|
175
|
+
if (_isHttpHandlerEnabled) {
|
|
176
|
+
if (typeof _httpErrorCallback === "function") {
|
|
177
|
+
await _httpErrorCallback(error);
|
|
178
|
+
}
|
|
179
|
+
if (typeof _httpFinishCallback === "function") {
|
|
180
|
+
_httpFinishCallback();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return Promise.reject(error);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (_isHttpHandlerEnabled) {
|
|
190
|
+
if (typeof _httpErrorCallback === "function") {
|
|
191
|
+
await _httpErrorCallback(error);
|
|
192
|
+
}
|
|
193
|
+
if (typeof _httpFinishCallback === "function") {
|
|
194
|
+
_httpFinishCallback();
|
|
195
|
+
}
|
|
162
196
|
}
|
|
163
197
|
|
|
164
198
|
return Promise.reject(error);
|
|
@@ -171,8 +205,8 @@ export const MainThreadClient = async (
|
|
|
171
205
|
"httpRequest",
|
|
172
206
|
"Request to the provided endpoint is prohibited.",
|
|
173
207
|
"Requests can only be sent to resource servers specified by the `resourceServerURLs`" +
|
|
174
|
-
|
|
175
|
-
|
|
208
|
+
" attribute while initializing the SDK. The specified endpoint in this request " +
|
|
209
|
+
"cannot be found among the `resourceServerURLs`"
|
|
176
210
|
)
|
|
177
211
|
);
|
|
178
212
|
}
|
|
@@ -185,7 +219,7 @@ export const MainThreadClient = async (
|
|
|
185
219
|
for (const requestConfig of requestConfigs) {
|
|
186
220
|
let urlMatches = false;
|
|
187
221
|
|
|
188
|
-
for (const baseUrl of [
|
|
222
|
+
for (const baseUrl of [...((await config)?.resourceServerURLs ?? []), config?.serverOrigin]) {
|
|
189
223
|
if (requestConfig.url?.startsWith(baseUrl)) {
|
|
190
224
|
urlMatches = true;
|
|
191
225
|
|
|
@@ -214,35 +248,62 @@ export const MainThreadClient = async (
|
|
|
214
248
|
.then((responses: HttpResponse[]) => {
|
|
215
249
|
return Promise.resolve(responses);
|
|
216
250
|
})
|
|
217
|
-
.catch((error: HttpError) => {
|
|
218
|
-
if (error?.response?.status === 401) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
.
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
251
|
+
.catch(async (error: HttpError) => {
|
|
252
|
+
if (error?.response?.status === 401 || !error?.response) {
|
|
253
|
+
let refreshTokenResponse;
|
|
254
|
+
try {
|
|
255
|
+
refreshTokenResponse = await _authenticationClient.refreshAccessToken();
|
|
256
|
+
} catch (refreshError: any) {
|
|
257
|
+
if (_isHttpHandlerEnabled) {
|
|
258
|
+
if (typeof _httpErrorCallback === "function") {
|
|
259
|
+
await _httpErrorCallback(error);
|
|
260
|
+
}
|
|
261
|
+
if (typeof _httpFinishCallback === "function") {
|
|
262
|
+
_httpFinishCallback();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return Promise.reject(
|
|
267
|
+
new AsgardeoSPAException(
|
|
268
|
+
"MAIN_THREAD_CLIENT-HRA-ES01",
|
|
269
|
+
"main-thread-client",
|
|
270
|
+
"httpRequestAll",
|
|
271
|
+
"",
|
|
272
|
+
"",
|
|
273
|
+
refreshError
|
|
274
|
+
)
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (refreshTokenResponse) {
|
|
279
|
+
return _httpClient.all &&
|
|
280
|
+
_httpClient
|
|
281
|
+
.all(requests)
|
|
282
|
+
.then((response) => {
|
|
283
|
+
return Promise.resolve(response);
|
|
284
|
+
})
|
|
285
|
+
.catch(async (error) => {
|
|
286
|
+
if (_isHttpHandlerEnabled) {
|
|
287
|
+
if (typeof _httpErrorCallback === "function") {
|
|
288
|
+
await _httpErrorCallback(error);
|
|
289
|
+
}
|
|
290
|
+
if (typeof _httpFinishCallback === "function") {
|
|
291
|
+
_httpFinishCallback();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return Promise.reject(error);
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (_isHttpHandlerEnabled) {
|
|
301
|
+
if (typeof _httpErrorCallback === "function") {
|
|
302
|
+
await _httpErrorCallback(error);
|
|
303
|
+
}
|
|
304
|
+
if (typeof _httpFinishCallback === "function") {
|
|
305
|
+
_httpFinishCallback();
|
|
306
|
+
}
|
|
246
307
|
}
|
|
247
308
|
|
|
248
309
|
return Promise.reject(error);
|
|
@@ -256,8 +317,8 @@ export const MainThreadClient = async (
|
|
|
256
317
|
"httpRequest",
|
|
257
318
|
"Request to the provided endpoint is prohibited.",
|
|
258
319
|
"Requests can only be sent to resource servers specified by the `resourceServerURLs`" +
|
|
259
|
-
|
|
260
|
-
|
|
320
|
+
" attribute while initializing the SDK. The specified endpoint in this request " +
|
|
321
|
+
"cannot be found among the `resourceServerURLs`"
|
|
261
322
|
)
|
|
262
323
|
);
|
|
263
324
|
}
|
|
@@ -269,12 +330,14 @@ export const MainThreadClient = async (
|
|
|
269
330
|
|
|
270
331
|
const enableHttpHandler = (): boolean => {
|
|
271
332
|
_httpClient?.enableHandler && _httpClient.enableHandler();
|
|
333
|
+
_isHttpHandlerEnabled = true;
|
|
272
334
|
|
|
273
335
|
return true;
|
|
274
336
|
};
|
|
275
337
|
|
|
276
338
|
const disableHttpHandler = (): boolean => {
|
|
277
339
|
_httpClient?.disableHandler && _httpClient.disableHandler();
|
|
340
|
+
_isHttpHandlerEnabled = false;
|
|
278
341
|
|
|
279
342
|
return true;
|
|
280
343
|
};
|
|
@@ -315,6 +378,7 @@ export const MainThreadClient = async (
|
|
|
315
378
|
displayName: "",
|
|
316
379
|
email: "",
|
|
317
380
|
sessionState: "",
|
|
381
|
+
sub: "",
|
|
318
382
|
tenantDomain: "",
|
|
319
383
|
username: ""
|
|
320
384
|
});
|
|
@@ -383,6 +447,7 @@ export const MainThreadClient = async (
|
|
|
383
447
|
displayName: "",
|
|
384
448
|
email: "",
|
|
385
449
|
sessionState: "",
|
|
450
|
+
sub: "",
|
|
386
451
|
tenantDomain: "",
|
|
387
452
|
username: ""
|
|
388
453
|
});
|
|
@@ -421,7 +486,9 @@ export const MainThreadClient = async (
|
|
|
421
486
|
}
|
|
422
487
|
}
|
|
423
488
|
}
|
|
424
|
-
|
|
489
|
+
if(config.shouldReplayAfterRefresh) {
|
|
490
|
+
_dataLayer.setTemporaryDataParameter(CUSTOM_GRANT_CONFIG, JSON.stringify(config));
|
|
491
|
+
}
|
|
425
492
|
if (useDefaultEndpoint || matches) {
|
|
426
493
|
return _authenticationClient
|
|
427
494
|
.requestCustomGrant(config)
|
|
@@ -445,24 +512,26 @@ export const MainThreadClient = async (
|
|
|
445
512
|
"requestCustomGrant",
|
|
446
513
|
"Request to the provided endpoint is prohibited.",
|
|
447
514
|
"Requests can only be sent to resource servers specified by the `resourceServerURLs`" +
|
|
448
|
-
|
|
449
|
-
|
|
515
|
+
" attribute while initializing the SDK. The specified token endpoint in this request " +
|
|
516
|
+
"cannot be found among the `resourceServerURLs`"
|
|
450
517
|
)
|
|
451
518
|
);
|
|
452
519
|
}
|
|
453
520
|
};
|
|
454
521
|
|
|
455
|
-
const refreshAccessToken = (): Promise<BasicUserInfo> => {
|
|
456
|
-
|
|
457
|
-
.refreshAccessToken()
|
|
458
|
-
|
|
459
|
-
|
|
522
|
+
const refreshAccessToken = async (): Promise<BasicUserInfo> => {
|
|
523
|
+
try {
|
|
524
|
+
await _authenticationClient.refreshAccessToken();
|
|
525
|
+
const customGrantConfig = await getCustomGrantConfigData();
|
|
526
|
+
if (customGrantConfig) {
|
|
527
|
+
await requestCustomGrant(customGrantConfig);
|
|
528
|
+
}
|
|
529
|
+
_spaHelper.refreshAccessTokenAutomatically();
|
|
460
530
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
.
|
|
464
|
-
|
|
465
|
-
});
|
|
531
|
+
return _authenticationClient.getBasicUserInfo();
|
|
532
|
+
} catch (error) {
|
|
533
|
+
return Promise.reject(error);
|
|
534
|
+
}
|
|
466
535
|
};
|
|
467
536
|
|
|
468
537
|
const revokeAccessToken = (): Promise<boolean> => {
|
|
@@ -529,6 +598,7 @@ export const MainThreadClient = async (
|
|
|
529
598
|
displayName: "",
|
|
530
599
|
email: "",
|
|
531
600
|
sessionState: "",
|
|
601
|
+
sub: "",
|
|
532
602
|
tenantDomain: "",
|
|
533
603
|
username: ""
|
|
534
604
|
});
|
|
@@ -640,6 +710,15 @@ export const MainThreadClient = async (
|
|
|
640
710
|
}
|
|
641
711
|
};
|
|
642
712
|
|
|
713
|
+
const getCustomGrantConfigData = async (): Promise<AuthClientConfig<CustomGrantConfig> | null> => {
|
|
714
|
+
const configString = await _dataLayer.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
|
|
715
|
+
if(configString) {
|
|
716
|
+
return JSON.parse(configString as string);
|
|
717
|
+
} else {
|
|
718
|
+
return null
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
|
|
643
722
|
return {
|
|
644
723
|
disableHttpHandler,
|
|
645
724
|
enableHttpHandler,
|
|
@@ -51,7 +51,6 @@ import {
|
|
|
51
51
|
REFRESH_ACCESS_TOKEN,
|
|
52
52
|
REQUEST_ACCESS_TOKEN,
|
|
53
53
|
REQUEST_CUSTOM_GRANT,
|
|
54
|
-
REQUEST_ERROR,
|
|
55
54
|
REQUEST_FINISH,
|
|
56
55
|
REQUEST_START,
|
|
57
56
|
REQUEST_SUCCESS,
|
|
@@ -88,6 +87,8 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
88
87
|
* API request time out.
|
|
89
88
|
*/
|
|
90
89
|
const _requestTimeout: number = config?.requestTimeout ?? 60000;
|
|
90
|
+
let _isHttpHandlerEnabled: boolean = true;
|
|
91
|
+
|
|
91
92
|
const _sessionManagementHelper = SessionManagementHelper(
|
|
92
93
|
async () => {
|
|
93
94
|
const message: Message<string> = {
|
|
@@ -186,7 +187,16 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
186
187
|
.then((response) => {
|
|
187
188
|
return Promise.resolve(response);
|
|
188
189
|
})
|
|
189
|
-
.catch((error) => {
|
|
190
|
+
.catch(async (error) => {
|
|
191
|
+
if (_isHttpHandlerEnabled) {
|
|
192
|
+
if (typeof httpClientHandlers.requestErrorCallback === "function") {
|
|
193
|
+
await httpClientHandlers.requestErrorCallback(error);
|
|
194
|
+
}
|
|
195
|
+
if (typeof httpClientHandlers.requestFinishCallback === "function") {
|
|
196
|
+
httpClientHandlers.requestFinishCallback();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
190
200
|
return Promise.reject(error);
|
|
191
201
|
});
|
|
192
202
|
};
|
|
@@ -210,7 +220,16 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
210
220
|
.then((response) => {
|
|
211
221
|
return Promise.resolve(response);
|
|
212
222
|
})
|
|
213
|
-
.catch((error) => {
|
|
223
|
+
.catch(async (error) => {
|
|
224
|
+
if (_isHttpHandlerEnabled) {
|
|
225
|
+
if (typeof httpClientHandlers.requestErrorCallback === "function") {
|
|
226
|
+
await httpClientHandlers.requestErrorCallback(error);
|
|
227
|
+
}
|
|
228
|
+
if (typeof httpClientHandlers.requestFinishCallback === "function") {
|
|
229
|
+
httpClientHandlers.requestFinishCallback();
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
214
233
|
return Promise.reject(error);
|
|
215
234
|
});
|
|
216
235
|
};
|
|
@@ -221,6 +240,8 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
221
240
|
};
|
|
222
241
|
return communicate<null, null>(message)
|
|
223
242
|
.then(() => {
|
|
243
|
+
_isHttpHandlerEnabled = true;
|
|
244
|
+
|
|
224
245
|
return Promise.resolve(true);
|
|
225
246
|
})
|
|
226
247
|
.catch((error) => {
|
|
@@ -234,6 +255,8 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
234
255
|
};
|
|
235
256
|
return communicate<null, null>(message)
|
|
236
257
|
.then(() => {
|
|
258
|
+
_isHttpHandlerEnabled = false;
|
|
259
|
+
|
|
237
260
|
return Promise.resolve(true);
|
|
238
261
|
})
|
|
239
262
|
.catch((error) => {
|
|
@@ -250,19 +273,17 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
250
273
|
*
|
|
251
274
|
*/
|
|
252
275
|
const initialize = (): Promise<boolean> => {
|
|
253
|
-
httpClientHandlers
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
276
|
+
if (!httpClientHandlers) {
|
|
277
|
+
httpClientHandlers = {
|
|
278
|
+
requestErrorCallback: () => Promise.resolve(),
|
|
279
|
+
requestFinishCallback: () => null,
|
|
280
|
+
requestStartCallback: () => null,
|
|
281
|
+
requestSuccessCallback: () => null
|
|
282
|
+
};
|
|
283
|
+
}
|
|
259
284
|
|
|
260
285
|
worker.onmessage = ({ data }) => {
|
|
261
286
|
switch (data.type) {
|
|
262
|
-
case REQUEST_ERROR:
|
|
263
|
-
httpClientHandlers?.requestErrorCallback &&
|
|
264
|
-
httpClientHandlers?.requestErrorCallback(data.data ? JSON.parse(data.data) : null);
|
|
265
|
-
break;
|
|
266
287
|
case REQUEST_FINISH:
|
|
267
288
|
httpClientHandlers?.requestFinishCallback && httpClientHandlers?.requestFinishCallback();
|
|
268
289
|
break;
|
|
@@ -342,6 +363,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
342
363
|
displayName: "",
|
|
343
364
|
email: "",
|
|
344
365
|
sessionState: "",
|
|
366
|
+
sub: "",
|
|
345
367
|
tenantDomain: "",
|
|
346
368
|
username: ""
|
|
347
369
|
});
|
|
@@ -394,16 +416,18 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
394
416
|
}
|
|
395
417
|
|
|
396
418
|
if (data?.type == CHECK_SESSION_SIGNED_IN && data?.data?.code) {
|
|
397
|
-
requestAccessToken(data?.data?.code, data?.data?.sessionState)
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
419
|
+
requestAccessToken(data?.data?.code, data?.data?.sessionState)
|
|
420
|
+
.then((response: BasicUserInfo) => {
|
|
421
|
+
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
422
|
+
resolve(response);
|
|
423
|
+
})
|
|
424
|
+
.catch((error) => {
|
|
425
|
+
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
426
|
+
reject(error);
|
|
427
|
+
})
|
|
428
|
+
.finally(() => {
|
|
429
|
+
clearTimeout(timer);
|
|
430
|
+
});
|
|
407
431
|
}
|
|
408
432
|
};
|
|
409
433
|
|
|
@@ -480,6 +504,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
480
504
|
displayName: "",
|
|
481
505
|
email: "",
|
|
482
506
|
sessionState: "",
|
|
507
|
+
sub: "",
|
|
483
508
|
tenantDomain: "",
|
|
484
509
|
username: ""
|
|
485
510
|
});
|
|
@@ -553,6 +578,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
553
578
|
displayName: "",
|
|
554
579
|
email: "",
|
|
555
580
|
sessionState: "",
|
|
581
|
+
sub: "",
|
|
556
582
|
tenantDomain: "",
|
|
557
583
|
username: ""
|
|
558
584
|
});
|
|
@@ -717,7 +743,7 @@ export const WebWorkerClient = (config: AuthClientConfig<WebWorkerClientConfig>)
|
|
|
717
743
|
}
|
|
718
744
|
};
|
|
719
745
|
|
|
720
|
-
const setHttpRequestErrorCallback = (callback: (response: HttpError) => void): void => {
|
|
746
|
+
const setHttpRequestErrorCallback = (callback: (response: HttpError) => void | Promise<void>): void => {
|
|
721
747
|
if (callback && typeof callback === "function") {
|
|
722
748
|
httpClientHandlers.requestErrorCallback = callback;
|
|
723
749
|
}
|
package/src/models/client.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface MainThreadClientInterface {
|
|
|
38
38
|
setHttpRequestStartCallback(callback: () => void): void;
|
|
39
39
|
setHttpRequestSuccessCallback(callback: (response: HttpResponse) => void): void;
|
|
40
40
|
setHttpRequestFinishCallback(callback: () => void): void;
|
|
41
|
-
setHttpRequestErrorCallback(callback: (error: HttpError) => void): void;
|
|
41
|
+
setHttpRequestErrorCallback(callback: (error: HttpError) => void | Promise<void>): void;
|
|
42
42
|
httpRequest(config: HttpRequestConfig): Promise<HttpResponse>;
|
|
43
43
|
httpRequestAll(config: HttpRequestConfig[]): Promise<HttpResponse[] | undefined>;
|
|
44
44
|
getHttpClient(): HttpClientInstance;
|
|
@@ -85,7 +85,7 @@ export interface WebWorkerClientInterface {
|
|
|
85
85
|
getIDToken(): Promise<string>;
|
|
86
86
|
isAuthenticated(): Promise<boolean>;
|
|
87
87
|
setHttpRequestSuccessCallback(callback: (response: HttpResponse) => void): void;
|
|
88
|
-
setHttpRequestErrorCallback(callback: (response: HttpError) => void): void;
|
|
88
|
+
setHttpRequestErrorCallback(callback: (response: HttpError) => void | Promise<void>): void;
|
|
89
89
|
setHttpRequestStartCallback(callback: () => void): void;
|
|
90
90
|
setHttpRequestFinishCallback(callback: () => void): void;
|
|
91
91
|
refreshAccessToken(): Promise<BasicUserInfo>;
|
|
@@ -22,7 +22,7 @@ import { HttpError, HttpResponse } from ".";
|
|
|
22
22
|
export interface HttpClient {
|
|
23
23
|
requestStartCallback: () => void;
|
|
24
24
|
requestSuccessCallback: (response: HttpResponse) => void;
|
|
25
|
-
requestErrorCallback: (error: HttpError) => void
|
|
25
|
+
requestErrorCallback: (error: HttpError) => void | Promise<void>;
|
|
26
26
|
requestFinishCallback: () => void;
|
|
27
27
|
}
|
|
28
28
|
|
package/src/models/web-worker.ts
CHANGED
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
DecodedIDTokenPayload,
|
|
25
25
|
OIDCEndpoints
|
|
26
26
|
} from "@asgardeo/auth-js";
|
|
27
|
-
import {
|
|
27
|
+
import { HttpRequestConfig, HttpResponse, Message } from ".";
|
|
28
28
|
import { AuthorizationResponse, WebWorkerClientConfig } from "..";
|
|
29
29
|
|
|
30
30
|
interface WebWorkerEvent<T> extends MessageEvent {
|
|
@@ -39,7 +39,6 @@ export interface WebWorkerCoreInterface {
|
|
|
39
39
|
setHttpRequestStartCallback(callback: () => void): void;
|
|
40
40
|
setHttpRequestSuccessCallback(callback: (response: HttpResponse) => void): void;
|
|
41
41
|
setHttpRequestFinishCallback(callback: () => void): void;
|
|
42
|
-
setHttpRequestErrorCallback(callback: (error: HttpError) => void): void;
|
|
43
42
|
httpRequest(config: HttpRequestConfig): Promise<HttpResponse>;
|
|
44
43
|
httpRequestAll(configs: HttpRequestConfig[]): Promise<HttpResponse[] | undefined>;
|
|
45
44
|
enableHttpHandler(): void;
|
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
REFRESH_ACCESS_TOKEN,
|
|
36
36
|
REQUEST_ACCESS_TOKEN,
|
|
37
37
|
REQUEST_CUSTOM_GRANT,
|
|
38
|
-
REQUEST_ERROR,
|
|
39
38
|
REQUEST_FINISH,
|
|
40
39
|
REQUEST_START,
|
|
41
40
|
REQUEST_SUCCESS,
|
|
@@ -48,7 +47,6 @@ import {
|
|
|
48
47
|
import { AsgardeoSPAException } from "../exception";
|
|
49
48
|
import {
|
|
50
49
|
AuthorizationResponse,
|
|
51
|
-
HttpError,
|
|
52
50
|
HttpResponse,
|
|
53
51
|
WebWorkerClass,
|
|
54
52
|
WebWorkerClientConfig,
|
|
@@ -83,7 +81,6 @@ ctx.onmessage = async ({ data, ports }) => {
|
|
|
83
81
|
try {
|
|
84
82
|
const config: AuthClientConfig<WebWorkerClientConfig> = { ...data.data };
|
|
85
83
|
webWorker = await WebWorkerCore(config);
|
|
86
|
-
webWorker.setHttpRequestErrorCallback(onRequestErrorCallback);
|
|
87
84
|
webWorker.setHttpRequestFinishCallback(onRequestFinishCallback);
|
|
88
85
|
webWorker.setHttpRequestStartCallback(onRequestStartCallback);
|
|
89
86
|
webWorker.setHttpRequestSuccessCallback(onRequestSuccessCallback);
|
|
@@ -279,22 +276,16 @@ ctx.onmessage = async ({ data, ports }) => {
|
|
|
279
276
|
}
|
|
280
277
|
};
|
|
281
278
|
|
|
282
|
-
const onRequestStartCallback = () => {
|
|
279
|
+
const onRequestStartCallback = (): void => {
|
|
283
280
|
ctx.postMessage({ type: REQUEST_START });
|
|
284
281
|
};
|
|
285
282
|
|
|
286
|
-
const onRequestSuccessCallback = (response: HttpResponse) => {
|
|
283
|
+
const onRequestSuccessCallback = (response: HttpResponse): void => {
|
|
287
284
|
ctx.postMessage({ data: JSON.stringify(response ?? ""), type: REQUEST_SUCCESS });
|
|
288
285
|
};
|
|
289
286
|
|
|
290
|
-
const onRequestFinishCallback = () => {
|
|
287
|
+
const onRequestFinishCallback = (): void => {
|
|
291
288
|
ctx.postMessage({ type: REQUEST_FINISH });
|
|
292
289
|
};
|
|
293
290
|
|
|
294
|
-
const onRequestErrorCallback = (error: HttpError) => {
|
|
295
|
-
const errorObject: Partial<HttpError> = { ...error };
|
|
296
|
-
delete errorObject.toJSON;
|
|
297
|
-
ctx.postMessage({ data: JSON.stringify(errorObject ?? ""), type: REQUEST_ERROR });
|
|
298
|
-
};
|
|
299
|
-
|
|
300
291
|
export default {} as typeof Worker & { new (): Worker };
|