@asgardeo/browser 0.0.1 → 0.1.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/README.md +3 -3
- package/dist/__legacy__/client.d.ts +34 -35
- package/dist/__legacy__/helpers/authentication-helper.d.ts +17 -17
- package/dist/__legacy__/helpers/session-management-helper.d.ts +2 -2
- package/dist/__legacy__/helpers/spa-helper.d.ts +1 -1
- package/dist/__legacy__/models/client-config.d.ts +3 -3
- package/dist/__legacy__/models/client.d.ts +28 -28
- package/dist/__legacy__/models/request-custom-grant.d.ts +2 -2
- package/dist/__legacy__/models/session-management-helper.d.ts +2 -2
- package/dist/__legacy__/models/sign-in.d.ts +2 -2
- package/dist/__legacy__/models/storage.d.ts +1 -1
- package/dist/__legacy__/models/web-worker.d.ts +16 -15
- package/dist/__legacy__/stores/local-store.d.ts +2 -2
- package/dist/__legacy__/stores/memory-store.d.ts +2 -2
- package/dist/__legacy__/stores/session-store.d.ts +2 -2
- package/dist/__legacy__/utils/crypto-utils.d.ts +1 -1
- package/dist/__legacy__/utils/spa-utils.d.ts +2 -2
- package/dist/cjs/index.js +1566 -1562
- package/dist/cjs/index.js.map +4 -4
- package/dist/index.js +1556 -1552
- package/dist/index.js.map +4 -4
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -1914,13 +1914,16 @@ var require_browser = __commonJS({
|
|
|
1914
1914
|
|
|
1915
1915
|
// src/__legacy__/client.ts
|
|
1916
1916
|
import {
|
|
1917
|
-
AsgardeoAuthException as
|
|
1917
|
+
AsgardeoAuthException as AsgardeoAuthException4
|
|
1918
1918
|
} from "@asgardeo/javascript";
|
|
1919
1919
|
|
|
1920
|
-
// src/__legacy__/
|
|
1920
|
+
// src/__legacy__/clients/main-thread-client.ts
|
|
1921
1921
|
import {
|
|
1922
|
-
|
|
1923
|
-
|
|
1922
|
+
AsgardeoAuthClient as AsgardeoAuthClient5,
|
|
1923
|
+
OIDCRequestConstants as OIDCRequestConstants3,
|
|
1924
|
+
extractPkceStorageKeyFromState as extractPkceStorageKeyFromState2,
|
|
1925
|
+
initializeApplicationNativeAuthentication,
|
|
1926
|
+
handleApplicationNativeAuthentication
|
|
1924
1927
|
} from "@asgardeo/javascript";
|
|
1925
1928
|
|
|
1926
1929
|
// src/__legacy__/constants/messages-types.ts
|
|
@@ -1991,6 +1994,12 @@ var STATE_QUERY = "state";
|
|
|
1991
1994
|
// src/__legacy__/constants/errors.ts
|
|
1992
1995
|
var ACCESS_TOKEN_INVALID = "Access token is invalid";
|
|
1993
1996
|
|
|
1997
|
+
// src/__legacy__/helpers/authentication-helper.ts
|
|
1998
|
+
import {
|
|
1999
|
+
AsgardeoAuthException,
|
|
2000
|
+
extractPkceStorageKeyFromState
|
|
2001
|
+
} from "@asgardeo/javascript";
|
|
2002
|
+
|
|
1994
2003
|
// src/__legacy__/utils/message-utils.ts
|
|
1995
2004
|
var MessageUtils = class {
|
|
1996
2005
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
@@ -2046,15 +2055,15 @@ var _SPAUtils = class _SPAUtils {
|
|
|
2046
2055
|
static setPKCE(pkceKey, pkce) {
|
|
2047
2056
|
sessionStorage.setItem(pkceKey, pkce);
|
|
2048
2057
|
}
|
|
2049
|
-
static setSignOutURL(url,
|
|
2058
|
+
static setSignOutURL(url, clientId, instanceID) {
|
|
2050
2059
|
sessionStorage.setItem(
|
|
2051
|
-
`${OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${
|
|
2060
|
+
`${OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${clientId}`,
|
|
2052
2061
|
url
|
|
2053
2062
|
);
|
|
2054
2063
|
}
|
|
2055
|
-
static
|
|
2064
|
+
static getSignOutUrl(clientId, instanceID) {
|
|
2056
2065
|
return sessionStorage.getItem(
|
|
2057
|
-
`${OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${
|
|
2066
|
+
`${OIDCRequestConstants.SignOut.Storage.StorageKeys.SIGN_OUT_URL}-instance_${instanceID}-${clientId}`
|
|
2058
2067
|
) ?? "";
|
|
2059
2068
|
}
|
|
2060
2069
|
static removePKCE(pkceKey) {
|
|
@@ -2108,7 +2117,7 @@ var _SPAUtils = class _SPAUtils {
|
|
|
2108
2117
|
if (AsgardeoAuthClient.isSignOutSuccessful(window.location.href)) {
|
|
2109
2118
|
const newUrl = window.location.href.split("?")[0];
|
|
2110
2119
|
history.pushState({}, document.title, newUrl);
|
|
2111
|
-
await AsgardeoAuthClient.
|
|
2120
|
+
await AsgardeoAuthClient.clearSession();
|
|
2112
2121
|
return true;
|
|
2113
2122
|
}
|
|
2114
2123
|
return false;
|
|
@@ -2207,14 +2216,14 @@ var SPAUtils = _SPAUtils;
|
|
|
2207
2216
|
var AuthenticationHelper = class {
|
|
2208
2217
|
constructor(authClient, spaHelper) {
|
|
2209
2218
|
__publicField(this, "_authenticationClient");
|
|
2210
|
-
__publicField(this, "
|
|
2219
|
+
__publicField(this, "_storageManager");
|
|
2211
2220
|
__publicField(this, "_spaHelper");
|
|
2212
2221
|
__publicField(this, "_instanceID");
|
|
2213
2222
|
__publicField(this, "_isTokenRefreshing");
|
|
2214
2223
|
this._authenticationClient = authClient;
|
|
2215
|
-
this.
|
|
2224
|
+
this._storageManager = this._authenticationClient.getStorageManager();
|
|
2216
2225
|
this._spaHelper = spaHelper;
|
|
2217
|
-
this._instanceID = this._authenticationClient.
|
|
2226
|
+
this._instanceID = this._authenticationClient.getInstanceId();
|
|
2218
2227
|
this._isTokenRefreshing = false;
|
|
2219
2228
|
}
|
|
2220
2229
|
enableHttpHandler(httpClient) {
|
|
@@ -2225,22 +2234,22 @@ var AuthenticationHelper = class {
|
|
|
2225
2234
|
}
|
|
2226
2235
|
initializeSessionManger(config, oidcEndpoints, getSessionState, getAuthzURL, sessionManagementHelper) {
|
|
2227
2236
|
sessionManagementHelper.initialize(
|
|
2228
|
-
config.
|
|
2237
|
+
config.clientId,
|
|
2229
2238
|
oidcEndpoints.checkSessionIframe ?? "",
|
|
2230
2239
|
getSessionState,
|
|
2231
2240
|
config.checkSessionInterval ?? 3,
|
|
2232
2241
|
config.sessionRefreshInterval ?? 300,
|
|
2233
|
-
config.
|
|
2242
|
+
config.afterSignInUrl,
|
|
2234
2243
|
getAuthzURL
|
|
2235
2244
|
);
|
|
2236
2245
|
}
|
|
2237
|
-
async
|
|
2246
|
+
async exchangeToken(config, enableRetrievingSignOutURLFromSession) {
|
|
2238
2247
|
let useDefaultEndpoint = true;
|
|
2239
2248
|
let matches = false;
|
|
2240
2249
|
if (config?.tokenEndpoint) {
|
|
2241
2250
|
useDefaultEndpoint = false;
|
|
2242
2251
|
for (const baseUrl of [
|
|
2243
|
-
...(await this.
|
|
2252
|
+
...(await this._storageManager.getConfigData())?.resourceServerURLs ?? [],
|
|
2244
2253
|
config.baseUrl
|
|
2245
2254
|
]) {
|
|
2246
2255
|
if (baseUrl && config.tokenEndpoint?.startsWith(baseUrl)) {
|
|
@@ -2250,16 +2259,16 @@ var AuthenticationHelper = class {
|
|
|
2250
2259
|
}
|
|
2251
2260
|
}
|
|
2252
2261
|
if (config.shouldReplayAfterRefresh) {
|
|
2253
|
-
this.
|
|
2262
|
+
this._storageManager.setTemporaryDataParameter(CUSTOM_GRANT_CONFIG, JSON.stringify(config));
|
|
2254
2263
|
}
|
|
2255
2264
|
if (useDefaultEndpoint || matches) {
|
|
2256
|
-
return this._authenticationClient.
|
|
2265
|
+
return this._authenticationClient.exchangeToken(config).then(async (response) => {
|
|
2257
2266
|
if (enableRetrievingSignOutURLFromSession && typeof enableRetrievingSignOutURLFromSession === "function") {
|
|
2258
2267
|
enableRetrievingSignOutURLFromSession(config);
|
|
2259
2268
|
}
|
|
2260
2269
|
if (config.returnsSession) {
|
|
2261
2270
|
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2262
|
-
return this._authenticationClient.
|
|
2271
|
+
return this._authenticationClient.getUser();
|
|
2263
2272
|
} else {
|
|
2264
2273
|
return response;
|
|
2265
2274
|
}
|
|
@@ -2277,7 +2286,7 @@ var AuthenticationHelper = class {
|
|
|
2277
2286
|
}
|
|
2278
2287
|
}
|
|
2279
2288
|
async getCustomGrantConfigData() {
|
|
2280
|
-
const configString = await this.
|
|
2289
|
+
const configString = await this._storageManager.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
|
|
2281
2290
|
if (configString) {
|
|
2282
2291
|
return JSON.parse(configString);
|
|
2283
2292
|
} else {
|
|
@@ -2289,10 +2298,10 @@ var AuthenticationHelper = class {
|
|
|
2289
2298
|
await this._authenticationClient.refreshAccessToken();
|
|
2290
2299
|
const customGrantConfig = await this.getCustomGrantConfigData();
|
|
2291
2300
|
if (customGrantConfig) {
|
|
2292
|
-
await this.
|
|
2301
|
+
await this.exchangeToken(customGrantConfig, enableRetrievingSignOutURLFromSession);
|
|
2293
2302
|
}
|
|
2294
2303
|
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2295
|
-
return this._authenticationClient.
|
|
2304
|
+
return this._authenticationClient.getUser();
|
|
2296
2305
|
} catch (error) {
|
|
2297
2306
|
const refreshTokenError = {
|
|
2298
2307
|
type: REFRESH_ACCESS_TOKEN_ERR0R
|
|
@@ -2325,7 +2334,7 @@ var AuthenticationHelper = class {
|
|
|
2325
2334
|
}
|
|
2326
2335
|
async httpRequest(httpClient, requestConfig, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback, enableRetrievingSignOutURLFromSession) {
|
|
2327
2336
|
let matches = false;
|
|
2328
|
-
const config = await this.
|
|
2337
|
+
const config = await this._storageManager.getConfigData();
|
|
2329
2338
|
for (const baseUrl of [...await config?.resourceServerURLs ?? [], config.baseUrl]) {
|
|
2330
2339
|
if (baseUrl && requestConfig?.url?.startsWith(baseUrl)) {
|
|
2331
2340
|
matches = true;
|
|
@@ -2410,7 +2419,7 @@ var AuthenticationHelper = class {
|
|
|
2410
2419
|
}
|
|
2411
2420
|
async httpRequestAll(requestConfigs, httpClient, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback) {
|
|
2412
2421
|
let matches = true;
|
|
2413
|
-
const config = await this.
|
|
2422
|
+
const config = await this._storageManager.getConfigData();
|
|
2414
2423
|
for (const requestConfig of requestConfigs) {
|
|
2415
2424
|
let urlMatches = false;
|
|
2416
2425
|
for (const baseUrl of [...(await config)?.resourceServerURLs ?? [], config.baseUrl]) {
|
|
@@ -2489,7 +2498,7 @@ var AuthenticationHelper = class {
|
|
|
2489
2498
|
}
|
|
2490
2499
|
}
|
|
2491
2500
|
async requestAccessToken(authorizationCode, sessionState, checkSession, pkce, state, tokenRequestConfig) {
|
|
2492
|
-
const config = await this.
|
|
2501
|
+
const config = await this._storageManager.getConfigData();
|
|
2493
2502
|
if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE && sessionState) {
|
|
2494
2503
|
const pkce2 = SPAUtils.getPKCE(extractPkceStorageKeyFromState(sessionState));
|
|
2495
2504
|
await this._authenticationClient.setPKCECode(extractPkceStorageKeyFromState(sessionState), pkce2);
|
|
@@ -2499,7 +2508,7 @@ var AuthenticationHelper = class {
|
|
|
2499
2508
|
if (authorizationCode) {
|
|
2500
2509
|
return this._authenticationClient.requestAccessToken(authorizationCode, sessionState ?? "", state ?? "", void 0, tokenRequestConfig).then(async () => {
|
|
2501
2510
|
if (config.storage !== "webWorker" /* WebWorker */) {
|
|
2502
|
-
SPAUtils.setSignOutURL(await this._authenticationClient.
|
|
2511
|
+
SPAUtils.setSignOutURL(await this._authenticationClient.getSignOutUrl(), config.clientId, this._instanceID);
|
|
2503
2512
|
if (this._spaHelper) {
|
|
2504
2513
|
this._spaHelper.clearRefreshTokenTimeout();
|
|
2505
2514
|
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
@@ -2512,7 +2521,7 @@ var AuthenticationHelper = class {
|
|
|
2512
2521
|
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2513
2522
|
}
|
|
2514
2523
|
}
|
|
2515
|
-
return this._authenticationClient.
|
|
2524
|
+
return this._authenticationClient.getUser();
|
|
2516
2525
|
}).catch((error) => {
|
|
2517
2526
|
return Promise.reject(error);
|
|
2518
2527
|
});
|
|
@@ -2575,7 +2584,7 @@ var AuthenticationHelper = class {
|
|
|
2575
2584
|
});
|
|
2576
2585
|
}
|
|
2577
2586
|
async handleSignIn(shouldStopAuthn, checkSession, tryRetrievingUserInfo) {
|
|
2578
|
-
const config = await this.
|
|
2587
|
+
const config = await this._storageManager.getConfigData();
|
|
2579
2588
|
if (await shouldStopAuthn()) {
|
|
2580
2589
|
return Promise.resolve({
|
|
2581
2590
|
allowedScopes: "",
|
|
@@ -2588,13 +2597,13 @@ var AuthenticationHelper = class {
|
|
|
2588
2597
|
});
|
|
2589
2598
|
}
|
|
2590
2599
|
if (config.storage !== "webWorker" /* WebWorker */) {
|
|
2591
|
-
if (await this._authenticationClient.
|
|
2600
|
+
if (await this._authenticationClient.isSignedIn()) {
|
|
2592
2601
|
this._spaHelper.clearRefreshTokenTimeout();
|
|
2593
2602
|
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2594
2603
|
if (config.enableOIDCSessionManagement) {
|
|
2595
2604
|
checkSession();
|
|
2596
2605
|
}
|
|
2597
|
-
return Promise.resolve(await this._authenticationClient.
|
|
2606
|
+
return Promise.resolve(await this._authenticationClient.getUser());
|
|
2598
2607
|
}
|
|
2599
2608
|
}
|
|
2600
2609
|
const error = new URL(window.location.href).searchParams.get(ERROR);
|
|
@@ -2630,35 +2639,35 @@ var AuthenticationHelper = class {
|
|
|
2630
2639
|
}
|
|
2631
2640
|
}
|
|
2632
2641
|
}
|
|
2633
|
-
async
|
|
2634
|
-
return this._authenticationClient.
|
|
2642
|
+
async getUser() {
|
|
2643
|
+
return this._authenticationClient.getUser();
|
|
2635
2644
|
}
|
|
2636
|
-
async
|
|
2637
|
-
return this._authenticationClient.
|
|
2645
|
+
async getDecodedIdToken() {
|
|
2646
|
+
return this._authenticationClient.getDecodedIdToken();
|
|
2638
2647
|
}
|
|
2639
2648
|
async getDecodedIDPIDToken() {
|
|
2640
|
-
return this._authenticationClient.
|
|
2649
|
+
return this._authenticationClient.getDecodedIdToken();
|
|
2641
2650
|
}
|
|
2642
|
-
async
|
|
2643
|
-
return this._authenticationClient.
|
|
2651
|
+
async getCrypto() {
|
|
2652
|
+
return this._authenticationClient.getCrypto();
|
|
2644
2653
|
}
|
|
2645
|
-
async
|
|
2646
|
-
return this._authenticationClient.
|
|
2654
|
+
async getIdToken() {
|
|
2655
|
+
return this._authenticationClient.getIdToken();
|
|
2647
2656
|
}
|
|
2648
|
-
async
|
|
2649
|
-
return this._authenticationClient.
|
|
2657
|
+
async getOpenIDProviderEndpoints() {
|
|
2658
|
+
return this._authenticationClient.getOpenIDProviderEndpoints();
|
|
2650
2659
|
}
|
|
2651
2660
|
async getAccessToken() {
|
|
2652
2661
|
return this._authenticationClient.getAccessToken();
|
|
2653
2662
|
}
|
|
2654
2663
|
async getIDPAccessToken() {
|
|
2655
|
-
return (await this.
|
|
2664
|
+
return (await this._storageManager.getSessionData())?.access_token;
|
|
2656
2665
|
}
|
|
2657
|
-
|
|
2658
|
-
return this.
|
|
2666
|
+
getStorageManager() {
|
|
2667
|
+
return this._storageManager;
|
|
2659
2668
|
}
|
|
2660
|
-
async
|
|
2661
|
-
return this._authenticationClient.
|
|
2669
|
+
async isSignedIn() {
|
|
2670
|
+
return this._authenticationClient.isSignedIn();
|
|
2662
2671
|
}
|
|
2663
2672
|
};
|
|
2664
2673
|
|
|
@@ -2667,32 +2676,32 @@ import { TokenConstants } from "@asgardeo/javascript";
|
|
|
2667
2676
|
var SPAHelper = class {
|
|
2668
2677
|
constructor(authClient) {
|
|
2669
2678
|
__publicField(this, "_authenticationClient");
|
|
2670
|
-
__publicField(this, "
|
|
2679
|
+
__publicField(this, "_storageManager");
|
|
2671
2680
|
this._authenticationClient = authClient;
|
|
2672
|
-
this.
|
|
2681
|
+
this._storageManager = this._authenticationClient.getStorageManager();
|
|
2673
2682
|
}
|
|
2674
2683
|
async refreshAccessTokenAutomatically(authenticationHelper) {
|
|
2675
|
-
const shouldRefreshAutomatically = (await this.
|
|
2684
|
+
const shouldRefreshAutomatically = (await this._storageManager.getConfigData())?.periodicTokenRefresh ?? false;
|
|
2676
2685
|
if (!shouldRefreshAutomatically) {
|
|
2677
2686
|
return;
|
|
2678
2687
|
}
|
|
2679
|
-
const sessionData = await this.
|
|
2688
|
+
const sessionData = await this._storageManager.getSessionData();
|
|
2680
2689
|
if (sessionData.refresh_token) {
|
|
2681
2690
|
const expiryTime = parseInt(sessionData.expires_in);
|
|
2682
2691
|
const time = expiryTime <= 10 ? expiryTime : expiryTime - 10;
|
|
2683
2692
|
const timer = setTimeout(async () => {
|
|
2684
2693
|
await authenticationHelper.refreshAccessToken();
|
|
2685
2694
|
}, time * 1e3);
|
|
2686
|
-
await this.
|
|
2695
|
+
await this._storageManager.setTemporaryDataParameter(
|
|
2687
2696
|
TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER,
|
|
2688
2697
|
JSON.stringify(timer)
|
|
2689
2698
|
);
|
|
2690
2699
|
}
|
|
2691
2700
|
}
|
|
2692
2701
|
async getRefreshTimeoutTimer() {
|
|
2693
|
-
if (await this.
|
|
2702
|
+
if (await this._storageManager.getTemporaryDataParameter(TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER)) {
|
|
2694
2703
|
return JSON.parse(
|
|
2695
|
-
await this.
|
|
2704
|
+
await this._storageManager.getTemporaryDataParameter(
|
|
2696
2705
|
TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER
|
|
2697
2706
|
)
|
|
2698
2707
|
);
|
|
@@ -2725,15 +2734,15 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
|
2725
2734
|
let _checkSessionIntervalTimeout;
|
|
2726
2735
|
let _storage;
|
|
2727
2736
|
let _setSessionState;
|
|
2728
|
-
let
|
|
2729
|
-
const initialize = (
|
|
2730
|
-
_clientID =
|
|
2737
|
+
let _getSignInUrl;
|
|
2738
|
+
const initialize = (clientId, checkSessionEndpoint, getSessionState, interval, sessionRefreshInterval, redirectURL, getSignInUrl) => {
|
|
2739
|
+
_clientID = clientId;
|
|
2731
2740
|
_checkSessionEndpoint = checkSessionEndpoint;
|
|
2732
2741
|
_sessionState = getSessionState;
|
|
2733
2742
|
_interval = interval;
|
|
2734
2743
|
_redirectURL = redirectURL;
|
|
2735
2744
|
_sessionRefreshInterval = sessionRefreshInterval;
|
|
2736
|
-
|
|
2745
|
+
_getSignInUrl = getSignInUrl;
|
|
2737
2746
|
if (_interval > -1) {
|
|
2738
2747
|
initiateCheckSession();
|
|
2739
2748
|
}
|
|
@@ -2799,7 +2808,7 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
|
2799
2808
|
if (_storage === "browserMemory" /* BrowserMemory */ || _storage === "webWorker" /* WebWorker */) {
|
|
2800
2809
|
window?.addEventListener("message", receiveMessageListener);
|
|
2801
2810
|
}
|
|
2802
|
-
const promptNoneURL = await
|
|
2811
|
+
const promptNoneURL = await _getSignInUrl({
|
|
2803
2812
|
prompt: "none",
|
|
2804
2813
|
response_mode: "query",
|
|
2805
2814
|
state: STATE
|
|
@@ -2857,7 +2866,7 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
|
2857
2866
|
}
|
|
2858
2867
|
SPAUtils.setPromptNoneRequestSent(false);
|
|
2859
2868
|
const signOutURL = await _signOut();
|
|
2860
|
-
await AsgardeoAuthClient4.
|
|
2869
|
+
await AsgardeoAuthClient4.clearSession();
|
|
2861
2870
|
parent.location.href = signOutURL;
|
|
2862
2871
|
window.location.href = "about:blank";
|
|
2863
2872
|
await SPAUtils.waitTillPageRedirect();
|
|
@@ -2906,15 +2915,6 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
|
2906
2915
|
};
|
|
2907
2916
|
})();
|
|
2908
2917
|
|
|
2909
|
-
// src/__legacy__/worker/worker-receiver.ts
|
|
2910
|
-
import { AsgardeoAuthException as AsgardeoAuthException3 } from "@asgardeo/javascript";
|
|
2911
|
-
|
|
2912
|
-
// src/__legacy__/worker/worker-core.ts
|
|
2913
|
-
import {
|
|
2914
|
-
AsgardeoAuthClient as AsgardeoAuthClient5,
|
|
2915
|
-
OIDCRequestConstants as OIDCRequestConstants3
|
|
2916
|
-
} from "@asgardeo/javascript";
|
|
2917
|
-
|
|
2918
2918
|
// src/__legacy__/http-client/clients/axios-http-client.ts
|
|
2919
2919
|
import axios from "axios";
|
|
2920
2920
|
|
|
@@ -3166,10 +3166,10 @@ var SPACryptoUtils = class {
|
|
|
3166
3166
|
generateRandomBytes(length) {
|
|
3167
3167
|
return (0, import_randombytes.default)(length);
|
|
3168
3168
|
}
|
|
3169
|
-
verifyJwt(idToken, jwk, algorithms,
|
|
3169
|
+
verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance, validateJwtIssuer) {
|
|
3170
3170
|
const jwtVerifyOptions = {
|
|
3171
3171
|
algorithms,
|
|
3172
|
-
audience:
|
|
3172
|
+
audience: clientId,
|
|
3173
3173
|
clockTolerance,
|
|
3174
3174
|
subject
|
|
3175
3175
|
};
|
|
@@ -3196,19 +3196,42 @@ var SPACryptoUtils = class {
|
|
|
3196
3196
|
}
|
|
3197
3197
|
};
|
|
3198
3198
|
|
|
3199
|
-
// src/__legacy__/
|
|
3200
|
-
var
|
|
3201
|
-
|
|
3199
|
+
// src/__legacy__/clients/main-thread-client.ts
|
|
3200
|
+
var initiateStore = (store) => {
|
|
3201
|
+
switch (store) {
|
|
3202
|
+
case "localStorage" /* LocalStorage */:
|
|
3203
|
+
return new LocalStore();
|
|
3204
|
+
case "sessionStorage" /* SessionStorage */:
|
|
3205
|
+
return new SessionStore();
|
|
3206
|
+
case "browserMemory" /* BrowserMemory */:
|
|
3207
|
+
return new MemoryStore();
|
|
3208
|
+
default:
|
|
3209
|
+
return new SessionStore();
|
|
3210
|
+
}
|
|
3211
|
+
};
|
|
3212
|
+
var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
3213
|
+
const _store = initiateStore(config.storage);
|
|
3202
3214
|
const _cryptoUtils = new SPACryptoUtils();
|
|
3203
3215
|
const _authenticationClient = new AsgardeoAuthClient5();
|
|
3204
|
-
await _authenticationClient.initialize(config, _store, _cryptoUtils);
|
|
3216
|
+
await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
|
|
3205
3217
|
const _spaHelper = new SPAHelper(_authenticationClient);
|
|
3206
|
-
const
|
|
3207
|
-
|
|
3208
|
-
|
|
3218
|
+
const _dataLayer = _authenticationClient.getStorageManager();
|
|
3219
|
+
const _sessionManagementHelper = await SessionManagementHelper(
|
|
3220
|
+
async () => {
|
|
3221
|
+
return _authenticationClient.getSignOutUrl();
|
|
3222
|
+
},
|
|
3223
|
+
config.storage ?? "sessionStorage" /* SessionStorage */,
|
|
3224
|
+
(sessionState) => _dataLayer.setSessionDataParameter(
|
|
3225
|
+
OIDCRequestConstants3.Params.SESSION_STATE,
|
|
3226
|
+
sessionState ?? ""
|
|
3227
|
+
)
|
|
3209
3228
|
);
|
|
3210
|
-
const
|
|
3229
|
+
const _authenticationHelper = getAuthHelper(_authenticationClient, _spaHelper);
|
|
3230
|
+
let _getSignOutURLFromSessionStorage = false;
|
|
3211
3231
|
const _httpClient = HttpClient.getInstance();
|
|
3232
|
+
let _isHttpHandlerEnabled = true;
|
|
3233
|
+
let _httpErrorCallback;
|
|
3234
|
+
let _httpFinishCallback;
|
|
3212
3235
|
const attachToken = async (request) => {
|
|
3213
3236
|
await _authenticationHelper.attachTokenToRequestConfig(request);
|
|
3214
3237
|
};
|
|
@@ -3222,47 +3245,156 @@ var WebWorkerCore = async (config, getAuthHelper) => {
|
|
|
3222
3245
|
const setHttpRequestFinishCallback = (callback) => {
|
|
3223
3246
|
_httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
|
|
3224
3247
|
};
|
|
3248
|
+
const setHttpRequestErrorCallback = (callback) => {
|
|
3249
|
+
_httpErrorCallback = callback;
|
|
3250
|
+
};
|
|
3225
3251
|
const httpRequest = async (requestConfig) => {
|
|
3226
|
-
return await _authenticationHelper.httpRequest(
|
|
3252
|
+
return await _authenticationHelper.httpRequest(
|
|
3253
|
+
_httpClient,
|
|
3254
|
+
requestConfig,
|
|
3255
|
+
_isHttpHandlerEnabled,
|
|
3256
|
+
_httpErrorCallback,
|
|
3257
|
+
_httpFinishCallback
|
|
3258
|
+
);
|
|
3227
3259
|
};
|
|
3228
3260
|
const httpRequestAll = async (requestConfigs) => {
|
|
3229
|
-
return await _authenticationHelper.httpRequestAll(
|
|
3261
|
+
return await _authenticationHelper.httpRequestAll(
|
|
3262
|
+
requestConfigs,
|
|
3263
|
+
_httpClient,
|
|
3264
|
+
_isHttpHandlerEnabled,
|
|
3265
|
+
_httpErrorCallback,
|
|
3266
|
+
_httpFinishCallback
|
|
3267
|
+
);
|
|
3268
|
+
};
|
|
3269
|
+
const getHttpClient = () => {
|
|
3270
|
+
return _httpClient;
|
|
3230
3271
|
};
|
|
3231
3272
|
const enableHttpHandler = () => {
|
|
3232
3273
|
_authenticationHelper.enableHttpHandler(_httpClient);
|
|
3274
|
+
_isHttpHandlerEnabled = true;
|
|
3275
|
+
return true;
|
|
3233
3276
|
};
|
|
3234
3277
|
const disableHttpHandler = () => {
|
|
3235
3278
|
_authenticationHelper.disableHttpHandler(_httpClient);
|
|
3279
|
+
_isHttpHandlerEnabled = false;
|
|
3280
|
+
return true;
|
|
3236
3281
|
};
|
|
3237
|
-
const
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3282
|
+
const checkSession = async () => {
|
|
3283
|
+
const oidcEndpoints = await _authenticationClient.getOpenIDProviderEndpoints();
|
|
3284
|
+
const config2 = await _dataLayer.getConfigData();
|
|
3285
|
+
_authenticationHelper.initializeSessionManger(
|
|
3286
|
+
config2,
|
|
3287
|
+
oidcEndpoints,
|
|
3288
|
+
async () => (await _authenticationClient.getUserSession()).sessionState,
|
|
3289
|
+
async (params) => _authenticationClient.getSignInUrl(params),
|
|
3290
|
+
_sessionManagementHelper
|
|
3291
|
+
);
|
|
3244
3292
|
};
|
|
3245
|
-
const
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3293
|
+
const shouldStopAuthn = async () => {
|
|
3294
|
+
return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
|
|
3295
|
+
await _dataLayer.setSessionDataParameter(
|
|
3296
|
+
OIDCRequestConstants3.Params.SESSION_STATE,
|
|
3297
|
+
sessionState ?? ""
|
|
3298
|
+
);
|
|
3299
|
+
return;
|
|
3300
|
+
});
|
|
3249
3301
|
};
|
|
3250
|
-
const
|
|
3251
|
-
|
|
3302
|
+
const setSessionStatus = async (sessionStatus) => {
|
|
3303
|
+
await _dataLayer.setSessionStatus(sessionStatus);
|
|
3304
|
+
};
|
|
3305
|
+
const signIn = async (signInConfig, authorizationCode, sessionState, state, tokenRequestConfig) => {
|
|
3306
|
+
if (signInConfig["flow"]) {
|
|
3307
|
+
return handleApplicationNativeAuthentication({
|
|
3308
|
+
url: signInConfig["flow"]["requestConfig"]["url"],
|
|
3309
|
+
payload: signInConfig["flow"]["payload"]
|
|
3310
|
+
});
|
|
3311
|
+
}
|
|
3312
|
+
const basicUserInfo = await _authenticationHelper.handleSignIn(shouldStopAuthn, checkSession, void 0);
|
|
3313
|
+
if (basicUserInfo) {
|
|
3314
|
+
return basicUserInfo;
|
|
3315
|
+
} else {
|
|
3316
|
+
let resolvedAuthorizationCode;
|
|
3317
|
+
let resolvedSessionState;
|
|
3318
|
+
let resolvedState;
|
|
3319
|
+
let resolvedTokenRequestConfig = { params: {} };
|
|
3320
|
+
if (config?.responseMode === "form_post" && authorizationCode) {
|
|
3321
|
+
resolvedAuthorizationCode = authorizationCode;
|
|
3322
|
+
resolvedSessionState = sessionState ?? "";
|
|
3323
|
+
resolvedState = state ?? "";
|
|
3324
|
+
} else {
|
|
3325
|
+
resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(OIDCRequestConstants3.Params.AUTHORIZATION_CODE) ?? "";
|
|
3326
|
+
resolvedSessionState = new URL(window.location.href).searchParams.get(OIDCRequestConstants3.Params.SESSION_STATE) ?? "";
|
|
3327
|
+
resolvedState = new URL(window.location.href).searchParams.get(OIDCRequestConstants3.Params.STATE) ?? "";
|
|
3328
|
+
SPAUtils.removeAuthorizationCode();
|
|
3329
|
+
}
|
|
3330
|
+
if (resolvedAuthorizationCode && resolvedState) {
|
|
3331
|
+
setSessionStatus("true");
|
|
3332
|
+
const storedTokenRequestConfig = await _dataLayer.getTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY);
|
|
3333
|
+
if (storedTokenRequestConfig && typeof storedTokenRequestConfig === "string") {
|
|
3334
|
+
resolvedTokenRequestConfig = JSON.parse(storedTokenRequestConfig);
|
|
3335
|
+
}
|
|
3336
|
+
return requestAccessToken(
|
|
3337
|
+
resolvedAuthorizationCode,
|
|
3338
|
+
resolvedSessionState,
|
|
3339
|
+
resolvedState,
|
|
3340
|
+
resolvedTokenRequestConfig
|
|
3341
|
+
);
|
|
3342
|
+
}
|
|
3343
|
+
return _authenticationClient.getSignInUrl(signInConfig).then(async (url) => {
|
|
3344
|
+
if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE) {
|
|
3345
|
+
const pkceKey = extractPkceStorageKeyFromState2(resolvedState);
|
|
3346
|
+
SPAUtils.setPKCE(pkceKey, await _authenticationClient.getPKCECode(resolvedState));
|
|
3347
|
+
}
|
|
3348
|
+
if (tokenRequestConfig) {
|
|
3349
|
+
_dataLayer.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
|
|
3350
|
+
}
|
|
3351
|
+
if (signInConfig["response_mode"] === "direct") {
|
|
3352
|
+
const authorizeUrl = new URL(url);
|
|
3353
|
+
return initializeApplicationNativeAuthentication({
|
|
3354
|
+
url: `${authorizeUrl.origin}${authorizeUrl.pathname}`,
|
|
3355
|
+
payload: Object.fromEntries(authorizeUrl.searchParams.entries())
|
|
3356
|
+
});
|
|
3357
|
+
} else {
|
|
3358
|
+
location.href = url;
|
|
3359
|
+
}
|
|
3360
|
+
await SPAUtils.waitTillPageRedirect();
|
|
3361
|
+
return Promise.resolve({
|
|
3362
|
+
allowedScopes: "",
|
|
3363
|
+
displayName: "",
|
|
3364
|
+
email: "",
|
|
3365
|
+
sessionState: "",
|
|
3366
|
+
sub: "",
|
|
3367
|
+
tenantDomain: "",
|
|
3368
|
+
username: ""
|
|
3369
|
+
});
|
|
3370
|
+
});
|
|
3371
|
+
}
|
|
3252
3372
|
};
|
|
3253
3373
|
const signOut = async () => {
|
|
3374
|
+
if (await _authenticationClient.isSignedIn() && !_getSignOutURLFromSessionStorage) {
|
|
3375
|
+
location.href = await _authenticationClient.getSignOutUrl();
|
|
3376
|
+
} else {
|
|
3377
|
+
location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
|
|
3378
|
+
}
|
|
3254
3379
|
_spaHelper.clearRefreshTokenTimeout();
|
|
3255
|
-
|
|
3380
|
+
await _dataLayer.removeOIDCProviderMetaData();
|
|
3381
|
+
await _dataLayer.removeTemporaryData();
|
|
3382
|
+
await _dataLayer.removeSessionData();
|
|
3383
|
+
await _dataLayer.removeSessionStatus();
|
|
3384
|
+
await SPAUtils.waitTillPageRedirect();
|
|
3385
|
+
return true;
|
|
3256
3386
|
};
|
|
3257
|
-
const
|
|
3258
|
-
|
|
3387
|
+
const enableRetrievingSignOutURLFromSession = (config2) => {
|
|
3388
|
+
if (config2.preventSignOutURLUpdate) {
|
|
3389
|
+
_getSignOutURLFromSessionStorage = true;
|
|
3390
|
+
}
|
|
3259
3391
|
};
|
|
3260
|
-
const
|
|
3261
|
-
return await _authenticationHelper.
|
|
3392
|
+
const exchangeToken = async (config2) => {
|
|
3393
|
+
return await _authenticationHelper.exchangeToken(config2, enableRetrievingSignOutURLFromSession);
|
|
3262
3394
|
};
|
|
3263
3395
|
const refreshAccessToken = async () => {
|
|
3264
3396
|
try {
|
|
3265
|
-
return await _authenticationHelper.refreshAccessToken();
|
|
3397
|
+
return await _authenticationHelper.refreshAccessToken(enableRetrievingSignOutURLFromSession);
|
|
3266
3398
|
} catch (error) {
|
|
3267
3399
|
return Promise.reject(error);
|
|
3268
3400
|
}
|
|
@@ -3270,300 +3402,127 @@ var WebWorkerCore = async (config, getAuthHelper) => {
|
|
|
3270
3402
|
const revokeAccessToken = async () => {
|
|
3271
3403
|
const timer = await _spaHelper.getRefreshTimeoutTimer();
|
|
3272
3404
|
return _authenticationClient.revokeAccessToken().then(() => {
|
|
3405
|
+
_sessionManagementHelper.reset();
|
|
3273
3406
|
_spaHelper.clearRefreshTokenTimeout(timer);
|
|
3274
3407
|
return Promise.resolve(true);
|
|
3275
3408
|
}).catch((error) => Promise.reject(error));
|
|
3276
3409
|
};
|
|
3277
|
-
const
|
|
3278
|
-
return _authenticationHelper.
|
|
3410
|
+
const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
|
|
3411
|
+
return await _authenticationHelper.requestAccessToken(
|
|
3412
|
+
resolvedAuthorizationCode,
|
|
3413
|
+
resolvedSessionState,
|
|
3414
|
+
checkSession,
|
|
3415
|
+
void 0,
|
|
3416
|
+
resolvedState,
|
|
3417
|
+
tokenRequestConfig
|
|
3418
|
+
);
|
|
3419
|
+
};
|
|
3420
|
+
const constructSilentSignInUrl = async (additionalParams = {}) => {
|
|
3421
|
+
const config2 = await _dataLayer.getConfigData();
|
|
3422
|
+
const urlString = await _authenticationClient.getSignInUrl({
|
|
3423
|
+
prompt: "none",
|
|
3424
|
+
state: SILENT_SIGN_IN_STATE,
|
|
3425
|
+
...additionalParams
|
|
3426
|
+
});
|
|
3427
|
+
const urlObject = new URL(urlString);
|
|
3428
|
+
urlObject.searchParams.set("response_mode", "query");
|
|
3429
|
+
const url = urlObject.toString();
|
|
3430
|
+
if (config2.storage === "browserMemory" /* BrowserMemory */ && config2.enablePKCE) {
|
|
3431
|
+
const state = urlObject.searchParams.get(OIDCRequestConstants3.Params.STATE);
|
|
3432
|
+
SPAUtils.setPKCE(
|
|
3433
|
+
extractPkceStorageKeyFromState2(state ?? ""),
|
|
3434
|
+
await _authenticationClient.getPKCECode(state ?? "")
|
|
3435
|
+
);
|
|
3436
|
+
}
|
|
3437
|
+
return url;
|
|
3438
|
+
};
|
|
3439
|
+
const trySignInSilently = async (additionalParams, tokenRequestConfig) => {
|
|
3440
|
+
return await _authenticationHelper.trySignInSilently(
|
|
3441
|
+
constructSilentSignInUrl,
|
|
3442
|
+
requestAccessToken,
|
|
3443
|
+
_sessionManagementHelper,
|
|
3444
|
+
additionalParams,
|
|
3445
|
+
tokenRequestConfig
|
|
3446
|
+
);
|
|
3279
3447
|
};
|
|
3280
|
-
const
|
|
3281
|
-
return _authenticationHelper.
|
|
3448
|
+
const getUser = async () => {
|
|
3449
|
+
return _authenticationHelper.getUser();
|
|
3282
3450
|
};
|
|
3283
|
-
const
|
|
3284
|
-
return _authenticationHelper.
|
|
3451
|
+
const getDecodedIdToken = async () => {
|
|
3452
|
+
return _authenticationHelper.getDecodedIdToken();
|
|
3285
3453
|
};
|
|
3286
|
-
const
|
|
3287
|
-
return _authenticationHelper.
|
|
3454
|
+
const getCrypto = async () => {
|
|
3455
|
+
return _authenticationHelper.getCrypto();
|
|
3288
3456
|
};
|
|
3289
|
-
const
|
|
3290
|
-
return _authenticationHelper.
|
|
3457
|
+
const getIdToken = async () => {
|
|
3458
|
+
return _authenticationHelper.getIdToken();
|
|
3291
3459
|
};
|
|
3292
|
-
const
|
|
3293
|
-
return _authenticationHelper.
|
|
3460
|
+
const getOpenIDProviderEndpoints = async () => {
|
|
3461
|
+
return _authenticationHelper.getOpenIDProviderEndpoints();
|
|
3294
3462
|
};
|
|
3295
|
-
const getAccessToken = () => {
|
|
3463
|
+
const getAccessToken = async () => {
|
|
3296
3464
|
return _authenticationHelper.getAccessToken();
|
|
3297
3465
|
};
|
|
3298
|
-
const
|
|
3299
|
-
return _authenticationHelper.
|
|
3466
|
+
const getStorageManager = async () => {
|
|
3467
|
+
return _authenticationHelper.getStorageManager();
|
|
3300
3468
|
};
|
|
3301
|
-
const
|
|
3302
|
-
await _dataLayer.
|
|
3303
|
-
OIDCRequestConstants3.Params.SESSION_STATE,
|
|
3304
|
-
sessionState
|
|
3305
|
-
);
|
|
3306
|
-
return;
|
|
3469
|
+
const getConfigData = async () => {
|
|
3470
|
+
return await _dataLayer.getConfigData();
|
|
3307
3471
|
};
|
|
3308
|
-
const
|
|
3309
|
-
|
|
3310
|
-
return;
|
|
3472
|
+
const isSignedIn = async () => {
|
|
3473
|
+
return _authenticationHelper.isSignedIn();
|
|
3311
3474
|
};
|
|
3312
|
-
const
|
|
3313
|
-
return _dataLayer.
|
|
3475
|
+
const isSessionActive = async () => {
|
|
3476
|
+
return await _dataLayer.getSessionStatus() === "true";
|
|
3477
|
+
};
|
|
3478
|
+
const reInitialize = async (newConfig) => {
|
|
3479
|
+
const existingConfig = await _dataLayer.getConfigData();
|
|
3480
|
+
const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
|
|
3481
|
+
const config2 = { ...existingConfig, ...newConfig };
|
|
3482
|
+
await _authenticationClient.reInitialize(config2);
|
|
3483
|
+
if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
|
|
3484
|
+
_sessionManagementHelper.reset();
|
|
3485
|
+
checkSession();
|
|
3486
|
+
}
|
|
3314
3487
|
};
|
|
3315
3488
|
return {
|
|
3316
3489
|
disableHttpHandler,
|
|
3317
3490
|
enableHttpHandler,
|
|
3318
3491
|
getAccessToken,
|
|
3319
|
-
|
|
3320
|
-
getBasicUserInfo,
|
|
3492
|
+
getUser,
|
|
3321
3493
|
getConfigData,
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3494
|
+
getCrypto,
|
|
3495
|
+
getStorageManager,
|
|
3496
|
+
getDecodedIdToken,
|
|
3497
|
+
getHttpClient,
|
|
3498
|
+
getIdToken,
|
|
3499
|
+
getOpenIDProviderEndpoints,
|
|
3328
3500
|
httpRequest,
|
|
3329
3501
|
httpRequestAll,
|
|
3330
|
-
|
|
3502
|
+
isSignedIn,
|
|
3503
|
+
isSessionActive,
|
|
3331
3504
|
refreshAccessToken,
|
|
3332
|
-
|
|
3333
|
-
requestCustomGrant,
|
|
3505
|
+
exchangeToken,
|
|
3334
3506
|
revokeAccessToken,
|
|
3507
|
+
setHttpRequestErrorCallback,
|
|
3335
3508
|
setHttpRequestFinishCallback,
|
|
3336
3509
|
setHttpRequestStartCallback,
|
|
3337
3510
|
setHttpRequestSuccessCallback,
|
|
3338
|
-
|
|
3511
|
+
signIn,
|
|
3339
3512
|
signOut,
|
|
3340
|
-
|
|
3341
|
-
|
|
3513
|
+
trySignInSilently,
|
|
3514
|
+
reInitialize
|
|
3342
3515
|
};
|
|
3343
3516
|
};
|
|
3344
3517
|
|
|
3345
|
-
// src/__legacy__/
|
|
3346
|
-
var workerReceiver = (getAuthHelper) => {
|
|
3347
|
-
const ctx = self;
|
|
3348
|
-
let webWorker;
|
|
3349
|
-
ctx.onmessage = async ({ data, ports }) => {
|
|
3350
|
-
const port = ports[0];
|
|
3351
|
-
if (data.type !== INIT && !webWorker) {
|
|
3352
|
-
port.postMessage(
|
|
3353
|
-
MessageUtils.generateFailureMessage(
|
|
3354
|
-
new AsgardeoAuthException3(
|
|
3355
|
-
"SPA-CLIENT_WORKER-ONMSG-NF01",
|
|
3356
|
-
"The web worker has not been initialized yet.",
|
|
3357
|
-
"The initialize method needs to be called before the specified operation can be carried out."
|
|
3358
|
-
)
|
|
3359
|
-
)
|
|
3360
|
-
);
|
|
3361
|
-
return;
|
|
3362
|
-
}
|
|
3363
|
-
switch (data.type) {
|
|
3364
|
-
case INIT:
|
|
3365
|
-
try {
|
|
3366
|
-
const config = { ...data.data };
|
|
3367
|
-
webWorker = await WebWorkerCore(config, getAuthHelper);
|
|
3368
|
-
webWorker.setHttpRequestFinishCallback(onRequestFinishCallback);
|
|
3369
|
-
webWorker.setHttpRequestStartCallback(onRequestStartCallback);
|
|
3370
|
-
webWorker.setHttpRequestSuccessCallback(onRequestSuccessCallback);
|
|
3371
|
-
port.postMessage(MessageUtils.generateSuccessMessage());
|
|
3372
|
-
} catch (error) {
|
|
3373
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3374
|
-
}
|
|
3375
|
-
break;
|
|
3376
|
-
case GET_AUTH_URL:
|
|
3377
|
-
webWorker.getAuthorizationURL(data?.data).then((response) => {
|
|
3378
|
-
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
3379
|
-
}).catch((error) => {
|
|
3380
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3381
|
-
});
|
|
3382
|
-
break;
|
|
3383
|
-
case REQUEST_ACCESS_TOKEN:
|
|
3384
|
-
webWorker.requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.pkce, data?.data?.state).then((response) => {
|
|
3385
|
-
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
3386
|
-
}).catch((error) => {
|
|
3387
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3388
|
-
});
|
|
3389
|
-
break;
|
|
3390
|
-
case HTTP_REQUEST: {
|
|
3391
|
-
const request = data.data;
|
|
3392
|
-
const requestData = request?.data;
|
|
3393
|
-
if (data.data?.data?.formData === true) {
|
|
3394
|
-
const formData = new FormData();
|
|
3395
|
-
for (const key in requestData) {
|
|
3396
|
-
if (key === "formData") {
|
|
3397
|
-
continue;
|
|
3398
|
-
}
|
|
3399
|
-
formData.append(key, requestData[key]);
|
|
3400
|
-
}
|
|
3401
|
-
request.data = formData;
|
|
3402
|
-
}
|
|
3403
|
-
webWorker.httpRequest(request).then((response) => {
|
|
3404
|
-
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
3405
|
-
}).catch((error) => {
|
|
3406
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3407
|
-
});
|
|
3408
|
-
break;
|
|
3409
|
-
}
|
|
3410
|
-
case HTTP_REQUEST_ALL:
|
|
3411
|
-
webWorker.httpRequestAll(data.data).then((response) => {
|
|
3412
|
-
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
3413
|
-
}).catch((error) => {
|
|
3414
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3415
|
-
});
|
|
3416
|
-
break;
|
|
3417
|
-
case SIGN_OUT:
|
|
3418
|
-
try {
|
|
3419
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.signOut()));
|
|
3420
|
-
} catch (error) {
|
|
3421
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3422
|
-
}
|
|
3423
|
-
break;
|
|
3424
|
-
case REQUEST_CUSTOM_GRANT:
|
|
3425
|
-
webWorker.requestCustomGrant(data.data).then((response) => {
|
|
3426
|
-
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
3427
|
-
}).catch((error) => {
|
|
3428
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3429
|
-
});
|
|
3430
|
-
break;
|
|
3431
|
-
case REVOKE_ACCESS_TOKEN:
|
|
3432
|
-
webWorker.revokeAccessToken().then((response) => {
|
|
3433
|
-
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
3434
|
-
}).catch((error) => {
|
|
3435
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3436
|
-
});
|
|
3437
|
-
break;
|
|
3438
|
-
case GET_OIDC_SERVICE_ENDPOINTS:
|
|
3439
|
-
try {
|
|
3440
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getOIDCServiceEndpoints()));
|
|
3441
|
-
} catch (error) {
|
|
3442
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3443
|
-
}
|
|
3444
|
-
break;
|
|
3445
|
-
case GET_BASIC_USER_INFO:
|
|
3446
|
-
try {
|
|
3447
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getBasicUserInfo()));
|
|
3448
|
-
} catch (error) {
|
|
3449
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3450
|
-
}
|
|
3451
|
-
break;
|
|
3452
|
-
case GET_DECODED_ID_TOKEN:
|
|
3453
|
-
try {
|
|
3454
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getDecodedIDToken()));
|
|
3455
|
-
} catch (error) {
|
|
3456
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3457
|
-
}
|
|
3458
|
-
break;
|
|
3459
|
-
case GET_CRYPTO_HELPER:
|
|
3460
|
-
try {
|
|
3461
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getCryptoHelper()));
|
|
3462
|
-
} catch (error) {
|
|
3463
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3464
|
-
}
|
|
3465
|
-
break;
|
|
3466
|
-
case GET_ID_TOKEN:
|
|
3467
|
-
try {
|
|
3468
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getIDToken()));
|
|
3469
|
-
} catch (error) {
|
|
3470
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3471
|
-
}
|
|
3472
|
-
break;
|
|
3473
|
-
case ENABLE_HTTP_HANDLER:
|
|
3474
|
-
webWorker.enableHttpHandler();
|
|
3475
|
-
port.postMessage(MessageUtils.generateSuccessMessage());
|
|
3476
|
-
break;
|
|
3477
|
-
case DISABLE_HTTP_HANDLER:
|
|
3478
|
-
webWorker.disableHttpHandler();
|
|
3479
|
-
port.postMessage(MessageUtils.generateSuccessMessage());
|
|
3480
|
-
break;
|
|
3481
|
-
case IS_AUTHENTICATED:
|
|
3482
|
-
try {
|
|
3483
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.isAuthenticated()));
|
|
3484
|
-
} catch (error) {
|
|
3485
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3486
|
-
}
|
|
3487
|
-
break;
|
|
3488
|
-
case GET_SIGN_OUT_URL:
|
|
3489
|
-
try {
|
|
3490
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getSignOutURL()));
|
|
3491
|
-
} catch (error) {
|
|
3492
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3493
|
-
}
|
|
3494
|
-
break;
|
|
3495
|
-
case REFRESH_ACCESS_TOKEN:
|
|
3496
|
-
try {
|
|
3497
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.refreshAccessToken()));
|
|
3498
|
-
} catch (error) {
|
|
3499
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3500
|
-
}
|
|
3501
|
-
break;
|
|
3502
|
-
case START_AUTO_REFRESH_TOKEN:
|
|
3503
|
-
try {
|
|
3504
|
-
port.postMessage(MessageUtils.generateSuccessMessage(webWorker.startAutoRefreshToken()));
|
|
3505
|
-
} catch (error) {
|
|
3506
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3507
|
-
}
|
|
3508
|
-
break;
|
|
3509
|
-
case SET_SESSION_STATE:
|
|
3510
|
-
try {
|
|
3511
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.setSessionState(data?.data)));
|
|
3512
|
-
} catch (error) {
|
|
3513
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3514
|
-
}
|
|
3515
|
-
break;
|
|
3516
|
-
case UPDATE_CONFIG:
|
|
3517
|
-
try {
|
|
3518
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.updateConfig(data?.data)));
|
|
3519
|
-
} catch (error) {
|
|
3520
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3521
|
-
}
|
|
3522
|
-
break;
|
|
3523
|
-
case GET_CONFIG_DATA:
|
|
3524
|
-
try {
|
|
3525
|
-
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getConfigData()));
|
|
3526
|
-
} catch (error) {
|
|
3527
|
-
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
3528
|
-
}
|
|
3529
|
-
break;
|
|
3530
|
-
default:
|
|
3531
|
-
port?.postMessage(
|
|
3532
|
-
MessageUtils.generateFailureMessage(
|
|
3533
|
-
new AsgardeoAuthException3(
|
|
3534
|
-
"SPA-CLIENT_WORKER-ONMSG-IV02",
|
|
3535
|
-
"The message type is invalid.",
|
|
3536
|
-
`The message type provided, ${data.type}, is invalid.`
|
|
3537
|
-
)
|
|
3538
|
-
)
|
|
3539
|
-
);
|
|
3540
|
-
}
|
|
3541
|
-
};
|
|
3542
|
-
const onRequestStartCallback = () => {
|
|
3543
|
-
ctx.postMessage({ type: REQUEST_START });
|
|
3544
|
-
};
|
|
3545
|
-
const onRequestSuccessCallback = (response) => {
|
|
3546
|
-
ctx.postMessage({ data: JSON.stringify(response ?? ""), type: REQUEST_SUCCESS });
|
|
3547
|
-
};
|
|
3548
|
-
const onRequestFinishCallback = () => {
|
|
3549
|
-
ctx.postMessage({ type: REQUEST_FINISH });
|
|
3550
|
-
};
|
|
3551
|
-
};
|
|
3552
|
-
|
|
3553
|
-
// src/worker.ts
|
|
3554
|
-
workerReceiver((authClient, spaHelper) => {
|
|
3555
|
-
return new AuthenticationHelper(authClient, spaHelper);
|
|
3556
|
-
});
|
|
3557
|
-
var worker_default = {};
|
|
3558
|
-
|
|
3559
|
-
// src/__legacy__/clients/main-thread-client.ts
|
|
3518
|
+
// src/__legacy__/clients/web-worker-client.ts
|
|
3560
3519
|
import {
|
|
3561
|
-
AsgardeoAuthClient as
|
|
3562
|
-
|
|
3520
|
+
AsgardeoAuthClient as AsgardeoAuthClient6,
|
|
3521
|
+
AsgardeoAuthException as AsgardeoAuthException3,
|
|
3563
3522
|
OIDCRequestConstants as OIDCRequestConstants4,
|
|
3564
|
-
extractPkceStorageKeyFromState as
|
|
3523
|
+
extractPkceStorageKeyFromState as extractPkceStorageKeyFromState3
|
|
3565
3524
|
} from "@asgardeo/javascript";
|
|
3566
|
-
var
|
|
3525
|
+
var initiateStore2 = (store) => {
|
|
3567
3526
|
switch (store) {
|
|
3568
3527
|
case "localStorage" /* LocalStorage */:
|
|
3569
3528
|
return new LocalStore();
|
|
@@ -3575,109 +3534,308 @@ var initiateStore = (store) => {
|
|
|
3575
3534
|
return new SessionStore();
|
|
3576
3535
|
}
|
|
3577
3536
|
};
|
|
3578
|
-
var
|
|
3579
|
-
|
|
3537
|
+
var WebWorkerClient = async (instanceID, config, webWorker, getAuthHelper) => {
|
|
3538
|
+
let httpClientHandlers;
|
|
3539
|
+
const _requestTimeout = config?.requestTimeout ?? 6e4;
|
|
3540
|
+
let _isHttpHandlerEnabled = true;
|
|
3541
|
+
let _getSignOutURLFromSessionStorage = false;
|
|
3542
|
+
const _store = initiateStore2(config.storage);
|
|
3580
3543
|
const _cryptoUtils = new SPACryptoUtils();
|
|
3581
|
-
const _authenticationClient = new
|
|
3544
|
+
const _authenticationClient = new AsgardeoAuthClient6();
|
|
3582
3545
|
await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
|
|
3583
3546
|
const _spaHelper = new SPAHelper(_authenticationClient);
|
|
3584
|
-
const _dataLayer = _authenticationClient.getDataLayer();
|
|
3585
3547
|
const _sessionManagementHelper = await SessionManagementHelper(
|
|
3586
3548
|
async () => {
|
|
3587
|
-
|
|
3549
|
+
const message = {
|
|
3550
|
+
type: SIGN_OUT
|
|
3551
|
+
};
|
|
3552
|
+
try {
|
|
3553
|
+
const signOutURL = await communicate(message);
|
|
3554
|
+
return signOutURL;
|
|
3555
|
+
} catch {
|
|
3556
|
+
return SPAUtils.getSignOutUrl(config.clientId, instanceID);
|
|
3557
|
+
}
|
|
3588
3558
|
},
|
|
3589
|
-
config.storage
|
|
3590
|
-
(sessionState) =>
|
|
3591
|
-
OIDCRequestConstants4.Params.SESSION_STATE,
|
|
3592
|
-
sessionState ?? ""
|
|
3593
|
-
)
|
|
3559
|
+
config.storage,
|
|
3560
|
+
(sessionState) => setSessionState(sessionState)
|
|
3594
3561
|
);
|
|
3595
|
-
const _authenticationHelper = getAuthHelper(
|
|
3596
|
-
|
|
3597
|
-
|
|
3598
|
-
|
|
3599
|
-
|
|
3600
|
-
|
|
3601
|
-
|
|
3602
|
-
|
|
3562
|
+
const _authenticationHelper = getAuthHelper(
|
|
3563
|
+
_authenticationClient,
|
|
3564
|
+
_spaHelper
|
|
3565
|
+
);
|
|
3566
|
+
const worker = new webWorker();
|
|
3567
|
+
const communicate = (message) => {
|
|
3568
|
+
const channel = new MessageChannel();
|
|
3569
|
+
worker.postMessage(message, [channel.port2]);
|
|
3570
|
+
return new Promise((resolve, reject) => {
|
|
3571
|
+
const timer = setTimeout(() => {
|
|
3572
|
+
reject(
|
|
3573
|
+
new AsgardeoAuthException3(
|
|
3574
|
+
"SPA-WEB_WORKER_CLIENT-COM-TO01",
|
|
3575
|
+
"Operation timed out.",
|
|
3576
|
+
"No response was received from the web worker for " + _requestTimeout / 1e3 + " since dispatching the request"
|
|
3577
|
+
)
|
|
3578
|
+
);
|
|
3579
|
+
}, _requestTimeout);
|
|
3580
|
+
return channel.port1.onmessage = ({ data }) => {
|
|
3581
|
+
clearTimeout(timer);
|
|
3582
|
+
channel.port1.close();
|
|
3583
|
+
channel.port2.close();
|
|
3584
|
+
if (data?.success) {
|
|
3585
|
+
const responseData = data?.data ? JSON.parse(data?.data) : null;
|
|
3586
|
+
if (data?.blob) {
|
|
3587
|
+
responseData.data = data?.blob;
|
|
3588
|
+
}
|
|
3589
|
+
resolve(responseData);
|
|
3590
|
+
} else {
|
|
3591
|
+
reject(data.error ? JSON.parse(data.error) : null);
|
|
3592
|
+
}
|
|
3593
|
+
};
|
|
3594
|
+
});
|
|
3603
3595
|
};
|
|
3604
|
-
|
|
3605
|
-
|
|
3606
|
-
|
|
3607
|
-
|
|
3608
|
-
|
|
3609
|
-
|
|
3596
|
+
const exchangeToken = (requestParams) => {
|
|
3597
|
+
const message = {
|
|
3598
|
+
data: requestParams,
|
|
3599
|
+
type: REQUEST_CUSTOM_GRANT
|
|
3600
|
+
};
|
|
3601
|
+
return communicate(message).then((response) => {
|
|
3602
|
+
if (requestParams.preventSignOutURLUpdate) {
|
|
3603
|
+
_getSignOutURLFromSessionStorage = true;
|
|
3604
|
+
}
|
|
3605
|
+
return Promise.resolve(response);
|
|
3606
|
+
}).catch((error) => {
|
|
3607
|
+
return Promise.reject(error);
|
|
3608
|
+
});
|
|
3610
3609
|
};
|
|
3611
|
-
const
|
|
3612
|
-
|
|
3610
|
+
const httpRequest = (config2) => {
|
|
3611
|
+
if (config2?.data && config2?.data instanceof FormData) {
|
|
3612
|
+
config2.data = { ...Object.fromEntries((config2?.data).entries()), formData: true };
|
|
3613
|
+
}
|
|
3614
|
+
const message = {
|
|
3615
|
+
data: config2,
|
|
3616
|
+
type: HTTP_REQUEST
|
|
3617
|
+
};
|
|
3618
|
+
return communicate(message).then((response) => {
|
|
3619
|
+
return Promise.resolve(response);
|
|
3620
|
+
}).catch(async (error) => {
|
|
3621
|
+
if (_isHttpHandlerEnabled) {
|
|
3622
|
+
if (typeof httpClientHandlers.requestErrorCallback === "function") {
|
|
3623
|
+
await httpClientHandlers.requestErrorCallback(error);
|
|
3624
|
+
}
|
|
3625
|
+
if (typeof httpClientHandlers.requestFinishCallback === "function") {
|
|
3626
|
+
httpClientHandlers.requestFinishCallback();
|
|
3627
|
+
}
|
|
3628
|
+
}
|
|
3629
|
+
return Promise.reject(error);
|
|
3630
|
+
});
|
|
3613
3631
|
};
|
|
3614
|
-
const
|
|
3615
|
-
|
|
3632
|
+
const httpRequestAll = (configs) => {
|
|
3633
|
+
const message = {
|
|
3634
|
+
data: configs,
|
|
3635
|
+
type: HTTP_REQUEST_ALL
|
|
3636
|
+
};
|
|
3637
|
+
return communicate(message).then((response) => {
|
|
3638
|
+
return Promise.resolve(response);
|
|
3639
|
+
}).catch(async (error) => {
|
|
3640
|
+
if (_isHttpHandlerEnabled) {
|
|
3641
|
+
if (typeof httpClientHandlers.requestErrorCallback === "function") {
|
|
3642
|
+
await httpClientHandlers.requestErrorCallback(error);
|
|
3643
|
+
}
|
|
3644
|
+
if (typeof httpClientHandlers.requestFinishCallback === "function") {
|
|
3645
|
+
httpClientHandlers.requestFinishCallback();
|
|
3646
|
+
}
|
|
3647
|
+
}
|
|
3648
|
+
return Promise.reject(error);
|
|
3649
|
+
});
|
|
3616
3650
|
};
|
|
3617
|
-
const
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
)
|
|
3651
|
+
const enableHttpHandler = () => {
|
|
3652
|
+
const message = {
|
|
3653
|
+
type: ENABLE_HTTP_HANDLER
|
|
3654
|
+
};
|
|
3655
|
+
return communicate(message).then(() => {
|
|
3656
|
+
_isHttpHandlerEnabled = true;
|
|
3657
|
+
return Promise.resolve(true);
|
|
3658
|
+
}).catch((error) => {
|
|
3659
|
+
return Promise.reject(error);
|
|
3660
|
+
});
|
|
3625
3661
|
};
|
|
3626
|
-
const
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
)
|
|
3662
|
+
const disableHttpHandler = () => {
|
|
3663
|
+
const message = {
|
|
3664
|
+
type: DISABLE_HTTP_HANDLER
|
|
3665
|
+
};
|
|
3666
|
+
return communicate(message).then(() => {
|
|
3667
|
+
_isHttpHandlerEnabled = false;
|
|
3668
|
+
return Promise.resolve(true);
|
|
3669
|
+
}).catch((error) => {
|
|
3670
|
+
return Promise.reject(error);
|
|
3671
|
+
});
|
|
3634
3672
|
};
|
|
3635
|
-
const
|
|
3636
|
-
|
|
3673
|
+
const initialize = () => {
|
|
3674
|
+
if (!httpClientHandlers) {
|
|
3675
|
+
httpClientHandlers = {
|
|
3676
|
+
requestErrorCallback: () => Promise.resolve(),
|
|
3677
|
+
requestFinishCallback: () => null,
|
|
3678
|
+
requestStartCallback: () => null,
|
|
3679
|
+
requestSuccessCallback: () => null
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3682
|
+
worker.onmessage = ({ data }) => {
|
|
3683
|
+
switch (data.type) {
|
|
3684
|
+
case REQUEST_FINISH:
|
|
3685
|
+
httpClientHandlers?.requestFinishCallback && httpClientHandlers?.requestFinishCallback();
|
|
3686
|
+
break;
|
|
3687
|
+
case REQUEST_START:
|
|
3688
|
+
httpClientHandlers?.requestStartCallback && httpClientHandlers?.requestStartCallback();
|
|
3689
|
+
break;
|
|
3690
|
+
case REQUEST_SUCCESS:
|
|
3691
|
+
httpClientHandlers?.requestSuccessCallback && httpClientHandlers?.requestSuccessCallback(data.data ? JSON.parse(data.data) : null);
|
|
3692
|
+
break;
|
|
3693
|
+
}
|
|
3694
|
+
};
|
|
3695
|
+
const message = {
|
|
3696
|
+
data: config,
|
|
3697
|
+
type: INIT
|
|
3698
|
+
};
|
|
3699
|
+
return communicate(message).then(() => {
|
|
3700
|
+
return Promise.resolve(true);
|
|
3701
|
+
}).catch((error) => {
|
|
3702
|
+
return Promise.reject(error);
|
|
3703
|
+
});
|
|
3637
3704
|
};
|
|
3638
|
-
const
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3705
|
+
const setSessionState = (sessionState) => {
|
|
3706
|
+
const message = {
|
|
3707
|
+
data: sessionState,
|
|
3708
|
+
type: SET_SESSION_STATE
|
|
3709
|
+
};
|
|
3710
|
+
return communicate(message);
|
|
3642
3711
|
};
|
|
3643
|
-
const
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3712
|
+
const startAutoRefreshToken = () => {
|
|
3713
|
+
const message = {
|
|
3714
|
+
type: START_AUTO_REFRESH_TOKEN
|
|
3715
|
+
};
|
|
3716
|
+
return communicate(message);
|
|
3647
3717
|
};
|
|
3648
3718
|
const checkSession = async () => {
|
|
3649
|
-
const oidcEndpoints = await
|
|
3650
|
-
const config2 = await
|
|
3719
|
+
const oidcEndpoints = await getOpenIDProviderEndpoints();
|
|
3720
|
+
const config2 = await getConfigData();
|
|
3651
3721
|
_authenticationHelper.initializeSessionManger(
|
|
3652
3722
|
config2,
|
|
3653
3723
|
oidcEndpoints,
|
|
3654
|
-
async () => (await _authenticationClient.
|
|
3655
|
-
async (params) =>
|
|
3724
|
+
async () => (await _authenticationClient.getUserSession()).sessionState,
|
|
3725
|
+
async (params) => (await getSignInUrl(params)).authorizationURL,
|
|
3656
3726
|
_sessionManagementHelper
|
|
3657
3727
|
);
|
|
3658
3728
|
};
|
|
3729
|
+
const constructSilentSignInUrl = async (additionalParams = {}) => {
|
|
3730
|
+
const config2 = await getConfigData();
|
|
3731
|
+
const message = {
|
|
3732
|
+
data: {
|
|
3733
|
+
prompt: "none",
|
|
3734
|
+
state: SILENT_SIGN_IN_STATE,
|
|
3735
|
+
...additionalParams
|
|
3736
|
+
},
|
|
3737
|
+
type: GET_AUTH_URL
|
|
3738
|
+
};
|
|
3739
|
+
const response = await communicate(
|
|
3740
|
+
message
|
|
3741
|
+
);
|
|
3742
|
+
const pkceKey = extractPkceStorageKeyFromState3(
|
|
3743
|
+
new URL(response.authorizationURL).searchParams.get(OIDCRequestConstants4.Params.STATE) ?? ""
|
|
3744
|
+
);
|
|
3745
|
+
response.pkce && config2.enablePKCE && SPAUtils.setPKCE(pkceKey, response.pkce);
|
|
3746
|
+
const urlString = response.authorizationURL;
|
|
3747
|
+
const urlObject = new URL(urlString);
|
|
3748
|
+
urlObject.searchParams.set("response_mode", "query");
|
|
3749
|
+
const url = urlObject.toString();
|
|
3750
|
+
return url;
|
|
3751
|
+
};
|
|
3752
|
+
const trySignInSilently = async (additionalParams, tokenRequestConfig) => {
|
|
3753
|
+
return await _authenticationHelper.trySignInSilently(
|
|
3754
|
+
constructSilentSignInUrl,
|
|
3755
|
+
requestAccessToken,
|
|
3756
|
+
_sessionManagementHelper,
|
|
3757
|
+
additionalParams,
|
|
3758
|
+
tokenRequestConfig
|
|
3759
|
+
);
|
|
3760
|
+
};
|
|
3761
|
+
const getSignInUrl = async (params) => {
|
|
3762
|
+
const config2 = await getConfigData();
|
|
3763
|
+
const message = {
|
|
3764
|
+
data: params,
|
|
3765
|
+
type: GET_AUTH_URL
|
|
3766
|
+
};
|
|
3767
|
+
return communicate(message).then(
|
|
3768
|
+
async (response) => {
|
|
3769
|
+
if (response.pkce && config2.enablePKCE) {
|
|
3770
|
+
const pkceKey = extractPkceStorageKeyFromState3(
|
|
3771
|
+
new URL(response.authorizationURL).searchParams.get(OIDCRequestConstants4.Params.STATE) ?? ""
|
|
3772
|
+
);
|
|
3773
|
+
SPAUtils.setPKCE(pkceKey, response.pkce);
|
|
3774
|
+
}
|
|
3775
|
+
return Promise.resolve(response);
|
|
3776
|
+
}
|
|
3777
|
+
);
|
|
3778
|
+
};
|
|
3779
|
+
const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
|
|
3780
|
+
const config2 = await getConfigData();
|
|
3781
|
+
const pkceKey = extractPkceStorageKeyFromState3(resolvedState);
|
|
3782
|
+
const message = {
|
|
3783
|
+
data: {
|
|
3784
|
+
code: resolvedAuthorizationCode,
|
|
3785
|
+
pkce: config2.enablePKCE ? SPAUtils.getPKCE(pkceKey) : void 0,
|
|
3786
|
+
sessionState: resolvedSessionState,
|
|
3787
|
+
state: resolvedState,
|
|
3788
|
+
tokenRequestConfig
|
|
3789
|
+
},
|
|
3790
|
+
type: REQUEST_ACCESS_TOKEN
|
|
3791
|
+
};
|
|
3792
|
+
config2.enablePKCE && SPAUtils.removePKCE(pkceKey);
|
|
3793
|
+
return communicate(message).then((response) => {
|
|
3794
|
+
const message2 = {
|
|
3795
|
+
type: GET_SIGN_OUT_URL
|
|
3796
|
+
};
|
|
3797
|
+
return communicate(message2).then((url) => {
|
|
3798
|
+
SPAUtils.setSignOutURL(url, config2.clientId, instanceID);
|
|
3799
|
+
if (config2.enableOIDCSessionManagement) {
|
|
3800
|
+
checkSession();
|
|
3801
|
+
}
|
|
3802
|
+
startAutoRefreshToken();
|
|
3803
|
+
return Promise.resolve(response);
|
|
3804
|
+
}).catch((error) => {
|
|
3805
|
+
return Promise.reject(error);
|
|
3806
|
+
});
|
|
3807
|
+
}).catch((error) => {
|
|
3808
|
+
return Promise.reject(error);
|
|
3809
|
+
});
|
|
3810
|
+
};
|
|
3659
3811
|
const shouldStopAuthn = async () => {
|
|
3660
3812
|
return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
|
|
3661
|
-
|
|
3662
|
-
OIDCRequestConstants4.Params.SESSION_STATE,
|
|
3663
|
-
sessionState ?? ""
|
|
3664
|
-
);
|
|
3665
|
-
return;
|
|
3813
|
+
return setSessionState(sessionState);
|
|
3666
3814
|
});
|
|
3667
3815
|
};
|
|
3668
|
-
const
|
|
3669
|
-
await
|
|
3816
|
+
const tryRetrievingUserInfo = async () => {
|
|
3817
|
+
if (await isSignedIn()) {
|
|
3818
|
+
await startAutoRefreshToken();
|
|
3819
|
+
if (config.enableOIDCSessionManagement) {
|
|
3820
|
+
checkSession();
|
|
3821
|
+
}
|
|
3822
|
+
return getUser();
|
|
3823
|
+
}
|
|
3824
|
+
return Promise.resolve(void 0);
|
|
3670
3825
|
};
|
|
3671
|
-
const signIn = async (
|
|
3672
|
-
const basicUserInfo = await _authenticationHelper.handleSignIn(
|
|
3826
|
+
const signIn = async (params, authorizationCode, sessionState, state, tokenRequestConfig) => {
|
|
3827
|
+
const basicUserInfo = await _authenticationHelper.handleSignIn(
|
|
3828
|
+
shouldStopAuthn,
|
|
3829
|
+
checkSession,
|
|
3830
|
+
tryRetrievingUserInfo
|
|
3831
|
+
);
|
|
3673
3832
|
if (basicUserInfo) {
|
|
3674
3833
|
return basicUserInfo;
|
|
3675
3834
|
} else {
|
|
3676
3835
|
let resolvedAuthorizationCode;
|
|
3677
3836
|
let resolvedSessionState;
|
|
3678
3837
|
let resolvedState;
|
|
3679
|
-
|
|
3680
|
-
if (config?.responseMode === ResponseMode.FormPost && authorizationCode) {
|
|
3838
|
+
if (config?.responseMode === "form_post" && authorizationCode) {
|
|
3681
3839
|
resolvedAuthorizationCode = authorizationCode;
|
|
3682
3840
|
resolvedSessionState = sessionState ?? "";
|
|
3683
3841
|
resolvedState = state ?? "";
|
|
@@ -3688,27 +3846,10 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
|
3688
3846
|
SPAUtils.removeAuthorizationCode();
|
|
3689
3847
|
}
|
|
3690
3848
|
if (resolvedAuthorizationCode && resolvedState) {
|
|
3691
|
-
|
|
3692
|
-
const storedTokenRequestConfig = await _dataLayer.getTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY);
|
|
3693
|
-
if (storedTokenRequestConfig && typeof storedTokenRequestConfig === "string") {
|
|
3694
|
-
resolvedTokenRequestConfig = JSON.parse(storedTokenRequestConfig);
|
|
3695
|
-
}
|
|
3696
|
-
return requestAccessToken(
|
|
3697
|
-
resolvedAuthorizationCode,
|
|
3698
|
-
resolvedSessionState,
|
|
3699
|
-
resolvedState,
|
|
3700
|
-
resolvedTokenRequestConfig
|
|
3701
|
-
);
|
|
3849
|
+
return requestAccessToken(resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig);
|
|
3702
3850
|
}
|
|
3703
|
-
return
|
|
3704
|
-
|
|
3705
|
-
const pkceKey = extractPkceStorageKeyFromState2(resolvedState);
|
|
3706
|
-
SPAUtils.setPKCE(pkceKey, await _authenticationClient.getPKCECode(resolvedState));
|
|
3707
|
-
}
|
|
3708
|
-
if (tokenRequestConfig) {
|
|
3709
|
-
_dataLayer.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
|
|
3710
|
-
}
|
|
3711
|
-
location.href = url;
|
|
3851
|
+
return getSignInUrl(params).then(async (response) => {
|
|
3852
|
+
location.href = response.authorizationURL;
|
|
3712
3853
|
await SPAUtils.waitTillPageRedirect();
|
|
3713
3854
|
return Promise.resolve({
|
|
3714
3855
|
allowedScopes: "",
|
|
@@ -3719,119 +3860,158 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
|
3719
3860
|
tenantDomain: "",
|
|
3720
3861
|
username: ""
|
|
3721
3862
|
});
|
|
3863
|
+
}).catch((error) => {
|
|
3864
|
+
return Promise.reject(error);
|
|
3722
3865
|
});
|
|
3723
3866
|
}
|
|
3724
3867
|
};
|
|
3725
|
-
const signOut =
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
return await _authenticationHelper.requestCustomGrant(config2, enableRetrievingSignOutURLFromSession);
|
|
3746
|
-
};
|
|
3747
|
-
const refreshAccessToken = async () => {
|
|
3748
|
-
try {
|
|
3749
|
-
return await _authenticationHelper.refreshAccessToken(enableRetrievingSignOutURLFromSession);
|
|
3750
|
-
} catch (error) {
|
|
3751
|
-
return Promise.reject(error);
|
|
3752
|
-
}
|
|
3868
|
+
const signOut = () => {
|
|
3869
|
+
return new Promise((resolve, reject) => {
|
|
3870
|
+
if (!_getSignOutURLFromSessionStorage) {
|
|
3871
|
+
const message = {
|
|
3872
|
+
type: SIGN_OUT
|
|
3873
|
+
};
|
|
3874
|
+
return communicate(message).then(async (response) => {
|
|
3875
|
+
window.location.href = response;
|
|
3876
|
+
await SPAUtils.waitTillPageRedirect();
|
|
3877
|
+
return resolve(true);
|
|
3878
|
+
}).catch((error) => {
|
|
3879
|
+
return reject(error);
|
|
3880
|
+
});
|
|
3881
|
+
} else {
|
|
3882
|
+
window.location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
|
|
3883
|
+
return SPAUtils.waitTillPageRedirect().then(() => {
|
|
3884
|
+
return Promise.resolve(true);
|
|
3885
|
+
});
|
|
3886
|
+
}
|
|
3887
|
+
});
|
|
3753
3888
|
};
|
|
3754
|
-
const revokeAccessToken =
|
|
3755
|
-
const
|
|
3756
|
-
|
|
3889
|
+
const revokeAccessToken = () => {
|
|
3890
|
+
const message = {
|
|
3891
|
+
type: REVOKE_ACCESS_TOKEN
|
|
3892
|
+
};
|
|
3893
|
+
return communicate(message).then((response) => {
|
|
3757
3894
|
_sessionManagementHelper.reset();
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3895
|
+
return Promise.resolve(response);
|
|
3896
|
+
}).catch((error) => {
|
|
3897
|
+
return Promise.reject(error);
|
|
3898
|
+
});
|
|
3761
3899
|
};
|
|
3762
|
-
const
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
);
|
|
3900
|
+
const getOpenIDProviderEndpoints = () => {
|
|
3901
|
+
const message = {
|
|
3902
|
+
type: GET_OIDC_SERVICE_ENDPOINTS
|
|
3903
|
+
};
|
|
3904
|
+
return communicate(message).then((response) => {
|
|
3905
|
+
return Promise.resolve(response);
|
|
3906
|
+
}).catch((error) => {
|
|
3907
|
+
return Promise.reject(error);
|
|
3908
|
+
});
|
|
3771
3909
|
};
|
|
3772
|
-
const
|
|
3773
|
-
const
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3910
|
+
const getConfigData = () => {
|
|
3911
|
+
const message = {
|
|
3912
|
+
type: GET_CONFIG_DATA
|
|
3913
|
+
};
|
|
3914
|
+
return communicate(message).then((response) => {
|
|
3915
|
+
return Promise.resolve(response);
|
|
3916
|
+
}).catch((error) => {
|
|
3917
|
+
return Promise.reject(error);
|
|
3778
3918
|
});
|
|
3779
|
-
const urlObject = new URL(urlString);
|
|
3780
|
-
urlObject.searchParams.set("response_mode", "query");
|
|
3781
|
-
const url = urlObject.toString();
|
|
3782
|
-
if (config2.storage === "browserMemory" /* BrowserMemory */ && config2.enablePKCE) {
|
|
3783
|
-
const state = urlObject.searchParams.get(OIDCRequestConstants4.Params.STATE);
|
|
3784
|
-
SPAUtils.setPKCE(
|
|
3785
|
-
extractPkceStorageKeyFromState2(state ?? ""),
|
|
3786
|
-
await _authenticationClient.getPKCECode(state ?? "")
|
|
3787
|
-
);
|
|
3788
|
-
}
|
|
3789
|
-
return url;
|
|
3790
3919
|
};
|
|
3791
|
-
const
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3920
|
+
const getUser = () => {
|
|
3921
|
+
const message = {
|
|
3922
|
+
type: GET_BASIC_USER_INFO
|
|
3923
|
+
};
|
|
3924
|
+
return communicate(message).then((response) => {
|
|
3925
|
+
return Promise.resolve(response);
|
|
3926
|
+
}).catch((error) => {
|
|
3927
|
+
return Promise.reject(error);
|
|
3928
|
+
});
|
|
3799
3929
|
};
|
|
3800
|
-
const
|
|
3801
|
-
|
|
3930
|
+
const getDecodedIdToken = () => {
|
|
3931
|
+
const message = {
|
|
3932
|
+
type: GET_DECODED_ID_TOKEN
|
|
3933
|
+
};
|
|
3934
|
+
return communicate(message).then((response) => {
|
|
3935
|
+
return Promise.resolve(response);
|
|
3936
|
+
}).catch((error) => {
|
|
3937
|
+
return Promise.reject(error);
|
|
3938
|
+
});
|
|
3802
3939
|
};
|
|
3803
|
-
const
|
|
3804
|
-
|
|
3940
|
+
const getDecodedIDPIDToken = () => {
|
|
3941
|
+
const message = {
|
|
3942
|
+
type: GET_DECODED_IDP_ID_TOKEN
|
|
3943
|
+
};
|
|
3944
|
+
return communicate(message).then((response) => {
|
|
3945
|
+
return Promise.resolve(response);
|
|
3946
|
+
}).catch((error) => {
|
|
3947
|
+
return Promise.reject(error);
|
|
3948
|
+
});
|
|
3805
3949
|
};
|
|
3806
|
-
const
|
|
3807
|
-
|
|
3950
|
+
const getCrypto = () => {
|
|
3951
|
+
const message = {
|
|
3952
|
+
type: GET_CRYPTO_HELPER
|
|
3953
|
+
};
|
|
3954
|
+
return communicate(message).then((response) => {
|
|
3955
|
+
return Promise.resolve(response);
|
|
3956
|
+
}).catch((error) => {
|
|
3957
|
+
return Promise.reject(error);
|
|
3958
|
+
});
|
|
3808
3959
|
};
|
|
3809
|
-
const
|
|
3810
|
-
|
|
3960
|
+
const getIdToken = () => {
|
|
3961
|
+
const message = {
|
|
3962
|
+
type: GET_ID_TOKEN
|
|
3963
|
+
};
|
|
3964
|
+
return communicate(message).then((response) => {
|
|
3965
|
+
return Promise.resolve(response);
|
|
3966
|
+
}).catch((error) => {
|
|
3967
|
+
return Promise.reject(error);
|
|
3968
|
+
});
|
|
3811
3969
|
};
|
|
3812
|
-
const
|
|
3813
|
-
|
|
3970
|
+
const isSignedIn = () => {
|
|
3971
|
+
const message = {
|
|
3972
|
+
type: IS_AUTHENTICATED
|
|
3973
|
+
};
|
|
3974
|
+
return communicate(message).then((response) => {
|
|
3975
|
+
return Promise.resolve(response);
|
|
3976
|
+
}).catch((error) => {
|
|
3977
|
+
return Promise.reject(error);
|
|
3978
|
+
});
|
|
3814
3979
|
};
|
|
3815
|
-
const
|
|
3816
|
-
|
|
3980
|
+
const refreshAccessToken = () => {
|
|
3981
|
+
const message = {
|
|
3982
|
+
type: REFRESH_ACCESS_TOKEN
|
|
3983
|
+
};
|
|
3984
|
+
return communicate(message);
|
|
3817
3985
|
};
|
|
3818
|
-
const
|
|
3819
|
-
|
|
3986
|
+
const setHttpRequestSuccessCallback = (callback) => {
|
|
3987
|
+
if (callback && typeof callback === "function") {
|
|
3988
|
+
httpClientHandlers.requestSuccessCallback = callback;
|
|
3989
|
+
}
|
|
3820
3990
|
};
|
|
3821
|
-
const
|
|
3822
|
-
|
|
3991
|
+
const setHttpRequestErrorCallback = (callback) => {
|
|
3992
|
+
if (callback && typeof callback === "function") {
|
|
3993
|
+
httpClientHandlers.requestErrorCallback = callback;
|
|
3994
|
+
}
|
|
3823
3995
|
};
|
|
3824
|
-
const
|
|
3825
|
-
|
|
3996
|
+
const setHttpRequestStartCallback = (callback) => {
|
|
3997
|
+
if (callback && typeof callback === "function") {
|
|
3998
|
+
httpClientHandlers.requestStartCallback = callback;
|
|
3999
|
+
}
|
|
3826
4000
|
};
|
|
3827
|
-
const
|
|
3828
|
-
|
|
4001
|
+
const setHttpRequestFinishCallback = (callback) => {
|
|
4002
|
+
if (callback && typeof callback === "function") {
|
|
4003
|
+
httpClientHandlers.requestFinishCallback = callback;
|
|
4004
|
+
}
|
|
3829
4005
|
};
|
|
3830
|
-
const
|
|
3831
|
-
const existingConfig = await
|
|
4006
|
+
const reInitialize = async (newConfig) => {
|
|
4007
|
+
const existingConfig = await getConfigData();
|
|
3832
4008
|
const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
|
|
3833
4009
|
const config2 = { ...existingConfig, ...newConfig };
|
|
3834
|
-
|
|
4010
|
+
const message = {
|
|
4011
|
+
data: config2,
|
|
4012
|
+
type: UPDATE_CONFIG
|
|
4013
|
+
};
|
|
4014
|
+
await communicate(message);
|
|
3835
4015
|
if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
|
|
3836
4016
|
_sessionManagementHelper.reset();
|
|
3837
4017
|
checkSession();
|
|
@@ -3840,21 +4020,19 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
|
3840
4020
|
return {
|
|
3841
4021
|
disableHttpHandler,
|
|
3842
4022
|
enableHttpHandler,
|
|
3843
|
-
|
|
3844
|
-
getBasicUserInfo,
|
|
4023
|
+
getUser,
|
|
3845
4024
|
getConfigData,
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
getOIDCServiceEndpoints,
|
|
4025
|
+
getCrypto,
|
|
4026
|
+
getDecodedIDPIDToken,
|
|
4027
|
+
getDecodedIdToken,
|
|
4028
|
+
getIdToken,
|
|
4029
|
+
getOpenIDProviderEndpoints,
|
|
3852
4030
|
httpRequest,
|
|
3853
4031
|
httpRequestAll,
|
|
3854
|
-
|
|
3855
|
-
|
|
4032
|
+
initialize,
|
|
4033
|
+
isSignedIn,
|
|
3856
4034
|
refreshAccessToken,
|
|
3857
|
-
|
|
4035
|
+
exchangeToken,
|
|
3858
4036
|
revokeAccessToken,
|
|
3859
4037
|
setHttpRequestErrorCallback,
|
|
3860
4038
|
setHttpRequestFinishCallback,
|
|
@@ -3863,1044 +4041,509 @@ var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
|
3863
4041
|
signIn,
|
|
3864
4042
|
signOut,
|
|
3865
4043
|
trySignInSilently,
|
|
3866
|
-
|
|
4044
|
+
reInitialize
|
|
3867
4045
|
};
|
|
3868
4046
|
};
|
|
3869
4047
|
|
|
3870
|
-
// src/__legacy__/
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
var initiateStore2 = (store) => {
|
|
3879
|
-
switch (store) {
|
|
3880
|
-
case "localStorage" /* LocalStorage */:
|
|
3881
|
-
return new LocalStore();
|
|
3882
|
-
case "sessionStorage" /* SessionStorage */:
|
|
3883
|
-
return new SessionStore();
|
|
3884
|
-
case "browserMemory" /* BrowserMemory */:
|
|
3885
|
-
return new MemoryStore();
|
|
3886
|
-
default:
|
|
3887
|
-
return new SessionStore();
|
|
3888
|
-
}
|
|
4048
|
+
// src/__legacy__/client.ts
|
|
4049
|
+
var DefaultConfig = {
|
|
4050
|
+
autoLogoutOnTokenRefreshError: true,
|
|
4051
|
+
checkSessionInterval: 3,
|
|
4052
|
+
enableOIDCSessionManagement: false,
|
|
4053
|
+
periodicTokenRefresh: false,
|
|
4054
|
+
sessionRefreshInterval: 300,
|
|
4055
|
+
storage: "sessionStorage" /* SessionStorage */
|
|
3889
4056
|
};
|
|
3890
|
-
var
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
}
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
return
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
const responseData = data?.data ? JSON.parse(data?.data) : null;
|
|
3939
|
-
if (data?.blob) {
|
|
3940
|
-
responseData.data = data?.blob;
|
|
3941
|
-
}
|
|
3942
|
-
resolve(responseData);
|
|
3943
|
-
} else {
|
|
3944
|
-
reject(data.error ? JSON.parse(data.error) : null);
|
|
3945
|
-
}
|
|
3946
|
-
};
|
|
3947
|
-
});
|
|
3948
|
-
};
|
|
3949
|
-
const requestCustomGrant = (requestParams) => {
|
|
3950
|
-
const message = {
|
|
3951
|
-
data: requestParams,
|
|
3952
|
-
type: REQUEST_CUSTOM_GRANT
|
|
4057
|
+
var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
4058
|
+
constructor(id) {
|
|
4059
|
+
__publicField(this, "_client");
|
|
4060
|
+
__publicField(this, "_storage");
|
|
4061
|
+
__publicField(this, "_authHelper", AuthenticationHelper);
|
|
4062
|
+
// protected _worker: new () => Worker = WorkerFile;
|
|
4063
|
+
__publicField(this, "_worker", null);
|
|
4064
|
+
__publicField(this, "_initialized", false);
|
|
4065
|
+
__publicField(this, "_startedInitialize", false);
|
|
4066
|
+
__publicField(this, "_onSignInCallback", () => null);
|
|
4067
|
+
__publicField(this, "_onSignOutCallback", () => null);
|
|
4068
|
+
__publicField(this, "_onSignOutFailedCallback", () => null);
|
|
4069
|
+
__publicField(this, "_onEndUserSession", () => null);
|
|
4070
|
+
__publicField(this, "_onInitialize", () => null);
|
|
4071
|
+
__publicField(this, "_onCustomGrant", /* @__PURE__ */ new Map());
|
|
4072
|
+
__publicField(this, "_instanceID");
|
|
4073
|
+
this._instanceID = id;
|
|
4074
|
+
}
|
|
4075
|
+
instantiateAuthHelper(authHelper) {
|
|
4076
|
+
if (authHelper) {
|
|
4077
|
+
this._authHelper = authHelper;
|
|
4078
|
+
} else {
|
|
4079
|
+
this._authHelper = AuthenticationHelper;
|
|
4080
|
+
}
|
|
4081
|
+
}
|
|
4082
|
+
// public instantiateWorker(worker: new () => Worker) {
|
|
4083
|
+
// if (worker) {
|
|
4084
|
+
// this._worker = worker;
|
|
4085
|
+
// } else {
|
|
4086
|
+
// this._worker = WorkerFile;
|
|
4087
|
+
// }
|
|
4088
|
+
// }
|
|
4089
|
+
/**
|
|
4090
|
+
* This method specifies if the `AsgardeoSPAClient` has been initialized or not.
|
|
4091
|
+
*
|
|
4092
|
+
* @return {Promise<boolean>} - Resolves to `true` if the client has been initialized.
|
|
4093
|
+
*
|
|
4094
|
+
* @memberof AsgardeoSPAClient
|
|
4095
|
+
*
|
|
4096
|
+
* @private
|
|
4097
|
+
*/
|
|
4098
|
+
async isInitialized() {
|
|
4099
|
+
if (!this._startedInitialize) {
|
|
4100
|
+
return false;
|
|
4101
|
+
}
|
|
4102
|
+
let iterationToWait = 0;
|
|
4103
|
+
const sleep = () => {
|
|
4104
|
+
return new Promise((resolve) => setTimeout(resolve, 1));
|
|
3953
4105
|
};
|
|
3954
|
-
|
|
3955
|
-
if (
|
|
3956
|
-
|
|
4106
|
+
while (!this._initialized) {
|
|
4107
|
+
if (iterationToWait === 1e4) {
|
|
4108
|
+
console.warn("It is taking longer than usual for the object to be initialized");
|
|
3957
4109
|
}
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
return Promise.reject(error);
|
|
3961
|
-
});
|
|
3962
|
-
};
|
|
3963
|
-
const httpRequest = (config2) => {
|
|
3964
|
-
if (config2?.data && config2?.data instanceof FormData) {
|
|
3965
|
-
config2.data = { ...Object.fromEntries((config2?.data).entries()), formData: true };
|
|
4110
|
+
await sleep();
|
|
4111
|
+
iterationToWait++;
|
|
3966
4112
|
}
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
4113
|
+
return true;
|
|
4114
|
+
}
|
|
4115
|
+
/**
|
|
4116
|
+
* This method checks if the SDK is initialized and the user is authenticated.
|
|
4117
|
+
*
|
|
4118
|
+
* @param validateAuthentication - should user's authenticated status be checked as part of validation
|
|
4119
|
+
*
|
|
4120
|
+
* @return {Promise<boolean>} - A Promise that resolves with `true` if the SDK is initialized and the
|
|
4121
|
+
* user is authenticated.
|
|
4122
|
+
*
|
|
4123
|
+
* @memberof AsgardeoSPAClient
|
|
4124
|
+
*
|
|
4125
|
+
* @private
|
|
4126
|
+
*/
|
|
4127
|
+
async _validateMethod(validateAuthentication = true) {
|
|
4128
|
+
if (!await this.isInitialized()) {
|
|
4129
|
+
return Promise.reject(
|
|
4130
|
+
new AsgardeoAuthException4(
|
|
4131
|
+
"SPA-AUTH_CLIENT-VM-NF01",
|
|
4132
|
+
"The SDK is not initialized.",
|
|
4133
|
+
"The SDK must be initialized first."
|
|
4134
|
+
)
|
|
4135
|
+
);
|
|
4136
|
+
}
|
|
4137
|
+
if (validateAuthentication && !await this.isSignedIn()) {
|
|
4138
|
+
return Promise.reject(
|
|
4139
|
+
new AsgardeoAuthException4(
|
|
4140
|
+
"SPA-AUTH_CLIENT-VM-IV02",
|
|
4141
|
+
"The user is not authenticated.",
|
|
4142
|
+
"The user must be authenticated first."
|
|
4143
|
+
)
|
|
4144
|
+
);
|
|
4145
|
+
}
|
|
4146
|
+
return true;
|
|
4147
|
+
}
|
|
4148
|
+
/**
|
|
4149
|
+
* This method returns the instance of the singleton class.
|
|
4150
|
+
* If an ID is provided, it will return the instance with the given ID.
|
|
4151
|
+
* If no ID is provided, it will return the default instance value 0.
|
|
4152
|
+
*
|
|
4153
|
+
* @return {AsgardeoSPAClient} - Returns the instance of the singleton class.
|
|
4154
|
+
*
|
|
4155
|
+
* @example
|
|
4156
|
+
* ```
|
|
4157
|
+
* const auth = AsgardeoSPAClient.getInstance();
|
|
4158
|
+
* ```
|
|
4159
|
+
*
|
|
4160
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getinstance
|
|
4161
|
+
*
|
|
4162
|
+
* @memberof AsgardeoSPAClient
|
|
4163
|
+
*
|
|
4164
|
+
* @preserve
|
|
4165
|
+
*/
|
|
4166
|
+
static getInstance(id) {
|
|
4167
|
+
if (id && this._instances?.get(id)) {
|
|
4168
|
+
return this._instances.get(id);
|
|
4169
|
+
} else if (!id && this._instances?.get(0)) {
|
|
4170
|
+
return this._instances.get(0);
|
|
4171
|
+
}
|
|
4172
|
+
if (id) {
|
|
4173
|
+
this._instances.set(id, new _AsgardeoSPAClient(id));
|
|
4174
|
+
return this._instances.get(id);
|
|
4175
|
+
}
|
|
4176
|
+
this._instances.set(0, new _AsgardeoSPAClient(0));
|
|
4177
|
+
return this._instances.get(0);
|
|
4178
|
+
}
|
|
4179
|
+
/**
|
|
4180
|
+
* This method initializes the `AsgardeoSPAClient` instance.
|
|
4181
|
+
*
|
|
4182
|
+
* @param {ConfigInterface} config The config object to initialize with.
|
|
4183
|
+
*
|
|
4184
|
+
* @return {Promise<boolean>} - Resolves to `true` if initialization is successful.
|
|
4185
|
+
*
|
|
4186
|
+
* @example
|
|
4187
|
+
* ```
|
|
4188
|
+
* auth.initialize({
|
|
4189
|
+
* afterSignInUrl: "http://localhost:3000/sign-in",
|
|
4190
|
+
* clientId: "client ID",
|
|
4191
|
+
* baseUrl: "https://api.asgardeo.io"
|
|
4192
|
+
* });
|
|
4193
|
+
* ```
|
|
4194
|
+
*
|
|
4195
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#initialize
|
|
4196
|
+
*
|
|
4197
|
+
* @memberof AsgardeoSPAClient
|
|
4198
|
+
*
|
|
4199
|
+
* @preserve
|
|
4200
|
+
*/
|
|
4201
|
+
async initialize(config, authHelper, workerFile) {
|
|
4202
|
+
this._storage = config.storage ?? "sessionStorage" /* SessionStorage */;
|
|
4203
|
+
this._initialized = false;
|
|
4204
|
+
this._startedInitialize = true;
|
|
4205
|
+
authHelper && this.instantiateAuthHelper(authHelper);
|
|
4206
|
+
const _config = await this._client?.getConfigData();
|
|
4207
|
+
if (!(this._storage === "webWorker" /* WebWorker */)) {
|
|
4208
|
+
const mainThreadClientConfig = config;
|
|
4209
|
+
const defaultConfig = { ...DefaultConfig };
|
|
4210
|
+
const mergedConfig = {
|
|
4211
|
+
...defaultConfig,
|
|
4212
|
+
...mainThreadClientConfig
|
|
4213
|
+
};
|
|
4214
|
+
if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
|
|
4215
|
+
this._client = await MainThreadClient(
|
|
4216
|
+
this._instanceID,
|
|
4217
|
+
mergedConfig,
|
|
4218
|
+
(authClient, spaHelper) => {
|
|
4219
|
+
return new this._authHelper(authClient, spaHelper);
|
|
4220
|
+
}
|
|
4221
|
+
);
|
|
3981
4222
|
}
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
const httpRequestAll = (configs) => {
|
|
3986
|
-
const message = {
|
|
3987
|
-
data: configs,
|
|
3988
|
-
type: HTTP_REQUEST_ALL
|
|
3989
|
-
};
|
|
3990
|
-
return communicate(message).then((response) => {
|
|
3991
|
-
return Promise.resolve(response);
|
|
3992
|
-
}).catch(async (error) => {
|
|
3993
|
-
if (_isHttpHandlerEnabled) {
|
|
3994
|
-
if (typeof httpClientHandlers.requestErrorCallback === "function") {
|
|
3995
|
-
await httpClientHandlers.requestErrorCallback(error);
|
|
3996
|
-
}
|
|
3997
|
-
if (typeof httpClientHandlers.requestFinishCallback === "function") {
|
|
3998
|
-
httpClientHandlers.requestFinishCallback();
|
|
3999
|
-
}
|
|
4223
|
+
this._initialized = true;
|
|
4224
|
+
if (this._onInitialize) {
|
|
4225
|
+
this._onInitialize(true);
|
|
4000
4226
|
}
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
_isHttpHandlerEnabled = true;
|
|
4010
|
-
return Promise.resolve(true);
|
|
4011
|
-
}).catch((error) => {
|
|
4012
|
-
return Promise.reject(error);
|
|
4013
|
-
});
|
|
4014
|
-
};
|
|
4015
|
-
const disableHttpHandler = () => {
|
|
4016
|
-
const message = {
|
|
4017
|
-
type: DISABLE_HTTP_HANDLER
|
|
4018
|
-
};
|
|
4019
|
-
return communicate(message).then(() => {
|
|
4020
|
-
_isHttpHandlerEnabled = false;
|
|
4227
|
+
if (!mergedConfig.autoLogoutOnTokenRefreshError) {
|
|
4228
|
+
return Promise.resolve(true);
|
|
4229
|
+
}
|
|
4230
|
+
window.addEventListener("message", (event) => {
|
|
4231
|
+
if (event?.data?.type === REFRESH_ACCESS_TOKEN_ERR0R) {
|
|
4232
|
+
this.signOut();
|
|
4233
|
+
}
|
|
4234
|
+
});
|
|
4021
4235
|
return Promise.resolve(true);
|
|
4022
|
-
}
|
|
4023
|
-
|
|
4024
|
-
|
|
4025
|
-
|
|
4026
|
-
|
|
4027
|
-
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
4033
|
-
|
|
4034
|
-
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
break;
|
|
4236
|
+
} else {
|
|
4237
|
+
if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
|
|
4238
|
+
const webWorkerClientConfig = config;
|
|
4239
|
+
this._client = await WebWorkerClient(
|
|
4240
|
+
this._instanceID,
|
|
4241
|
+
{
|
|
4242
|
+
...DefaultConfig,
|
|
4243
|
+
...webWorkerClientConfig
|
|
4244
|
+
},
|
|
4245
|
+
this._worker,
|
|
4246
|
+
(authClient, spaHelper) => {
|
|
4247
|
+
return new this._authHelper(authClient, spaHelper);
|
|
4248
|
+
}
|
|
4249
|
+
);
|
|
4250
|
+
return this._client.initialize().then(() => {
|
|
4251
|
+
if (this._onInitialize) {
|
|
4252
|
+
this._onInitialize(true);
|
|
4253
|
+
}
|
|
4254
|
+
this._initialized = true;
|
|
4255
|
+
return Promise.resolve(true);
|
|
4256
|
+
}).catch((error) => {
|
|
4257
|
+
return Promise.reject(error);
|
|
4258
|
+
});
|
|
4046
4259
|
}
|
|
4047
|
-
};
|
|
4048
|
-
const message = {
|
|
4049
|
-
data: config,
|
|
4050
|
-
type: INIT
|
|
4051
|
-
};
|
|
4052
|
-
return communicate(message).then(() => {
|
|
4053
4260
|
return Promise.resolve(true);
|
|
4054
|
-
}
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4073
|
-
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
}
|
|
4126
|
-
return Promise.resolve(response);
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
/**
|
|
4264
|
+
* This method returns a Promise that resolves with the basic user information obtained from the ID token.
|
|
4265
|
+
*
|
|
4266
|
+
* @return {Promise<User>} - A promise that resolves with the user information.
|
|
4267
|
+
*
|
|
4268
|
+
* @example
|
|
4269
|
+
* ```
|
|
4270
|
+
* auth.getUser().then((response) => {
|
|
4271
|
+
* // console.log(response);
|
|
4272
|
+
* }).catch((error) => {
|
|
4273
|
+
* // console.error(error);
|
|
4274
|
+
* });
|
|
4275
|
+
* ```
|
|
4276
|
+
*
|
|
4277
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getuserinfo
|
|
4278
|
+
*
|
|
4279
|
+
* @memberof AsgardeoSPAClient
|
|
4280
|
+
*
|
|
4281
|
+
* @preserve
|
|
4282
|
+
*/
|
|
4283
|
+
async getUser() {
|
|
4284
|
+
await this._validateMethod();
|
|
4285
|
+
return this._client?.getUser();
|
|
4286
|
+
}
|
|
4287
|
+
/**
|
|
4288
|
+
* This method initiates the authentication flow. This should be called twice.
|
|
4289
|
+
* 1. To initiate the authentication flow.
|
|
4290
|
+
* 2. To obtain the access token after getting the authorization code.
|
|
4291
|
+
*
|
|
4292
|
+
* To satisfy the second condition, one of the two strategies mentioned below can be used:
|
|
4293
|
+
* 1. Redirect the user back to the same login page that initiated the authentication flow.
|
|
4294
|
+
* 2. Call the `signIn()` method in the page the user is redirected to after authentication.
|
|
4295
|
+
*
|
|
4296
|
+
* **To fire a callback function after signing in, use the `on()` method.**
|
|
4297
|
+
* **To learn more about the `on()` method:**
|
|
4298
|
+
* @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
|
|
4299
|
+
*
|
|
4300
|
+
* @param {SignInConfig} config - The sign-in config.
|
|
4301
|
+
* The `SignInConfig` object has these two attributes in addition to any custom key-value pairs.
|
|
4302
|
+
* 1. fidp - Specifies the FIDP parameter that is used to take the user directly to an IdP login page.
|
|
4303
|
+
* 2. forceInit: Specifies if the OIDC Provider Meta Data should be loaded again from the `well-known`
|
|
4304
|
+
* endpoint.
|
|
4305
|
+
* 3. Any other parameters that should be appended to the authorization request.
|
|
4306
|
+
* @param {string} authorizationCode - The authorization code. (Optional)
|
|
4307
|
+
* @param {string} sessionState - The session state. (Optional)
|
|
4308
|
+
* @param {string} state - The state. (Optional)
|
|
4309
|
+
*
|
|
4310
|
+
* @return {Promise<User>} - A promise that resolves with the user information.
|
|
4311
|
+
*
|
|
4312
|
+
* @example
|
|
4313
|
+
* ```
|
|
4314
|
+
* auth.signIn();
|
|
4315
|
+
* ```
|
|
4316
|
+
*
|
|
4317
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signin
|
|
4318
|
+
*
|
|
4319
|
+
* @memberof AsgardeoSPAClient
|
|
4320
|
+
*
|
|
4321
|
+
* @preserve
|
|
4322
|
+
*/
|
|
4323
|
+
async signIn(config, authorizationCode, sessionState, state, tokenRequestConfig) {
|
|
4324
|
+
await this.isInitialized();
|
|
4325
|
+
if (!SPAUtils.canContinueSignIn(Boolean(config?.callOnlyOnRedirect), authorizationCode)) {
|
|
4326
|
+
return void 0;
|
|
4327
|
+
}
|
|
4328
|
+
delete config?.callOnlyOnRedirect;
|
|
4329
|
+
return this._client?.signIn(config, authorizationCode, sessionState, state, tokenRequestConfig).then((response) => {
|
|
4330
|
+
if (this._onSignInCallback) {
|
|
4331
|
+
this._onSignInCallback(response);
|
|
4127
4332
|
}
|
|
4128
|
-
|
|
4129
|
-
};
|
|
4130
|
-
const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => {
|
|
4131
|
-
const config2 = await getConfigData();
|
|
4132
|
-
const pkceKey = extractPkceStorageKeyFromState3(resolvedState);
|
|
4133
|
-
const message = {
|
|
4134
|
-
data: {
|
|
4135
|
-
code: resolvedAuthorizationCode,
|
|
4136
|
-
pkce: config2.enablePKCE ? SPAUtils.getPKCE(pkceKey) : void 0,
|
|
4137
|
-
sessionState: resolvedSessionState,
|
|
4138
|
-
state: resolvedState,
|
|
4139
|
-
tokenRequestConfig
|
|
4140
|
-
},
|
|
4141
|
-
type: REQUEST_ACCESS_TOKEN
|
|
4142
|
-
};
|
|
4143
|
-
config2.enablePKCE && SPAUtils.removePKCE(pkceKey);
|
|
4144
|
-
return communicate(message).then((response) => {
|
|
4145
|
-
const message2 = {
|
|
4146
|
-
type: GET_SIGN_OUT_URL
|
|
4147
|
-
};
|
|
4148
|
-
return communicate(message2).then((url) => {
|
|
4149
|
-
SPAUtils.setSignOutURL(url, config2.clientID, instanceID);
|
|
4150
|
-
if (config2.enableOIDCSessionManagement) {
|
|
4151
|
-
checkSession();
|
|
4152
|
-
}
|
|
4153
|
-
startAutoRefreshToken();
|
|
4154
|
-
return Promise.resolve(response);
|
|
4155
|
-
}).catch((error) => {
|
|
4156
|
-
return Promise.reject(error);
|
|
4157
|
-
});
|
|
4158
|
-
}).catch((error) => {
|
|
4159
|
-
return Promise.reject(error);
|
|
4160
|
-
});
|
|
4161
|
-
};
|
|
4162
|
-
const shouldStopAuthn = async () => {
|
|
4163
|
-
return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
|
|
4164
|
-
return setSessionState(sessionState);
|
|
4333
|
+
return response;
|
|
4165
4334
|
});
|
|
4166
|
-
}
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4335
|
+
}
|
|
4336
|
+
/**
|
|
4337
|
+
* This method allows you to sign in silently.
|
|
4338
|
+
* First, this method sends a prompt none request to see if there is an active user session in the identity server.
|
|
4339
|
+
* If there is one, then it requests the access token and stores it. Else, it returns false.
|
|
4340
|
+
*
|
|
4341
|
+
* If this method is to be called on page load and the `signIn` method is also to be called on page load,
|
|
4342
|
+
* then it is advisable to call this method after the `signIn` call.
|
|
4343
|
+
*
|
|
4344
|
+
* @return {Promise<User | boolean>} - A Promise that resolves with the user information after signing in
|
|
4345
|
+
* or with `false` if the user is not signed in.
|
|
4346
|
+
*
|
|
4347
|
+
* @example
|
|
4348
|
+
*```
|
|
4349
|
+
* auth.trySignInSilently()
|
|
4350
|
+
*```
|
|
4351
|
+
*/
|
|
4352
|
+
async trySignInSilently(additionalParams, tokenRequestConfig) {
|
|
4353
|
+
await this.isInitialized();
|
|
4354
|
+
if (SPAUtils.wasSignInCalled()) {
|
|
4355
|
+
return void 0;
|
|
4174
4356
|
}
|
|
4175
|
-
return
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
const basicUserInfo = await _authenticationHelper.handleSignIn(
|
|
4179
|
-
shouldStopAuthn,
|
|
4180
|
-
checkSession,
|
|
4181
|
-
tryRetrievingUserInfo
|
|
4182
|
-
);
|
|
4183
|
-
if (basicUserInfo) {
|
|
4184
|
-
return basicUserInfo;
|
|
4185
|
-
} else {
|
|
4186
|
-
let resolvedAuthorizationCode;
|
|
4187
|
-
let resolvedSessionState;
|
|
4188
|
-
let resolvedState;
|
|
4189
|
-
if (config?.responseMode === ResponseMode2.FormPost && authorizationCode) {
|
|
4190
|
-
resolvedAuthorizationCode = authorizationCode;
|
|
4191
|
-
resolvedSessionState = sessionState ?? "";
|
|
4192
|
-
resolvedState = state ?? "";
|
|
4193
|
-
} else {
|
|
4194
|
-
resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(OIDCRequestConstants5.Params.AUTHORIZATION_CODE) ?? "";
|
|
4195
|
-
resolvedSessionState = new URL(window.location.href).searchParams.get(OIDCRequestConstants5.Params.SESSION_STATE) ?? "";
|
|
4196
|
-
resolvedState = new URL(window.location.href).searchParams.get(OIDCRequestConstants5.Params.STATE) ?? "";
|
|
4197
|
-
SPAUtils.removeAuthorizationCode();
|
|
4198
|
-
}
|
|
4199
|
-
if (resolvedAuthorizationCode && resolvedState) {
|
|
4200
|
-
return requestAccessToken(resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig);
|
|
4201
|
-
}
|
|
4202
|
-
return getAuthorizationURL(params).then(async (response) => {
|
|
4203
|
-
location.href = response.authorizationURL;
|
|
4204
|
-
await SPAUtils.waitTillPageRedirect();
|
|
4205
|
-
return Promise.resolve({
|
|
4206
|
-
allowedScopes: "",
|
|
4207
|
-
displayName: "",
|
|
4208
|
-
email: "",
|
|
4209
|
-
sessionState: "",
|
|
4210
|
-
sub: "",
|
|
4211
|
-
tenantDomain: "",
|
|
4212
|
-
username: ""
|
|
4213
|
-
});
|
|
4214
|
-
}).catch((error) => {
|
|
4215
|
-
return Promise.reject(error);
|
|
4216
|
-
});
|
|
4217
|
-
}
|
|
4218
|
-
};
|
|
4219
|
-
const signOut = () => {
|
|
4220
|
-
return new Promise((resolve, reject) => {
|
|
4221
|
-
if (!_getSignOutURLFromSessionStorage) {
|
|
4222
|
-
const message = {
|
|
4223
|
-
type: SIGN_OUT
|
|
4224
|
-
};
|
|
4225
|
-
return communicate(message).then(async (response) => {
|
|
4226
|
-
window.location.href = response;
|
|
4227
|
-
await SPAUtils.waitTillPageRedirect();
|
|
4228
|
-
return resolve(true);
|
|
4229
|
-
}).catch((error) => {
|
|
4230
|
-
return reject(error);
|
|
4231
|
-
});
|
|
4232
|
-
} else {
|
|
4233
|
-
window.location.href = SPAUtils.getSignOutURL(config.clientID, instanceID);
|
|
4234
|
-
return SPAUtils.waitTillPageRedirect().then(() => {
|
|
4235
|
-
return Promise.resolve(true);
|
|
4236
|
-
});
|
|
4357
|
+
return this._client?.trySignInSilently(additionalParams, tokenRequestConfig).then((response) => {
|
|
4358
|
+
if (this._onSignInCallback && response) {
|
|
4359
|
+
this._onSignInCallback(response);
|
|
4237
4360
|
}
|
|
4361
|
+
return response;
|
|
4238
4362
|
});
|
|
4239
|
-
};
|
|
4240
|
-
const revokeAccessToken = () => {
|
|
4241
|
-
const message = {
|
|
4242
|
-
type: REVOKE_ACCESS_TOKEN
|
|
4243
|
-
};
|
|
4244
|
-
return communicate(message).then((response) => {
|
|
4245
|
-
_sessionManagementHelper.reset();
|
|
4246
|
-
return Promise.resolve(response);
|
|
4247
|
-
}).catch((error) => {
|
|
4248
|
-
return Promise.reject(error);
|
|
4249
|
-
});
|
|
4250
|
-
};
|
|
4251
|
-
const getOIDCServiceEndpoints = () => {
|
|
4252
|
-
const message = {
|
|
4253
|
-
type: GET_OIDC_SERVICE_ENDPOINTS
|
|
4254
|
-
};
|
|
4255
|
-
return communicate(message).then((response) => {
|
|
4256
|
-
return Promise.resolve(response);
|
|
4257
|
-
}).catch((error) => {
|
|
4258
|
-
return Promise.reject(error);
|
|
4259
|
-
});
|
|
4260
|
-
};
|
|
4261
|
-
const getConfigData = () => {
|
|
4262
|
-
const message = {
|
|
4263
|
-
type: GET_CONFIG_DATA
|
|
4264
|
-
};
|
|
4265
|
-
return communicate(message).then((response) => {
|
|
4266
|
-
return Promise.resolve(response);
|
|
4267
|
-
}).catch((error) => {
|
|
4268
|
-
return Promise.reject(error);
|
|
4269
|
-
});
|
|
4270
|
-
};
|
|
4271
|
-
const getBasicUserInfo = () => {
|
|
4272
|
-
const message = {
|
|
4273
|
-
type: GET_BASIC_USER_INFO
|
|
4274
|
-
};
|
|
4275
|
-
return communicate(message).then((response) => {
|
|
4276
|
-
return Promise.resolve(response);
|
|
4277
|
-
}).catch((error) => {
|
|
4278
|
-
return Promise.reject(error);
|
|
4279
|
-
});
|
|
4280
|
-
};
|
|
4281
|
-
const getDecodedIDToken = () => {
|
|
4282
|
-
const message = {
|
|
4283
|
-
type: GET_DECODED_ID_TOKEN
|
|
4284
|
-
};
|
|
4285
|
-
return communicate(message).then((response) => {
|
|
4286
|
-
return Promise.resolve(response);
|
|
4287
|
-
}).catch((error) => {
|
|
4288
|
-
return Promise.reject(error);
|
|
4289
|
-
});
|
|
4290
|
-
};
|
|
4291
|
-
const getDecodedIDPIDToken = () => {
|
|
4292
|
-
const message = {
|
|
4293
|
-
type: GET_DECODED_IDP_ID_TOKEN
|
|
4294
|
-
};
|
|
4295
|
-
return communicate(message).then((response) => {
|
|
4296
|
-
return Promise.resolve(response);
|
|
4297
|
-
}).catch((error) => {
|
|
4298
|
-
return Promise.reject(error);
|
|
4299
|
-
});
|
|
4300
|
-
};
|
|
4301
|
-
const getCryptoHelper = () => {
|
|
4302
|
-
const message = {
|
|
4303
|
-
type: GET_CRYPTO_HELPER
|
|
4304
|
-
};
|
|
4305
|
-
return communicate(message).then((response) => {
|
|
4306
|
-
return Promise.resolve(response);
|
|
4307
|
-
}).catch((error) => {
|
|
4308
|
-
return Promise.reject(error);
|
|
4309
|
-
});
|
|
4310
|
-
};
|
|
4311
|
-
const getIDToken = () => {
|
|
4312
|
-
const message = {
|
|
4313
|
-
type: GET_ID_TOKEN
|
|
4314
|
-
};
|
|
4315
|
-
return communicate(message).then((response) => {
|
|
4316
|
-
return Promise.resolve(response);
|
|
4317
|
-
}).catch((error) => {
|
|
4318
|
-
return Promise.reject(error);
|
|
4319
|
-
});
|
|
4320
|
-
};
|
|
4321
|
-
const isAuthenticated = () => {
|
|
4322
|
-
const message = {
|
|
4323
|
-
type: IS_AUTHENTICATED
|
|
4324
|
-
};
|
|
4325
|
-
return communicate(message).then((response) => {
|
|
4326
|
-
return Promise.resolve(response);
|
|
4327
|
-
}).catch((error) => {
|
|
4328
|
-
return Promise.reject(error);
|
|
4329
|
-
});
|
|
4330
|
-
};
|
|
4331
|
-
const refreshAccessToken = () => {
|
|
4332
|
-
const message = {
|
|
4333
|
-
type: REFRESH_ACCESS_TOKEN
|
|
4334
|
-
};
|
|
4335
|
-
return communicate(message);
|
|
4336
|
-
};
|
|
4337
|
-
const setHttpRequestSuccessCallback = (callback) => {
|
|
4338
|
-
if (callback && typeof callback === "function") {
|
|
4339
|
-
httpClientHandlers.requestSuccessCallback = callback;
|
|
4340
|
-
}
|
|
4341
|
-
};
|
|
4342
|
-
const setHttpRequestErrorCallback = (callback) => {
|
|
4343
|
-
if (callback && typeof callback === "function") {
|
|
4344
|
-
httpClientHandlers.requestErrorCallback = callback;
|
|
4345
|
-
}
|
|
4346
|
-
};
|
|
4347
|
-
const setHttpRequestStartCallback = (callback) => {
|
|
4348
|
-
if (callback && typeof callback === "function") {
|
|
4349
|
-
httpClientHandlers.requestStartCallback = callback;
|
|
4350
|
-
}
|
|
4351
|
-
};
|
|
4352
|
-
const setHttpRequestFinishCallback = (callback) => {
|
|
4353
|
-
if (callback && typeof callback === "function") {
|
|
4354
|
-
httpClientHandlers.requestFinishCallback = callback;
|
|
4355
|
-
}
|
|
4356
|
-
};
|
|
4357
|
-
const updateConfig = async (newConfig) => {
|
|
4358
|
-
const existingConfig = await getConfigData();
|
|
4359
|
-
const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
|
|
4360
|
-
const config2 = { ...existingConfig, ...newConfig };
|
|
4361
|
-
const message = {
|
|
4362
|
-
data: config2,
|
|
4363
|
-
type: UPDATE_CONFIG
|
|
4364
|
-
};
|
|
4365
|
-
await communicate(message);
|
|
4366
|
-
if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
|
|
4367
|
-
_sessionManagementHelper.reset();
|
|
4368
|
-
checkSession();
|
|
4369
|
-
}
|
|
4370
|
-
};
|
|
4371
|
-
return {
|
|
4372
|
-
disableHttpHandler,
|
|
4373
|
-
enableHttpHandler,
|
|
4374
|
-
getBasicUserInfo,
|
|
4375
|
-
getConfigData,
|
|
4376
|
-
getCryptoHelper,
|
|
4377
|
-
getDecodedIDPIDToken,
|
|
4378
|
-
getDecodedIDToken,
|
|
4379
|
-
getIDToken,
|
|
4380
|
-
getOIDCServiceEndpoints,
|
|
4381
|
-
httpRequest,
|
|
4382
|
-
httpRequestAll,
|
|
4383
|
-
initialize,
|
|
4384
|
-
isAuthenticated,
|
|
4385
|
-
refreshAccessToken,
|
|
4386
|
-
requestCustomGrant,
|
|
4387
|
-
revokeAccessToken,
|
|
4388
|
-
setHttpRequestErrorCallback,
|
|
4389
|
-
setHttpRequestFinishCallback,
|
|
4390
|
-
setHttpRequestStartCallback,
|
|
4391
|
-
setHttpRequestSuccessCallback,
|
|
4392
|
-
signIn,
|
|
4393
|
-
signOut,
|
|
4394
|
-
trySignInSilently,
|
|
4395
|
-
updateConfig
|
|
4396
|
-
};
|
|
4397
|
-
};
|
|
4398
|
-
|
|
4399
|
-
// src/__legacy__/client.ts
|
|
4400
|
-
var DefaultConfig = {
|
|
4401
|
-
autoLogoutOnTokenRefreshError: true,
|
|
4402
|
-
checkSessionInterval: 3,
|
|
4403
|
-
clientHost: origin,
|
|
4404
|
-
enableOIDCSessionManagement: false,
|
|
4405
|
-
periodicTokenRefresh: false,
|
|
4406
|
-
sessionRefreshInterval: 300,
|
|
4407
|
-
storage: "sessionStorage" /* SessionStorage */
|
|
4408
|
-
};
|
|
4409
|
-
var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
4410
|
-
constructor(id) {
|
|
4411
|
-
__publicField(this, "_client");
|
|
4412
|
-
__publicField(this, "_storage");
|
|
4413
|
-
__publicField(this, "_authHelper", AuthenticationHelper);
|
|
4414
|
-
__publicField(this, "_worker", worker_default);
|
|
4415
|
-
__publicField(this, "_initialized", false);
|
|
4416
|
-
__publicField(this, "_startedInitialize", false);
|
|
4417
|
-
__publicField(this, "_onSignInCallback", () => null);
|
|
4418
|
-
__publicField(this, "_onSignOutCallback", () => null);
|
|
4419
|
-
__publicField(this, "_onSignOutFailedCallback", () => null);
|
|
4420
|
-
__publicField(this, "_onEndUserSession", () => null);
|
|
4421
|
-
__publicField(this, "_onInitialize", () => null);
|
|
4422
|
-
__publicField(this, "_onCustomGrant", /* @__PURE__ */ new Map());
|
|
4423
|
-
__publicField(this, "_instanceID");
|
|
4424
|
-
this._instanceID = id;
|
|
4425
|
-
}
|
|
4426
|
-
instantiateAuthHelper(authHelper) {
|
|
4427
|
-
if (authHelper) {
|
|
4428
|
-
this._authHelper = authHelper;
|
|
4429
|
-
} else {
|
|
4430
|
-
this._authHelper = AuthenticationHelper;
|
|
4431
|
-
}
|
|
4432
|
-
}
|
|
4433
|
-
instantiateWorker(worker) {
|
|
4434
|
-
if (worker) {
|
|
4435
|
-
this._worker = worker;
|
|
4436
|
-
} else {
|
|
4437
|
-
this._worker = worker_default;
|
|
4438
|
-
}
|
|
4439
4363
|
}
|
|
4440
4364
|
/**
|
|
4441
|
-
* This method
|
|
4365
|
+
* This method initiates the sign-out flow.
|
|
4442
4366
|
*
|
|
4443
|
-
*
|
|
4367
|
+
* **To fire a callback function after signing out, use the `on()` method.**
|
|
4368
|
+
* **To learn more about the `on()` method:**
|
|
4369
|
+
* @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
|
|
4370
|
+
*
|
|
4371
|
+
* @return {Promise<boolean>} - Returns a promise that resolves with `true` if sign out is successful.
|
|
4372
|
+
*
|
|
4373
|
+
* @example
|
|
4374
|
+
* ```
|
|
4375
|
+
* auth.signOut();
|
|
4376
|
+
* ```
|
|
4377
|
+
*
|
|
4378
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signout
|
|
4444
4379
|
*
|
|
4445
4380
|
* @memberof AsgardeoSPAClient
|
|
4446
4381
|
*
|
|
4447
|
-
* @
|
|
4382
|
+
* @preserve
|
|
4448
4383
|
*/
|
|
4449
|
-
async
|
|
4450
|
-
|
|
4451
|
-
|
|
4452
|
-
|
|
4453
|
-
let iterationToWait = 0;
|
|
4454
|
-
const sleep = () => {
|
|
4455
|
-
return new Promise((resolve) => setTimeout(resolve, 1));
|
|
4456
|
-
};
|
|
4457
|
-
while (!this._initialized) {
|
|
4458
|
-
if (iterationToWait === 1e4) {
|
|
4459
|
-
console.warn("It is taking longer than usual for the object to be initialized");
|
|
4460
|
-
}
|
|
4461
|
-
await sleep();
|
|
4462
|
-
iterationToWait++;
|
|
4463
|
-
}
|
|
4464
|
-
return true;
|
|
4384
|
+
async signOut() {
|
|
4385
|
+
await this._validateMethod(false);
|
|
4386
|
+
const signOutResponse = await this._client?.signOut() ?? false;
|
|
4387
|
+
return signOutResponse;
|
|
4465
4388
|
}
|
|
4466
4389
|
/**
|
|
4467
|
-
* This method
|
|
4468
|
-
*
|
|
4469
|
-
*
|
|
4470
|
-
*
|
|
4471
|
-
* @return {Promise<boolean>} - A Promise that resolves with `true` if the SDK is initialized and the
|
|
4472
|
-
* user is authenticated.
|
|
4473
|
-
*
|
|
4474
|
-
* @memberof AsgardeoSPAClient
|
|
4390
|
+
* This method sends an API request to a protected endpoint.
|
|
4391
|
+
* The access token is automatically attached to the header of the request.
|
|
4392
|
+
* This is the only way by which protected endpoints can be accessed
|
|
4393
|
+
* when the web worker is used to store session information.
|
|
4475
4394
|
*
|
|
4476
|
-
* @
|
|
4477
|
-
*/
|
|
4478
|
-
async _validateMethod(validateAuthentication = true) {
|
|
4479
|
-
if (!await this._isInitialized()) {
|
|
4480
|
-
return Promise.reject(
|
|
4481
|
-
new AsgardeoAuthException5(
|
|
4482
|
-
"SPA-AUTH_CLIENT-VM-NF01",
|
|
4483
|
-
"The SDK is not initialized.",
|
|
4484
|
-
"The SDK must be initialized first."
|
|
4485
|
-
)
|
|
4486
|
-
);
|
|
4487
|
-
}
|
|
4488
|
-
if (validateAuthentication && !await this.isAuthenticated()) {
|
|
4489
|
-
return Promise.reject(
|
|
4490
|
-
new AsgardeoAuthException5(
|
|
4491
|
-
"SPA-AUTH_CLIENT-VM-IV02",
|
|
4492
|
-
"The user is not authenticated.",
|
|
4493
|
-
"The user must be authenticated first."
|
|
4494
|
-
)
|
|
4495
|
-
);
|
|
4496
|
-
}
|
|
4497
|
-
return true;
|
|
4498
|
-
}
|
|
4499
|
-
/**
|
|
4500
|
-
* This method returns the instance of the singleton class.
|
|
4501
|
-
* If an ID is provided, it will return the instance with the given ID.
|
|
4502
|
-
* If no ID is provided, it will return the default instance value 0.
|
|
4395
|
+
* @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
|
|
4503
4396
|
*
|
|
4504
|
-
* @return {
|
|
4397
|
+
* @return {Promise<HttpResponse>} - Returns a Promise that resolves with the response to the request.
|
|
4505
4398
|
*
|
|
4506
4399
|
* @example
|
|
4507
4400
|
* ```
|
|
4508
|
-
*
|
|
4401
|
+
* const requestConfig = {
|
|
4402
|
+
* headers: {
|
|
4403
|
+
* "Accept": "application/json",
|
|
4404
|
+
* "Access-Control-Allow-Origin": "https://api.asgardeo.io/myaccount",
|
|
4405
|
+
* "Content-Type": "application/scim+json"
|
|
4406
|
+
* },
|
|
4407
|
+
* method: "GET",
|
|
4408
|
+
* url: "https://api.asgardeo.io/scim2/me"
|
|
4409
|
+
* };
|
|
4410
|
+
*
|
|
4411
|
+
* return auth.httpRequest(requestConfig)
|
|
4412
|
+
* .then((response) => {
|
|
4413
|
+
* // console.log(response);
|
|
4414
|
+
* })
|
|
4415
|
+
* .catch((error) => {
|
|
4416
|
+
* // console.error(error);
|
|
4417
|
+
* });
|
|
4509
4418
|
* ```
|
|
4510
4419
|
*
|
|
4511
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#
|
|
4420
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequest
|
|
4512
4421
|
*
|
|
4513
4422
|
* @memberof AsgardeoSPAClient
|
|
4514
4423
|
*
|
|
4515
4424
|
* @preserve
|
|
4516
4425
|
*/
|
|
4517
|
-
|
|
4518
|
-
|
|
4519
|
-
|
|
4520
|
-
} else if (!id && this._instances?.get(0)) {
|
|
4521
|
-
return this._instances.get(0);
|
|
4522
|
-
}
|
|
4523
|
-
if (id) {
|
|
4524
|
-
this._instances.set(id, new _AsgardeoSPAClient(id));
|
|
4525
|
-
return this._instances.get(id);
|
|
4526
|
-
}
|
|
4527
|
-
this._instances.set(0, new _AsgardeoSPAClient(0));
|
|
4528
|
-
return this._instances.get(0);
|
|
4426
|
+
async httpRequest(config) {
|
|
4427
|
+
await this._validateMethod(false);
|
|
4428
|
+
return this._client?.httpRequest(config);
|
|
4529
4429
|
}
|
|
4530
4430
|
/**
|
|
4531
|
-
* This method
|
|
4431
|
+
* This method sends multiple API requests to a protected endpoint.
|
|
4432
|
+
* The access token is automatically attached to the header of the request.
|
|
4433
|
+
* This is the only way by which multiple requests can be sent to protected endpoints
|
|
4434
|
+
* when the web worker is used to store session information.
|
|
4532
4435
|
*
|
|
4533
|
-
* @param {
|
|
4436
|
+
* @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
|
|
4534
4437
|
*
|
|
4535
|
-
* @return {Promise<
|
|
4438
|
+
* @return {Promise<HttpResponse[]>} - Returns a Promise that resolves with the responses to the requests.
|
|
4536
4439
|
*
|
|
4537
4440
|
* @example
|
|
4538
4441
|
* ```
|
|
4539
|
-
*
|
|
4540
|
-
*
|
|
4541
|
-
*
|
|
4542
|
-
*
|
|
4543
|
-
*
|
|
4442
|
+
* const requestConfig = {
|
|
4443
|
+
* headers: {
|
|
4444
|
+
* "Accept": "application/json",
|
|
4445
|
+
* "Content-Type": "application/scim+json"
|
|
4446
|
+
* },
|
|
4447
|
+
* method: "GET",
|
|
4448
|
+
* url: "https://api.asgardeo.io/scim2/me"
|
|
4449
|
+
* };
|
|
4450
|
+
*
|
|
4451
|
+
* const requestConfig2 = {
|
|
4452
|
+
* headers: {
|
|
4453
|
+
* "Accept": "application/json",
|
|
4454
|
+
* "Content-Type": "application/scim+json"
|
|
4455
|
+
* },
|
|
4456
|
+
* method: "GET",
|
|
4457
|
+
* url: "https://api.asgardeo.io/scim2/me"
|
|
4458
|
+
* };
|
|
4459
|
+
*
|
|
4460
|
+
* return auth.httpRequest([requestConfig, requestConfig2])
|
|
4461
|
+
* .then((responses) => {
|
|
4462
|
+
* response.forEach((response)=>{
|
|
4463
|
+
* // console.log(response);
|
|
4464
|
+
* });
|
|
4465
|
+
* })
|
|
4466
|
+
* .catch((error) => {
|
|
4467
|
+
* // console.error(error);
|
|
4468
|
+
* });
|
|
4544
4469
|
* ```
|
|
4545
4470
|
*
|
|
4546
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#
|
|
4471
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequestall
|
|
4547
4472
|
*
|
|
4548
4473
|
* @memberof AsgardeoSPAClient
|
|
4549
4474
|
*
|
|
4550
4475
|
* @preserve
|
|
4551
4476
|
*/
|
|
4552
|
-
async
|
|
4553
|
-
this.
|
|
4554
|
-
this.
|
|
4555
|
-
this._startedInitialize = true;
|
|
4556
|
-
authHelper && this.instantiateAuthHelper(authHelper);
|
|
4557
|
-
workerFile && this.instantiateWorker(workerFile);
|
|
4558
|
-
const _config = await this._client?.getConfigData();
|
|
4559
|
-
if (!(this._storage === "webWorker" /* WebWorker */)) {
|
|
4560
|
-
const mainThreadClientConfig = config;
|
|
4561
|
-
const defaultConfig = { ...DefaultConfig };
|
|
4562
|
-
const mergedConfig = {
|
|
4563
|
-
...defaultConfig,
|
|
4564
|
-
...mainThreadClientConfig
|
|
4565
|
-
};
|
|
4566
|
-
if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
|
|
4567
|
-
this._client = await MainThreadClient(
|
|
4568
|
-
this._instanceID,
|
|
4569
|
-
mergedConfig,
|
|
4570
|
-
(authClient, spaHelper) => {
|
|
4571
|
-
return new this._authHelper(authClient, spaHelper);
|
|
4572
|
-
}
|
|
4573
|
-
);
|
|
4574
|
-
}
|
|
4575
|
-
this._initialized = true;
|
|
4576
|
-
if (this._onInitialize) {
|
|
4577
|
-
this._onInitialize(true);
|
|
4578
|
-
}
|
|
4579
|
-
if (!mergedConfig.autoLogoutOnTokenRefreshError) {
|
|
4580
|
-
return Promise.resolve(true);
|
|
4581
|
-
}
|
|
4582
|
-
window.addEventListener("message", (event) => {
|
|
4583
|
-
if (event?.data?.type === REFRESH_ACCESS_TOKEN_ERR0R) {
|
|
4584
|
-
this.signOut();
|
|
4585
|
-
}
|
|
4586
|
-
});
|
|
4587
|
-
return Promise.resolve(true);
|
|
4588
|
-
} else {
|
|
4589
|
-
if (!this._client || this._client && (!_config || Object.keys(_config)?.length === 0)) {
|
|
4590
|
-
const webWorkerClientConfig = config;
|
|
4591
|
-
this._client = await WebWorkerClient(
|
|
4592
|
-
this._instanceID,
|
|
4593
|
-
{
|
|
4594
|
-
...DefaultConfig,
|
|
4595
|
-
...webWorkerClientConfig
|
|
4596
|
-
},
|
|
4597
|
-
this._worker,
|
|
4598
|
-
(authClient, spaHelper) => {
|
|
4599
|
-
return new this._authHelper(authClient, spaHelper);
|
|
4600
|
-
}
|
|
4601
|
-
);
|
|
4602
|
-
return this._client.initialize().then(() => {
|
|
4603
|
-
if (this._onInitialize) {
|
|
4604
|
-
this._onInitialize(true);
|
|
4605
|
-
}
|
|
4606
|
-
this._initialized = true;
|
|
4607
|
-
return Promise.resolve(true);
|
|
4608
|
-
}).catch((error) => {
|
|
4609
|
-
return Promise.reject(error);
|
|
4610
|
-
});
|
|
4611
|
-
}
|
|
4612
|
-
return Promise.resolve(true);
|
|
4613
|
-
}
|
|
4477
|
+
async httpRequestAll(config) {
|
|
4478
|
+
await this._validateMethod(false);
|
|
4479
|
+
return this._client?.httpRequestAll(config);
|
|
4614
4480
|
}
|
|
4615
4481
|
/**
|
|
4616
|
-
* This method
|
|
4482
|
+
* This method allows you to send a request with a custom grant.
|
|
4483
|
+
*
|
|
4484
|
+
* @param {CustomGrantRequestParams} config - The request parameters.
|
|
4617
4485
|
*
|
|
4618
|
-
* @return {Promise<
|
|
4486
|
+
* @return {Promise<HttpResponse<any> | SignInResponse>} - A Promise that resolves with
|
|
4487
|
+
* the value returned by the custom grant request.
|
|
4619
4488
|
*
|
|
4620
4489
|
* @example
|
|
4621
4490
|
* ```
|
|
4622
|
-
* auth.
|
|
4623
|
-
*
|
|
4624
|
-
*
|
|
4625
|
-
*
|
|
4491
|
+
* auth.customGrant({
|
|
4492
|
+
* attachToken: false,
|
|
4493
|
+
* data: {
|
|
4494
|
+
* client_id: "{{clientId}}",
|
|
4495
|
+
* grant_type: "account_switch",
|
|
4496
|
+
* scope: "{{scope}}",
|
|
4497
|
+
* token: "{{token}}",
|
|
4498
|
+
* },
|
|
4499
|
+
* id: "account-switch",
|
|
4500
|
+
* returnResponse: true,
|
|
4501
|
+
* returnsSession: true,
|
|
4502
|
+
* signInRequired: true
|
|
4626
4503
|
* });
|
|
4627
4504
|
* ```
|
|
4628
4505
|
*
|
|
4629
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#
|
|
4506
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#customgrant
|
|
4630
4507
|
*
|
|
4631
4508
|
* @memberof AsgardeoSPAClient
|
|
4632
4509
|
*
|
|
4633
4510
|
* @preserve
|
|
4634
4511
|
*/
|
|
4635
|
-
async
|
|
4636
|
-
|
|
4637
|
-
|
|
4512
|
+
async exchangeToken(config) {
|
|
4513
|
+
if (config.signInRequired) {
|
|
4514
|
+
await this._validateMethod();
|
|
4515
|
+
} else {
|
|
4516
|
+
await this._validateMethod();
|
|
4517
|
+
}
|
|
4518
|
+
if (!config.id) {
|
|
4519
|
+
return Promise.reject(
|
|
4520
|
+
new AsgardeoAuthException4(
|
|
4521
|
+
"SPA-AUTH_CLIENT-RCG-NF01",
|
|
4522
|
+
"The custom grant request id not found.",
|
|
4523
|
+
"The id attribute of the custom grant config object passed as an argument should have a value."
|
|
4524
|
+
)
|
|
4525
|
+
);
|
|
4526
|
+
}
|
|
4527
|
+
const customGrantResponse = await this._client?.exchangeToken(config);
|
|
4528
|
+
const customGrantCallback = this._onCustomGrant.get(config.id);
|
|
4529
|
+
customGrantCallback && customGrantCallback(this._onCustomGrant?.get(config.id));
|
|
4530
|
+
return customGrantResponse;
|
|
4638
4531
|
}
|
|
4639
4532
|
/**
|
|
4640
|
-
* This method
|
|
4641
|
-
* 1. To initiate the authentication flow.
|
|
4642
|
-
* 2. To obtain the access token after getting the authorization code.
|
|
4643
|
-
*
|
|
4644
|
-
* To satisfy the second condition, one of the two strategies mentioned below can be used:
|
|
4645
|
-
* 1. Redirect the user back to the same login page that initiated the authentication flow.
|
|
4646
|
-
* 2. Call the `signIn()` method in the page the user is redirected to after authentication.
|
|
4533
|
+
* This method ends a user session. The access token is revoked and the session information is destroyed.
|
|
4647
4534
|
*
|
|
4648
|
-
* **To fire a callback function after
|
|
4535
|
+
* **To fire a callback function after ending user session, use the `on()` method.**
|
|
4649
4536
|
* **To learn more about the `on()` method:**
|
|
4650
4537
|
* @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
|
|
4651
4538
|
*
|
|
4652
|
-
* @
|
|
4653
|
-
* The `SignInConfig` object has these two attributes in addition to any custom key-value pairs.
|
|
4654
|
-
* 1. fidp - Specifies the FIDP parameter that is used to take the user directly to an IdP login page.
|
|
4655
|
-
* 2. forceInit: Specifies if the OIDC Provider Meta Data should be loaded again from the `well-known`
|
|
4656
|
-
* endpoint.
|
|
4657
|
-
* 3. Any other parameters that should be appended to the authorization request.
|
|
4658
|
-
* @param {string} authorizationCode - The authorization code. (Optional)
|
|
4659
|
-
* @param {string} sessionState - The session state. (Optional)
|
|
4660
|
-
* @param {string} state - The state. (Optional)
|
|
4661
|
-
*
|
|
4662
|
-
* @return {Promise<BasicUserInfo>} - A promise that resolves with the user information.
|
|
4539
|
+
* @return {Promise<boolean>} - A promise that resolves with `true` if the process is successful.
|
|
4663
4540
|
*
|
|
4664
4541
|
* @example
|
|
4665
4542
|
* ```
|
|
4666
|
-
* auth.
|
|
4543
|
+
* auth.endUserSession();
|
|
4667
4544
|
* ```
|
|
4668
4545
|
*
|
|
4669
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#
|
|
4670
|
-
*
|
|
4671
|
-
* @memberof AsgardeoSPAClient
|
|
4672
|
-
*
|
|
4673
|
-
* @preserve
|
|
4674
|
-
*/
|
|
4675
|
-
async signIn(config, authorizationCode, sessionState, state, tokenRequestConfig) {
|
|
4676
|
-
await this._isInitialized();
|
|
4677
|
-
if (!SPAUtils.canContinueSignIn(Boolean(config?.callOnlyOnRedirect), authorizationCode)) {
|
|
4678
|
-
return void 0;
|
|
4679
|
-
}
|
|
4680
|
-
delete config?.callOnlyOnRedirect;
|
|
4681
|
-
return this._client?.signIn(config, authorizationCode, sessionState, state, tokenRequestConfig).then((response) => {
|
|
4682
|
-
if (this._onSignInCallback) {
|
|
4683
|
-
if (response.allowedScopes || response.displayName || response.email || response.username) {
|
|
4684
|
-
this._onSignInCallback(response);
|
|
4685
|
-
}
|
|
4686
|
-
}
|
|
4687
|
-
return response;
|
|
4688
|
-
});
|
|
4689
|
-
}
|
|
4690
|
-
/**
|
|
4691
|
-
* This method allows you to sign in silently.
|
|
4692
|
-
* First, this method sends a prompt none request to see if there is an active user session in the identity server.
|
|
4693
|
-
* If there is one, then it requests the access token and stores it. Else, it returns false.
|
|
4694
|
-
*
|
|
4695
|
-
* If this method is to be called on page load and the `signIn` method is also to be called on page load,
|
|
4696
|
-
* then it is advisable to call this method after the `signIn` call.
|
|
4697
|
-
*
|
|
4698
|
-
* @return {Promise<BasicUserInfo | boolean>} - A Promise that resolves with the user information after signing in
|
|
4699
|
-
* or with `false` if the user is not signed in.
|
|
4700
|
-
*
|
|
4701
|
-
* @example
|
|
4702
|
-
*```
|
|
4703
|
-
* auth.trySignInSilently()
|
|
4704
|
-
*```
|
|
4705
|
-
*/
|
|
4706
|
-
async trySignInSilently(additionalParams, tokenRequestConfig) {
|
|
4707
|
-
await this._isInitialized();
|
|
4708
|
-
if (SPAUtils.wasSignInCalled()) {
|
|
4709
|
-
return void 0;
|
|
4710
|
-
}
|
|
4711
|
-
return this._client?.trySignInSilently(additionalParams, tokenRequestConfig).then((response) => {
|
|
4712
|
-
if (this._onSignInCallback && response) {
|
|
4713
|
-
const basicUserInfo = response;
|
|
4714
|
-
if (basicUserInfo.allowedScopes || basicUserInfo.displayName || basicUserInfo.email || basicUserInfo.username) {
|
|
4715
|
-
this._onSignInCallback(basicUserInfo);
|
|
4716
|
-
}
|
|
4717
|
-
}
|
|
4718
|
-
return response;
|
|
4719
|
-
});
|
|
4720
|
-
}
|
|
4721
|
-
/**
|
|
4722
|
-
* This method initiates the sign-out flow.
|
|
4723
|
-
*
|
|
4724
|
-
* **To fire a callback function after signing out, use the `on()` method.**
|
|
4725
|
-
* **To learn more about the `on()` method:**
|
|
4726
|
-
* @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
|
|
4727
|
-
*
|
|
4728
|
-
* @return {Promise<boolean>} - Returns a promise that resolves with `true` if sign out is successful.
|
|
4729
|
-
*
|
|
4730
|
-
* @example
|
|
4731
|
-
* ```
|
|
4732
|
-
* auth.signOut();
|
|
4733
|
-
* ```
|
|
4734
|
-
*
|
|
4735
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#signout
|
|
4736
|
-
*
|
|
4737
|
-
* @memberof AsgardeoSPAClient
|
|
4738
|
-
*
|
|
4739
|
-
* @preserve
|
|
4740
|
-
*/
|
|
4741
|
-
async signOut() {
|
|
4742
|
-
await this._validateMethod(false);
|
|
4743
|
-
const signOutResponse = await this._client?.signOut() ?? false;
|
|
4744
|
-
return signOutResponse;
|
|
4745
|
-
}
|
|
4746
|
-
/**
|
|
4747
|
-
* This method sends an API request to a protected endpoint.
|
|
4748
|
-
* The access token is automatically attached to the header of the request.
|
|
4749
|
-
* This is the only way by which protected endpoints can be accessed
|
|
4750
|
-
* when the web worker is used to store session information.
|
|
4751
|
-
*
|
|
4752
|
-
* @param {HttpRequestConfig} config - The config object containing attributes necessary to send a request.
|
|
4753
|
-
*
|
|
4754
|
-
* @return {Promise<HttpResponse>} - Returns a Promise that resolves with the response to the request.
|
|
4755
|
-
*
|
|
4756
|
-
* @example
|
|
4757
|
-
* ```
|
|
4758
|
-
* const requestConfig = {
|
|
4759
|
-
* headers: {
|
|
4760
|
-
* "Accept": "application/json",
|
|
4761
|
-
* "Access-Control-Allow-Origin": "https://api.asgardeo.io/myaccount",
|
|
4762
|
-
* "Content-Type": "application/scim+json"
|
|
4763
|
-
* },
|
|
4764
|
-
* method: "GET",
|
|
4765
|
-
* url: "https://api.asgardeo.io/scim2/me"
|
|
4766
|
-
* };
|
|
4767
|
-
*
|
|
4768
|
-
* return auth.httpRequest(requestConfig)
|
|
4769
|
-
* .then((response) => {
|
|
4770
|
-
* // console.log(response);
|
|
4771
|
-
* })
|
|
4772
|
-
* .catch((error) => {
|
|
4773
|
-
* // console.error(error);
|
|
4774
|
-
* });
|
|
4775
|
-
* ```
|
|
4776
|
-
*
|
|
4777
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequest
|
|
4778
|
-
*
|
|
4779
|
-
* @memberof AsgardeoSPAClient
|
|
4780
|
-
*
|
|
4781
|
-
* @preserve
|
|
4782
|
-
*/
|
|
4783
|
-
async httpRequest(config) {
|
|
4784
|
-
await this._validateMethod(false);
|
|
4785
|
-
return this._client?.httpRequest(config);
|
|
4786
|
-
}
|
|
4787
|
-
/**
|
|
4788
|
-
* This method sends multiple API requests to a protected endpoint.
|
|
4789
|
-
* The access token is automatically attached to the header of the request.
|
|
4790
|
-
* This is the only way by which multiple requests can be sent to protected endpoints
|
|
4791
|
-
* when the web worker is used to store session information.
|
|
4792
|
-
*
|
|
4793
|
-
* @param {HttpRequestConfig[]} config - The config object containing attributes necessary to send a request.
|
|
4794
|
-
*
|
|
4795
|
-
* @return {Promise<HttpResponse[]>} - Returns a Promise that resolves with the responses to the requests.
|
|
4796
|
-
*
|
|
4797
|
-
* @example
|
|
4798
|
-
* ```
|
|
4799
|
-
* const requestConfig = {
|
|
4800
|
-
* headers: {
|
|
4801
|
-
* "Accept": "application/json",
|
|
4802
|
-
* "Content-Type": "application/scim+json"
|
|
4803
|
-
* },
|
|
4804
|
-
* method: "GET",
|
|
4805
|
-
* url: "https://api.asgardeo.io/scim2/me"
|
|
4806
|
-
* };
|
|
4807
|
-
*
|
|
4808
|
-
* const requestConfig2 = {
|
|
4809
|
-
* headers: {
|
|
4810
|
-
* "Accept": "application/json",
|
|
4811
|
-
* "Content-Type": "application/scim+json"
|
|
4812
|
-
* },
|
|
4813
|
-
* method: "GET",
|
|
4814
|
-
* url: "https://api.asgardeo.io/scim2/me"
|
|
4815
|
-
* };
|
|
4816
|
-
*
|
|
4817
|
-
* return auth.httpRequest([requestConfig, requestConfig2])
|
|
4818
|
-
* .then((responses) => {
|
|
4819
|
-
* response.forEach((response)=>{
|
|
4820
|
-
* // console.log(response);
|
|
4821
|
-
* });
|
|
4822
|
-
* })
|
|
4823
|
-
* .catch((error) => {
|
|
4824
|
-
* // console.error(error);
|
|
4825
|
-
* });
|
|
4826
|
-
* ```
|
|
4827
|
-
*
|
|
4828
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#httprequestall
|
|
4829
|
-
*
|
|
4830
|
-
* @memberof AsgardeoSPAClient
|
|
4831
|
-
*
|
|
4832
|
-
* @preserve
|
|
4833
|
-
*/
|
|
4834
|
-
async httpRequestAll(config) {
|
|
4835
|
-
await this._validateMethod(false);
|
|
4836
|
-
return this._client?.httpRequestAll(config);
|
|
4837
|
-
}
|
|
4838
|
-
/**
|
|
4839
|
-
* This method allows you to send a request with a custom grant.
|
|
4840
|
-
*
|
|
4841
|
-
* @param {CustomGrantRequestParams} config - The request parameters.
|
|
4842
|
-
*
|
|
4843
|
-
* @return {Promise<HttpResponse<any> | SignInResponse>} - A Promise that resolves with
|
|
4844
|
-
* the value returned by the custom grant request.
|
|
4845
|
-
*
|
|
4846
|
-
* @example
|
|
4847
|
-
* ```
|
|
4848
|
-
* auth.customGrant({
|
|
4849
|
-
* attachToken: false,
|
|
4850
|
-
* data: {
|
|
4851
|
-
* client_id: "{{clientId}}",
|
|
4852
|
-
* grant_type: "account_switch",
|
|
4853
|
-
* scope: "{{scope}}",
|
|
4854
|
-
* token: "{{token}}",
|
|
4855
|
-
* },
|
|
4856
|
-
* id: "account-switch",
|
|
4857
|
-
* returnResponse: true,
|
|
4858
|
-
* returnsSession: true,
|
|
4859
|
-
* signInRequired: true
|
|
4860
|
-
* });
|
|
4861
|
-
* ```
|
|
4862
|
-
*
|
|
4863
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#customgrant
|
|
4864
|
-
*
|
|
4865
|
-
* @memberof AsgardeoSPAClient
|
|
4866
|
-
*
|
|
4867
|
-
* @preserve
|
|
4868
|
-
*/
|
|
4869
|
-
async requestCustomGrant(config) {
|
|
4870
|
-
if (config.signInRequired) {
|
|
4871
|
-
await this._validateMethod();
|
|
4872
|
-
} else {
|
|
4873
|
-
await this._validateMethod();
|
|
4874
|
-
}
|
|
4875
|
-
if (!config.id) {
|
|
4876
|
-
return Promise.reject(
|
|
4877
|
-
new AsgardeoAuthException5(
|
|
4878
|
-
"SPA-AUTH_CLIENT-RCG-NF01",
|
|
4879
|
-
"The custom grant request id not found.",
|
|
4880
|
-
"The id attribute of the custom grant config object passed as an argument should have a value."
|
|
4881
|
-
)
|
|
4882
|
-
);
|
|
4883
|
-
}
|
|
4884
|
-
const customGrantResponse = await this._client?.requestCustomGrant(config);
|
|
4885
|
-
const customGrantCallback = this._onCustomGrant.get(config.id);
|
|
4886
|
-
customGrantCallback && customGrantCallback(this._onCustomGrant?.get(config.id));
|
|
4887
|
-
return customGrantResponse;
|
|
4888
|
-
}
|
|
4889
|
-
/**
|
|
4890
|
-
* This method ends a user session. The access token is revoked and the session information is destroyed.
|
|
4891
|
-
*
|
|
4892
|
-
* **To fire a callback function after ending user session, use the `on()` method.**
|
|
4893
|
-
* **To learn more about the `on()` method:**
|
|
4894
|
-
* @see {@link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#on}
|
|
4895
|
-
*
|
|
4896
|
-
* @return {Promise<boolean>} - A promise that resolves with `true` if the process is successful.
|
|
4897
|
-
*
|
|
4898
|
-
* @example
|
|
4899
|
-
* ```
|
|
4900
|
-
* auth.endUserSession();
|
|
4901
|
-
* ```
|
|
4902
|
-
*
|
|
4903
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#endusersession
|
|
4546
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#endusersession
|
|
4904
4547
|
*
|
|
4905
4548
|
* @memberof AsgardeoSPAClient
|
|
4906
4549
|
*
|
|
@@ -4932,9 +4575,9 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
4932
4575
|
*
|
|
4933
4576
|
* @preserve
|
|
4934
4577
|
*/
|
|
4935
|
-
async
|
|
4936
|
-
await this.
|
|
4937
|
-
return this._client?.
|
|
4578
|
+
async getOpenIDProviderEndpoints() {
|
|
4579
|
+
await this.isInitialized();
|
|
4580
|
+
return this._client?.getOpenIDProviderEndpoints();
|
|
4938
4581
|
}
|
|
4939
4582
|
/**
|
|
4940
4583
|
* This methods returns the Axios http client.
|
|
@@ -4951,13 +4594,13 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
4951
4594
|
const mainThreadClient = this._client;
|
|
4952
4595
|
return mainThreadClient.getHttpClient();
|
|
4953
4596
|
}
|
|
4954
|
-
throw new
|
|
4597
|
+
throw new AsgardeoAuthException4(
|
|
4955
4598
|
"SPA-AUTH_CLIENT-GHC-IV01",
|
|
4956
4599
|
"Http client cannot be returned.",
|
|
4957
4600
|
"The http client cannot be returned when the storage type is set to webWorker."
|
|
4958
4601
|
);
|
|
4959
4602
|
}
|
|
4960
|
-
throw new
|
|
4603
|
+
throw new AsgardeoAuthException4(
|
|
4961
4604
|
"SPA-AUTH_CLIENT-GHC-NF02",
|
|
4962
4605
|
"The SDK is not initialized.",
|
|
4963
4606
|
"The SDK has not been initialized yet. Initialize the SDK using the initialize method before calling this method."
|
|
@@ -4971,7 +4614,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
4971
4614
|
*
|
|
4972
4615
|
* @example
|
|
4973
4616
|
* ```
|
|
4974
|
-
* auth.
|
|
4617
|
+
* auth.getDecodedIdToken().then((response)=>{
|
|
4975
4618
|
* // console.log(response);
|
|
4976
4619
|
* }).catch((error)=>{
|
|
4977
4620
|
* // console.error(error);
|
|
@@ -4983,9 +4626,9 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
4983
4626
|
*
|
|
4984
4627
|
* @preserve
|
|
4985
4628
|
*/
|
|
4986
|
-
async
|
|
4629
|
+
async getDecodedIdToken() {
|
|
4987
4630
|
await this._validateMethod();
|
|
4988
|
-
return this._client?.
|
|
4631
|
+
return this._client?.getDecodedIdToken();
|
|
4989
4632
|
}
|
|
4990
4633
|
/**
|
|
4991
4634
|
* This method returns the IsomorphicCrypto instance.
|
|
@@ -4995,21 +4638,21 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
4995
4638
|
*
|
|
4996
4639
|
* @example
|
|
4997
4640
|
* ```
|
|
4998
|
-
* auth.
|
|
4641
|
+
* auth.getCrypto().then((response)=>{
|
|
4999
4642
|
* // console.log(response);
|
|
5000
4643
|
* }).catch((error)=>{
|
|
5001
4644
|
* // console.error(error);
|
|
5002
4645
|
* });
|
|
5003
4646
|
* ```
|
|
5004
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#
|
|
4647
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master#getCrypto
|
|
5005
4648
|
*
|
|
5006
4649
|
* @memberof AsgardeoSPAClient
|
|
5007
4650
|
*
|
|
5008
4651
|
* @preserve
|
|
5009
4652
|
*/
|
|
5010
|
-
async
|
|
4653
|
+
async getCrypto() {
|
|
5011
4654
|
await this._validateMethod();
|
|
5012
|
-
return this._client?.
|
|
4655
|
+
return this._client?.getCrypto();
|
|
5013
4656
|
}
|
|
5014
4657
|
/**
|
|
5015
4658
|
* This method return the ID token.
|
|
@@ -5018,18 +4661,18 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5018
4661
|
*
|
|
5019
4662
|
* @example
|
|
5020
4663
|
* ```
|
|
5021
|
-
* const idToken = await auth.
|
|
4664
|
+
* const idToken = await auth.getIdToken();
|
|
5022
4665
|
* ```
|
|
5023
4666
|
*
|
|
5024
|
-
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#
|
|
4667
|
+
* @link https://github.com/asgardeo/asgardeo-auth-js-sdk/tree/master#getIdToken
|
|
5025
4668
|
*
|
|
5026
4669
|
* @memberof AsgardeoAuthClient
|
|
5027
4670
|
*
|
|
5028
4671
|
* @preserve
|
|
5029
4672
|
*/
|
|
5030
|
-
async
|
|
4673
|
+
async getIdToken() {
|
|
5031
4674
|
await this._validateMethod();
|
|
5032
|
-
return this._client?.
|
|
4675
|
+
return this._client?.getIdToken();
|
|
5033
4676
|
}
|
|
5034
4677
|
/**
|
|
5035
4678
|
* This method return a Promise that resolves with the access token.
|
|
@@ -5057,7 +4700,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5057
4700
|
await this._validateMethod();
|
|
5058
4701
|
if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
|
|
5059
4702
|
return Promise.reject(
|
|
5060
|
-
new
|
|
4703
|
+
new AsgardeoAuthException4(
|
|
5061
4704
|
"SPA-AUTH_CLIENT-GAT-IV01",
|
|
5062
4705
|
"The access token cannot be returned.",
|
|
5063
4706
|
"The access token cannot be returned when the storage type is set to webWorker or browserMemory."
|
|
@@ -5093,7 +4736,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5093
4736
|
await this._validateMethod();
|
|
5094
4737
|
if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
|
|
5095
4738
|
return Promise.reject(
|
|
5096
|
-
new
|
|
4739
|
+
new AsgardeoAuthException4(
|
|
5097
4740
|
"SPA-AUTH_CLIENT-GIAT-IV01",
|
|
5098
4741
|
"The access token cannot be returned.",
|
|
5099
4742
|
"The access token cannot be returned when the storage type is set to webWorker or browserMemory."
|
|
@@ -5112,7 +4755,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5112
4755
|
*
|
|
5113
4756
|
* @example
|
|
5114
4757
|
* ```
|
|
5115
|
-
* auth.
|
|
4758
|
+
* auth.getStorageManager().then((dataLayer) => {
|
|
5116
4759
|
* // console.log(dataLayer);
|
|
5117
4760
|
* }).catch((error) => {
|
|
5118
4761
|
* // console.error(error);
|
|
@@ -5125,11 +4768,11 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5125
4768
|
*
|
|
5126
4769
|
* @preserve
|
|
5127
4770
|
*/
|
|
5128
|
-
async
|
|
4771
|
+
async getStorageManager() {
|
|
5129
4772
|
await this._validateMethod();
|
|
5130
4773
|
if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
|
|
5131
4774
|
return Promise.reject(
|
|
5132
|
-
new
|
|
4775
|
+
new AsgardeoAuthException4(
|
|
5133
4776
|
"SPA-AUTH_CLIENT-GDL-IV01",
|
|
5134
4777
|
"The data layer cannot be returned.",
|
|
5135
4778
|
"The data layer cannot be returned when the storage type is set to webWorker or browserMemory."
|
|
@@ -5137,7 +4780,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5137
4780
|
);
|
|
5138
4781
|
}
|
|
5139
4782
|
const mainThreadClient = this._client;
|
|
5140
|
-
return mainThreadClient.
|
|
4783
|
+
return mainThreadClient.getStorageManager();
|
|
5141
4784
|
}
|
|
5142
4785
|
/**
|
|
5143
4786
|
* This method return a Promise that resolves with the config data stored in the storage.
|
|
@@ -5196,9 +4839,9 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5196
4839
|
*
|
|
5197
4840
|
* @preserve
|
|
5198
4841
|
*/
|
|
5199
|
-
async
|
|
5200
|
-
await this.
|
|
5201
|
-
return this._client?.
|
|
4842
|
+
async isSignedIn() {
|
|
4843
|
+
await this.isInitialized();
|
|
4844
|
+
return this._client?.isSignedIn();
|
|
5202
4845
|
}
|
|
5203
4846
|
/**
|
|
5204
4847
|
* This method specifies if there is an active session in the browser or not.
|
|
@@ -5210,10 +4853,10 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5210
4853
|
* @preserve
|
|
5211
4854
|
*/
|
|
5212
4855
|
async isSessionActive() {
|
|
5213
|
-
await this.
|
|
4856
|
+
await this.isInitialized();
|
|
5214
4857
|
if (this._storage && [("webWorker" /* WebWorker */, "browserMemory" /* BrowserMemory */)].includes(this._storage)) {
|
|
5215
4858
|
return Promise.reject(
|
|
5216
|
-
new
|
|
4859
|
+
new AsgardeoAuthException4(
|
|
5217
4860
|
"SPA-AUTH_CLIENT-ISA-IV01",
|
|
5218
4861
|
"The active session cannot be returned.",
|
|
5219
4862
|
"The active session cannot be returned when the storage type is set to webWorker or browserMemory."
|
|
@@ -5224,7 +4867,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5224
4867
|
return mainThreadClient?.isSessionActive();
|
|
5225
4868
|
}
|
|
5226
4869
|
async on(hook, callback, id) {
|
|
5227
|
-
await this.
|
|
4870
|
+
await this.isInitialized();
|
|
5228
4871
|
if (callback && typeof callback === "function") {
|
|
5229
4872
|
switch (hook) {
|
|
5230
4873
|
case "sign-in" /* SignIn */:
|
|
@@ -5266,10 +4909,10 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5266
4909
|
break;
|
|
5267
4910
|
}
|
|
5268
4911
|
default:
|
|
5269
|
-
throw new
|
|
4912
|
+
throw new AsgardeoAuthException4("SPA-AUTH_CLIENT-ON-IV01", "Invalid hook.", "The provided hook is invalid.");
|
|
5270
4913
|
}
|
|
5271
4914
|
} else {
|
|
5272
|
-
throw new
|
|
4915
|
+
throw new AsgardeoAuthException4(
|
|
5273
4916
|
"SPA-AUTH_CLIENT-ON-IV02",
|
|
5274
4917
|
"Invalid callback function.",
|
|
5275
4918
|
"The provided callback function is invalid."
|
|
@@ -5293,7 +4936,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5293
4936
|
* @preserve
|
|
5294
4937
|
*/
|
|
5295
4938
|
async enableHttpHandler() {
|
|
5296
|
-
await this.
|
|
4939
|
+
await this.isInitialized();
|
|
5297
4940
|
return this._client?.enableHttpHandler();
|
|
5298
4941
|
}
|
|
5299
4942
|
/**
|
|
@@ -5313,7 +4956,7 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5313
4956
|
* @preserve
|
|
5314
4957
|
*/
|
|
5315
4958
|
async disableHttpHandler() {
|
|
5316
|
-
await this.
|
|
4959
|
+
await this.isInitialized();
|
|
5317
4960
|
return this._client?.disableHttpHandler();
|
|
5318
4961
|
}
|
|
5319
4962
|
/**
|
|
@@ -5324,26 +4967,26 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
5324
4967
|
* @example
|
|
5325
4968
|
* ```
|
|
5326
4969
|
* const config = {
|
|
5327
|
-
*
|
|
5328
|
-
*
|
|
4970
|
+
* afterSignInUrl: "http://localhost:3000/sign-in",
|
|
4971
|
+
* clientId: "client ID",
|
|
5329
4972
|
* baseUrl: "https://api.asgardeo.io"
|
|
5330
4973
|
* }
|
|
5331
|
-
* const auth.
|
|
4974
|
+
* const auth.reInitialize(config);
|
|
5332
4975
|
* ```
|
|
5333
|
-
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#
|
|
4976
|
+
* @link https://github.com/asgardeo/asgardeo-auth-spa-sdk/tree/master/lib#reInitialize
|
|
5334
4977
|
*
|
|
5335
4978
|
* @memberof AsgardeoAuthClient
|
|
5336
4979
|
*
|
|
5337
4980
|
* @preserve
|
|
5338
4981
|
*/
|
|
5339
|
-
async
|
|
5340
|
-
await this.
|
|
4982
|
+
async reInitialize(config) {
|
|
4983
|
+
await this.isInitialized();
|
|
5341
4984
|
if (this._storage === "webWorker" /* WebWorker */) {
|
|
5342
4985
|
const client = this._client;
|
|
5343
|
-
await client.
|
|
4986
|
+
await client.reInitialize(config);
|
|
5344
4987
|
} else {
|
|
5345
4988
|
const client = this._client;
|
|
5346
|
-
await client.
|
|
4989
|
+
await client.reInitialize(config);
|
|
5347
4990
|
}
|
|
5348
4991
|
return;
|
|
5349
4992
|
}
|
|
@@ -5368,13 +5011,374 @@ import {
|
|
|
5368
5011
|
} from "axios";
|
|
5369
5012
|
|
|
5370
5013
|
// src/__legacy__/models/web-worker.ts
|
|
5371
|
-
var WebWorkerClass = class
|
|
5014
|
+
var WebWorkerClass = class {
|
|
5372
5015
|
constructor() {
|
|
5373
|
-
super(...arguments);
|
|
5374
5016
|
__publicField(this, "onmessage", () => null);
|
|
5017
|
+
__publicField(this, "postMessage", () => null);
|
|
5375
5018
|
}
|
|
5376
5019
|
};
|
|
5377
5020
|
|
|
5021
|
+
// src/__legacy__/worker/worker-receiver.ts
|
|
5022
|
+
import { AsgardeoAuthException as AsgardeoAuthException5 } from "@asgardeo/javascript";
|
|
5023
|
+
|
|
5024
|
+
// src/__legacy__/worker/worker-core.ts
|
|
5025
|
+
import {
|
|
5026
|
+
AsgardeoAuthClient as AsgardeoAuthClient8,
|
|
5027
|
+
OIDCRequestConstants as OIDCRequestConstants5
|
|
5028
|
+
} from "@asgardeo/javascript";
|
|
5029
|
+
var WebWorkerCore = async (config, getAuthHelper) => {
|
|
5030
|
+
const _store = new MemoryStore();
|
|
5031
|
+
const _cryptoUtils = new SPACryptoUtils();
|
|
5032
|
+
const _authenticationClient = new AsgardeoAuthClient8();
|
|
5033
|
+
await _authenticationClient.initialize(config, _store, _cryptoUtils);
|
|
5034
|
+
const _spaHelper = new SPAHelper(_authenticationClient);
|
|
5035
|
+
const _authenticationHelper = getAuthHelper(
|
|
5036
|
+
_authenticationClient,
|
|
5037
|
+
_spaHelper
|
|
5038
|
+
);
|
|
5039
|
+
const _dataLayer = _authenticationClient.getStorageManager();
|
|
5040
|
+
const _httpClient = HttpClient.getInstance();
|
|
5041
|
+
const attachToken = async (request) => {
|
|
5042
|
+
await _authenticationHelper.attachTokenToRequestConfig(request);
|
|
5043
|
+
};
|
|
5044
|
+
_httpClient?.init && await _httpClient.init(true, attachToken);
|
|
5045
|
+
const setHttpRequestStartCallback = (callback) => {
|
|
5046
|
+
_httpClient?.setHttpRequestStartCallback && _httpClient.setHttpRequestStartCallback(callback);
|
|
5047
|
+
};
|
|
5048
|
+
const setHttpRequestSuccessCallback = (callback) => {
|
|
5049
|
+
_httpClient?.setHttpRequestSuccessCallback && _httpClient.setHttpRequestSuccessCallback(callback);
|
|
5050
|
+
};
|
|
5051
|
+
const setHttpRequestFinishCallback = (callback) => {
|
|
5052
|
+
_httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
|
|
5053
|
+
};
|
|
5054
|
+
const httpRequest = async (requestConfig) => {
|
|
5055
|
+
return await _authenticationHelper.httpRequest(_httpClient, requestConfig);
|
|
5056
|
+
};
|
|
5057
|
+
const httpRequestAll = async (requestConfigs) => {
|
|
5058
|
+
return await _authenticationHelper.httpRequestAll(requestConfigs, _httpClient);
|
|
5059
|
+
};
|
|
5060
|
+
const enableHttpHandler = () => {
|
|
5061
|
+
_authenticationHelper.enableHttpHandler(_httpClient);
|
|
5062
|
+
};
|
|
5063
|
+
const disableHttpHandler = () => {
|
|
5064
|
+
_authenticationHelper.disableHttpHandler(_httpClient);
|
|
5065
|
+
};
|
|
5066
|
+
const getSignInUrl = async (params) => {
|
|
5067
|
+
return _authenticationClient.getSignInUrl(params).then(async (url) => {
|
|
5068
|
+
const urlObject = new URL(url);
|
|
5069
|
+
const state = urlObject.searchParams.get(OIDCRequestConstants5.Params.STATE) ?? "";
|
|
5070
|
+
const pkce = await _authenticationClient.getPKCECode(state);
|
|
5071
|
+
return { authorizationURL: url, pkce };
|
|
5072
|
+
}).catch((error) => Promise.reject(error));
|
|
5073
|
+
};
|
|
5074
|
+
const startAutoRefreshToken = async () => {
|
|
5075
|
+
_spaHelper.clearRefreshTokenTimeout();
|
|
5076
|
+
_spaHelper.refreshAccessTokenAutomatically(_authenticationHelper);
|
|
5077
|
+
return;
|
|
5078
|
+
};
|
|
5079
|
+
const requestAccessToken = async (authorizationCode, sessionState, pkce, state) => {
|
|
5080
|
+
return await _authenticationHelper.requestAccessToken(authorizationCode, sessionState, void 0, pkce, state);
|
|
5081
|
+
};
|
|
5082
|
+
const signOut = async () => {
|
|
5083
|
+
_spaHelper.clearRefreshTokenTimeout();
|
|
5084
|
+
return await _authenticationClient.getSignOutUrl();
|
|
5085
|
+
};
|
|
5086
|
+
const getSignOutUrl = async () => {
|
|
5087
|
+
return await _authenticationClient.getSignOutUrl();
|
|
5088
|
+
};
|
|
5089
|
+
const exchangeToken = async (config2) => {
|
|
5090
|
+
return await _authenticationHelper.exchangeToken(config2);
|
|
5091
|
+
};
|
|
5092
|
+
const refreshAccessToken = async () => {
|
|
5093
|
+
try {
|
|
5094
|
+
return await _authenticationHelper.refreshAccessToken();
|
|
5095
|
+
} catch (error) {
|
|
5096
|
+
return Promise.reject(error);
|
|
5097
|
+
}
|
|
5098
|
+
};
|
|
5099
|
+
const revokeAccessToken = async () => {
|
|
5100
|
+
const timer = await _spaHelper.getRefreshTimeoutTimer();
|
|
5101
|
+
return _authenticationClient.revokeAccessToken().then(() => {
|
|
5102
|
+
_spaHelper.clearRefreshTokenTimeout(timer);
|
|
5103
|
+
return Promise.resolve(true);
|
|
5104
|
+
}).catch((error) => Promise.reject(error));
|
|
5105
|
+
};
|
|
5106
|
+
const getUser = async () => {
|
|
5107
|
+
return _authenticationHelper.getUser();
|
|
5108
|
+
};
|
|
5109
|
+
const getDecodedIdToken = async () => {
|
|
5110
|
+
return _authenticationHelper.getDecodedIdToken();
|
|
5111
|
+
};
|
|
5112
|
+
const getCrypto = async () => {
|
|
5113
|
+
return _authenticationHelper.getCrypto();
|
|
5114
|
+
};
|
|
5115
|
+
const getDecodedIDPIDToken = async () => {
|
|
5116
|
+
return _authenticationHelper.getDecodedIDPIDToken();
|
|
5117
|
+
};
|
|
5118
|
+
const getIdToken = async () => {
|
|
5119
|
+
return _authenticationHelper.getIdToken();
|
|
5120
|
+
};
|
|
5121
|
+
const getOpenIDProviderEndpoints = async () => {
|
|
5122
|
+
return _authenticationHelper.getOpenIDProviderEndpoints();
|
|
5123
|
+
};
|
|
5124
|
+
const getAccessToken = () => {
|
|
5125
|
+
return _authenticationHelper.getAccessToken();
|
|
5126
|
+
};
|
|
5127
|
+
const isSignedIn = () => {
|
|
5128
|
+
return _authenticationHelper.isSignedIn();
|
|
5129
|
+
};
|
|
5130
|
+
const setSessionState = async (sessionState) => {
|
|
5131
|
+
await _dataLayer.setSessionDataParameter(
|
|
5132
|
+
OIDCRequestConstants5.Params.SESSION_STATE,
|
|
5133
|
+
sessionState
|
|
5134
|
+
);
|
|
5135
|
+
return;
|
|
5136
|
+
};
|
|
5137
|
+
const reInitialize = async (config2) => {
|
|
5138
|
+
await _authenticationClient.reInitialize(config2);
|
|
5139
|
+
return;
|
|
5140
|
+
};
|
|
5141
|
+
const getConfigData = async () => {
|
|
5142
|
+
return _dataLayer.getConfigData();
|
|
5143
|
+
};
|
|
5144
|
+
return {
|
|
5145
|
+
disableHttpHandler,
|
|
5146
|
+
enableHttpHandler,
|
|
5147
|
+
getAccessToken,
|
|
5148
|
+
getSignInUrl,
|
|
5149
|
+
getUser,
|
|
5150
|
+
getConfigData,
|
|
5151
|
+
getCrypto,
|
|
5152
|
+
getDecodedIDPIDToken,
|
|
5153
|
+
getDecodedIdToken,
|
|
5154
|
+
getIdToken,
|
|
5155
|
+
getOpenIDProviderEndpoints,
|
|
5156
|
+
getSignOutUrl,
|
|
5157
|
+
httpRequest,
|
|
5158
|
+
httpRequestAll,
|
|
5159
|
+
isSignedIn,
|
|
5160
|
+
refreshAccessToken,
|
|
5161
|
+
requestAccessToken,
|
|
5162
|
+
exchangeToken,
|
|
5163
|
+
revokeAccessToken,
|
|
5164
|
+
setHttpRequestFinishCallback,
|
|
5165
|
+
setHttpRequestStartCallback,
|
|
5166
|
+
setHttpRequestSuccessCallback,
|
|
5167
|
+
setSessionState,
|
|
5168
|
+
signOut,
|
|
5169
|
+
startAutoRefreshToken,
|
|
5170
|
+
reInitialize
|
|
5171
|
+
};
|
|
5172
|
+
};
|
|
5173
|
+
|
|
5174
|
+
// src/__legacy__/worker/worker-receiver.ts
|
|
5175
|
+
var workerReceiver = (getAuthHelper) => {
|
|
5176
|
+
const ctx = self;
|
|
5177
|
+
let webWorker;
|
|
5178
|
+
ctx.onmessage = async ({ data, ports }) => {
|
|
5179
|
+
const port = ports[0];
|
|
5180
|
+
if (data.type !== INIT && !webWorker) {
|
|
5181
|
+
port.postMessage(
|
|
5182
|
+
MessageUtils.generateFailureMessage(
|
|
5183
|
+
new AsgardeoAuthException5(
|
|
5184
|
+
"SPA-CLIENT_WORKER-ONMSG-NF01",
|
|
5185
|
+
"The web worker has not been initialized yet.",
|
|
5186
|
+
"The initialize method needs to be called before the specified operation can be carried out."
|
|
5187
|
+
)
|
|
5188
|
+
)
|
|
5189
|
+
);
|
|
5190
|
+
return;
|
|
5191
|
+
}
|
|
5192
|
+
switch (data.type) {
|
|
5193
|
+
case INIT:
|
|
5194
|
+
try {
|
|
5195
|
+
const config = { ...data.data };
|
|
5196
|
+
webWorker = await WebWorkerCore(config, getAuthHelper);
|
|
5197
|
+
webWorker.setHttpRequestFinishCallback(onRequestFinishCallback);
|
|
5198
|
+
webWorker.setHttpRequestStartCallback(onRequestStartCallback);
|
|
5199
|
+
webWorker.setHttpRequestSuccessCallback(onRequestSuccessCallback);
|
|
5200
|
+
port.postMessage(MessageUtils.generateSuccessMessage());
|
|
5201
|
+
} catch (error) {
|
|
5202
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5203
|
+
}
|
|
5204
|
+
break;
|
|
5205
|
+
case GET_AUTH_URL:
|
|
5206
|
+
webWorker.getSignInUrl(data?.data).then((response) => {
|
|
5207
|
+
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
5208
|
+
}).catch((error) => {
|
|
5209
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5210
|
+
});
|
|
5211
|
+
break;
|
|
5212
|
+
case REQUEST_ACCESS_TOKEN:
|
|
5213
|
+
webWorker.requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.pkce, data?.data?.state).then((response) => {
|
|
5214
|
+
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
5215
|
+
}).catch((error) => {
|
|
5216
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5217
|
+
});
|
|
5218
|
+
break;
|
|
5219
|
+
case HTTP_REQUEST: {
|
|
5220
|
+
const request = data.data;
|
|
5221
|
+
const requestData = request?.data;
|
|
5222
|
+
if (data.data?.data?.formData === true) {
|
|
5223
|
+
const formData = new FormData();
|
|
5224
|
+
for (const key in requestData) {
|
|
5225
|
+
if (key === "formData") {
|
|
5226
|
+
continue;
|
|
5227
|
+
}
|
|
5228
|
+
formData.append(key, requestData[key]);
|
|
5229
|
+
}
|
|
5230
|
+
request.data = formData;
|
|
5231
|
+
}
|
|
5232
|
+
webWorker.httpRequest(request).then((response) => {
|
|
5233
|
+
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
5234
|
+
}).catch((error) => {
|
|
5235
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5236
|
+
});
|
|
5237
|
+
break;
|
|
5238
|
+
}
|
|
5239
|
+
case HTTP_REQUEST_ALL:
|
|
5240
|
+
webWorker.httpRequestAll(data.data).then((response) => {
|
|
5241
|
+
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
5242
|
+
}).catch((error) => {
|
|
5243
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5244
|
+
});
|
|
5245
|
+
break;
|
|
5246
|
+
case SIGN_OUT:
|
|
5247
|
+
try {
|
|
5248
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.signOut()));
|
|
5249
|
+
} catch (error) {
|
|
5250
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5251
|
+
}
|
|
5252
|
+
break;
|
|
5253
|
+
case REQUEST_CUSTOM_GRANT:
|
|
5254
|
+
webWorker.exchangeToken(data.data).then((response) => {
|
|
5255
|
+
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
5256
|
+
}).catch((error) => {
|
|
5257
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5258
|
+
});
|
|
5259
|
+
break;
|
|
5260
|
+
case REVOKE_ACCESS_TOKEN:
|
|
5261
|
+
webWorker.revokeAccessToken().then((response) => {
|
|
5262
|
+
port.postMessage(MessageUtils.generateSuccessMessage(response));
|
|
5263
|
+
}).catch((error) => {
|
|
5264
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5265
|
+
});
|
|
5266
|
+
break;
|
|
5267
|
+
case GET_OIDC_SERVICE_ENDPOINTS:
|
|
5268
|
+
try {
|
|
5269
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getOpenIDProviderEndpoints()));
|
|
5270
|
+
} catch (error) {
|
|
5271
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5272
|
+
}
|
|
5273
|
+
break;
|
|
5274
|
+
case GET_BASIC_USER_INFO:
|
|
5275
|
+
try {
|
|
5276
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getUser()));
|
|
5277
|
+
} catch (error) {
|
|
5278
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5279
|
+
}
|
|
5280
|
+
break;
|
|
5281
|
+
case GET_DECODED_ID_TOKEN:
|
|
5282
|
+
try {
|
|
5283
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getDecodedIdToken()));
|
|
5284
|
+
} catch (error) {
|
|
5285
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5286
|
+
}
|
|
5287
|
+
break;
|
|
5288
|
+
case GET_CRYPTO_HELPER:
|
|
5289
|
+
try {
|
|
5290
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getCrypto()));
|
|
5291
|
+
} catch (error) {
|
|
5292
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5293
|
+
}
|
|
5294
|
+
break;
|
|
5295
|
+
case GET_ID_TOKEN:
|
|
5296
|
+
try {
|
|
5297
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getIdToken()));
|
|
5298
|
+
} catch (error) {
|
|
5299
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5300
|
+
}
|
|
5301
|
+
break;
|
|
5302
|
+
case ENABLE_HTTP_HANDLER:
|
|
5303
|
+
webWorker.enableHttpHandler();
|
|
5304
|
+
port.postMessage(MessageUtils.generateSuccessMessage());
|
|
5305
|
+
break;
|
|
5306
|
+
case DISABLE_HTTP_HANDLER:
|
|
5307
|
+
webWorker.disableHttpHandler();
|
|
5308
|
+
port.postMessage(MessageUtils.generateSuccessMessage());
|
|
5309
|
+
break;
|
|
5310
|
+
case IS_AUTHENTICATED:
|
|
5311
|
+
try {
|
|
5312
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.isSignedIn()));
|
|
5313
|
+
} catch (error) {
|
|
5314
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5315
|
+
}
|
|
5316
|
+
break;
|
|
5317
|
+
case GET_SIGN_OUT_URL:
|
|
5318
|
+
try {
|
|
5319
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getSignOutUrl()));
|
|
5320
|
+
} catch (error) {
|
|
5321
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5322
|
+
}
|
|
5323
|
+
break;
|
|
5324
|
+
case REFRESH_ACCESS_TOKEN:
|
|
5325
|
+
try {
|
|
5326
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.refreshAccessToken()));
|
|
5327
|
+
} catch (error) {
|
|
5328
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5329
|
+
}
|
|
5330
|
+
break;
|
|
5331
|
+
case START_AUTO_REFRESH_TOKEN:
|
|
5332
|
+
try {
|
|
5333
|
+
port.postMessage(MessageUtils.generateSuccessMessage(webWorker.startAutoRefreshToken()));
|
|
5334
|
+
} catch (error) {
|
|
5335
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5336
|
+
}
|
|
5337
|
+
break;
|
|
5338
|
+
case SET_SESSION_STATE:
|
|
5339
|
+
try {
|
|
5340
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.setSessionState(data?.data)));
|
|
5341
|
+
} catch (error) {
|
|
5342
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5343
|
+
}
|
|
5344
|
+
break;
|
|
5345
|
+
case UPDATE_CONFIG:
|
|
5346
|
+
try {
|
|
5347
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.reInitialize(data?.data)));
|
|
5348
|
+
} catch (error) {
|
|
5349
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5350
|
+
}
|
|
5351
|
+
break;
|
|
5352
|
+
case GET_CONFIG_DATA:
|
|
5353
|
+
try {
|
|
5354
|
+
port.postMessage(MessageUtils.generateSuccessMessage(await webWorker.getConfigData()));
|
|
5355
|
+
} catch (error) {
|
|
5356
|
+
port.postMessage(MessageUtils.generateFailureMessage(error));
|
|
5357
|
+
}
|
|
5358
|
+
break;
|
|
5359
|
+
default:
|
|
5360
|
+
port?.postMessage(
|
|
5361
|
+
MessageUtils.generateFailureMessage(
|
|
5362
|
+
new AsgardeoAuthException5(
|
|
5363
|
+
"SPA-CLIENT_WORKER-ONMSG-IV02",
|
|
5364
|
+
"The message type is invalid.",
|
|
5365
|
+
`The message type provided, ${data.type}, is invalid.`
|
|
5366
|
+
)
|
|
5367
|
+
)
|
|
5368
|
+
);
|
|
5369
|
+
}
|
|
5370
|
+
};
|
|
5371
|
+
const onRequestStartCallback = () => {
|
|
5372
|
+
ctx.postMessage({ type: REQUEST_START });
|
|
5373
|
+
};
|
|
5374
|
+
const onRequestSuccessCallback = (response) => {
|
|
5375
|
+
ctx.postMessage({ data: JSON.stringify(response ?? ""), type: REQUEST_SUCCESS });
|
|
5376
|
+
};
|
|
5377
|
+
const onRequestFinishCallback = () => {
|
|
5378
|
+
ctx.postMessage({ type: REQUEST_FINISH });
|
|
5379
|
+
};
|
|
5380
|
+
};
|
|
5381
|
+
|
|
5378
5382
|
// src/constants/StyleConstants.ts
|
|
5379
5383
|
var StyleConstants = class {
|
|
5380
5384
|
constructor() {
|