@asgardeo/browser 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/__legacy__/client.d.ts +2 -2
- package/dist/__legacy__/clients/main-thread-client.d.ts +4 -3
- package/dist/__legacy__/helpers/authentication-helper.d.ts +3 -3
- package/dist/__legacy__/models/client.d.ts +4 -4
- package/dist/__legacy__/models/web-worker.d.ts +3 -3
- package/dist/cjs/index.js +1092 -1084
- package/dist/cjs/index.js.map +4 -4
- package/dist/index.d.ts +1 -2
- package/dist/index.js +1248 -1241
- package/dist/index.js.map +4 -4
- package/dist/theme/themeDetection.d.ts +40 -0
- package/package.json +2 -2
- package/dist/constants/StyleConstants.d.ts +0 -28
- package/dist/utils/withVendorCSSClassPrefix.d.ts +0 -32
package/dist/cjs/index.js
CHANGED
|
@@ -1940,12 +1940,13 @@ __export(index_exports, {
|
|
|
1940
1940
|
ResponseType: () => import_axios2.ResponseType,
|
|
1941
1941
|
SPAHelper: () => SPAHelper,
|
|
1942
1942
|
SPAUtils: () => SPAUtils,
|
|
1943
|
-
StyleConstants: () => StyleConstants_default,
|
|
1944
1943
|
TOKEN_REQUEST_CONFIG_KEY: () => TOKEN_REQUEST_CONFIG_KEY,
|
|
1945
1944
|
WebWorkerClass: () => WebWorkerClass,
|
|
1946
1945
|
WebWorkerClient: () => WebWorkerClient,
|
|
1946
|
+
createClassObserver: () => createClassObserver,
|
|
1947
|
+
createMediaQueryListener: () => createMediaQueryListener,
|
|
1948
|
+
detectThemeMode: () => detectThemeMode,
|
|
1947
1949
|
hasAuthParamsInUrl: () => hasAuthParamsInUrl_default,
|
|
1948
|
-
withVendorCSSClassPrefix: () => withVendorCSSClassPrefix_default,
|
|
1949
1950
|
workerReceiver: () => workerReceiver
|
|
1950
1951
|
});
|
|
1951
1952
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -1954,7 +1955,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
1954
1955
|
var import_javascript8 = require("@asgardeo/javascript");
|
|
1955
1956
|
|
|
1956
1957
|
// src/__legacy__/clients/main-thread-client.ts
|
|
1957
|
-
var
|
|
1958
|
+
var import_javascript5 = require("@asgardeo/javascript");
|
|
1958
1959
|
|
|
1959
1960
|
// src/__legacy__/constants/messages-types.ts
|
|
1960
1961
|
var INIT = "init";
|
|
@@ -2024,7 +2025,7 @@ var STATE_QUERY = "state";
|
|
|
2024
2025
|
// src/__legacy__/constants/errors.ts
|
|
2025
2026
|
var ACCESS_TOKEN_INVALID = "Access token is invalid";
|
|
2026
2027
|
|
|
2027
|
-
// src/__legacy__/helpers/
|
|
2028
|
+
// src/__legacy__/helpers/session-management-helper.ts
|
|
2028
2029
|
var import_javascript2 = require("@asgardeo/javascript");
|
|
2029
2030
|
|
|
2030
2031
|
// src/__legacy__/utils/message-utils.ts
|
|
@@ -2239,665 +2240,156 @@ __publicField(_SPAUtils, "until", (condition, timeout = 500) => {
|
|
|
2239
2240
|
});
|
|
2240
2241
|
var SPAUtils = _SPAUtils;
|
|
2241
2242
|
|
|
2242
|
-
// src/__legacy__/helpers/
|
|
2243
|
-
var
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
getSessionState,
|
|
2267
|
-
config.checkSessionInterval ?? 3,
|
|
2268
|
-
config.sessionRefreshInterval ?? 300,
|
|
2269
|
-
config.afterSignInUrl,
|
|
2270
|
-
getAuthzURL
|
|
2271
|
-
);
|
|
2272
|
-
}
|
|
2273
|
-
async exchangeToken(config, enableRetrievingSignOutURLFromSession) {
|
|
2274
|
-
let useDefaultEndpoint = true;
|
|
2275
|
-
let matches = false;
|
|
2276
|
-
if (config?.tokenEndpoint) {
|
|
2277
|
-
useDefaultEndpoint = false;
|
|
2278
|
-
for (const baseUrl of [
|
|
2279
|
-
...(await this._storageManager.getConfigData())?.resourceServerURLs ?? [],
|
|
2280
|
-
config.baseUrl
|
|
2281
|
-
]) {
|
|
2282
|
-
if (baseUrl && config.tokenEndpoint?.startsWith(baseUrl)) {
|
|
2283
|
-
matches = true;
|
|
2284
|
-
break;
|
|
2285
|
-
}
|
|
2286
|
-
}
|
|
2243
|
+
// src/__legacy__/helpers/session-management-helper.ts
|
|
2244
|
+
var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
2245
|
+
let _clientID;
|
|
2246
|
+
let _checkSessionEndpoint;
|
|
2247
|
+
let _sessionState;
|
|
2248
|
+
let _interval;
|
|
2249
|
+
let _redirectURL;
|
|
2250
|
+
let _sessionRefreshInterval;
|
|
2251
|
+
let _signOut;
|
|
2252
|
+
let _sessionRefreshIntervalTimeout;
|
|
2253
|
+
let _checkSessionIntervalTimeout;
|
|
2254
|
+
let _storage;
|
|
2255
|
+
let _setSessionState;
|
|
2256
|
+
let _getSignInUrl;
|
|
2257
|
+
const initialize = (clientId, checkSessionEndpoint, getSessionState, interval, sessionRefreshInterval, redirectURL, getSignInUrl) => {
|
|
2258
|
+
_clientID = clientId;
|
|
2259
|
+
_checkSessionEndpoint = checkSessionEndpoint;
|
|
2260
|
+
_sessionState = getSessionState;
|
|
2261
|
+
_interval = interval;
|
|
2262
|
+
_redirectURL = redirectURL;
|
|
2263
|
+
_sessionRefreshInterval = sessionRefreshInterval;
|
|
2264
|
+
_getSignInUrl = getSignInUrl;
|
|
2265
|
+
if (_interval > -1) {
|
|
2266
|
+
initiateCheckSession();
|
|
2287
2267
|
}
|
|
2288
|
-
if (
|
|
2289
|
-
|
|
2268
|
+
if (_sessionRefreshInterval > -1) {
|
|
2269
|
+
sessionRefreshInterval = setInterval(() => {
|
|
2270
|
+
sendPromptNoneRequest();
|
|
2271
|
+
}, _sessionRefreshInterval * 1e3);
|
|
2290
2272
|
}
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
|
|
2295
|
-
}
|
|
2296
|
-
if (config.returnsSession) {
|
|
2297
|
-
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2298
|
-
return this._authenticationClient.getUser();
|
|
2299
|
-
} else {
|
|
2300
|
-
return response;
|
|
2301
|
-
}
|
|
2302
|
-
}).catch((error) => {
|
|
2303
|
-
return Promise.reject(error);
|
|
2304
|
-
});
|
|
2305
|
-
} else {
|
|
2306
|
-
return Promise.reject(
|
|
2307
|
-
new import_javascript2.AsgardeoAuthException(
|
|
2308
|
-
"SPA-MAIN_THREAD_CLIENT-RCG-IV01",
|
|
2309
|
-
"Request to the provided endpoint is prohibited.",
|
|
2310
|
-
"Requests can only be sent to resource servers specified by the `resourceServerURLs` attribute while initializing the SDK. The specified token endpoint in this request cannot be found among the `resourceServerURLs`"
|
|
2311
|
-
)
|
|
2312
|
-
);
|
|
2273
|
+
};
|
|
2274
|
+
const initiateCheckSession = async () => {
|
|
2275
|
+
if (!_checkSessionEndpoint || !_clientID || !_redirectURL) {
|
|
2276
|
+
return;
|
|
2313
2277
|
}
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2278
|
+
const OP_IFRAME2 = "opIFrame";
|
|
2279
|
+
async function checkSession() {
|
|
2280
|
+
const sessionState = await _sessionState();
|
|
2281
|
+
if (Boolean(_clientID) && Boolean(sessionState)) {
|
|
2282
|
+
const message = `${_clientID} ${sessionState}`;
|
|
2283
|
+
const rpIFrame2 = document.getElementById(RP_IFRAME);
|
|
2284
|
+
const opIframe2 = rpIFrame2?.contentDocument?.getElementById(OP_IFRAME2);
|
|
2285
|
+
const win = opIframe2.contentWindow;
|
|
2286
|
+
win?.postMessage(message, _checkSessionEndpoint);
|
|
2287
|
+
}
|
|
2321
2288
|
}
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2289
|
+
const rpIFrame = document.getElementById(RP_IFRAME);
|
|
2290
|
+
const opIframe = rpIFrame?.contentDocument?.getElementById(OP_IFRAME2);
|
|
2291
|
+
opIframe.src = _checkSessionEndpoint + "?client_id=" + _clientID + "&redirect_uri=" + _redirectURL;
|
|
2292
|
+
_checkSessionIntervalTimeout = setInterval(checkSession, _interval * 1e3);
|
|
2293
|
+
listenToResponseFromOPIFrame();
|
|
2294
|
+
};
|
|
2295
|
+
const reset = () => {
|
|
2296
|
+
clearInterval(_checkSessionIntervalTimeout);
|
|
2297
|
+
clearInterval(_sessionRefreshIntervalTimeout);
|
|
2298
|
+
};
|
|
2299
|
+
const listenToResponseFromOPIFrame = () => {
|
|
2300
|
+
async function receiveMessage(e) {
|
|
2301
|
+
const targetOrigin = _checkSessionEndpoint;
|
|
2302
|
+
if (!targetOrigin || targetOrigin?.indexOf(e.origin) < 0 || e?.data?.type === SET_SESSION_STATE_FROM_IFRAME) {
|
|
2303
|
+
return;
|
|
2329
2304
|
}
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2305
|
+
if (e.data === "unchanged") {
|
|
2306
|
+
} else if (e.data === "error") {
|
|
2307
|
+
window.location.href = await _signOut();
|
|
2308
|
+
} else if (e.data === "changed") {
|
|
2309
|
+
sendPromptNoneRequest();
|
|
2310
|
+
}
|
|
2311
|
+
}
|
|
2312
|
+
window?.addEventListener("message", receiveMessage, false);
|
|
2313
|
+
};
|
|
2314
|
+
const sendPromptNoneRequest = async () => {
|
|
2315
|
+
const rpIFrame = document.getElementById(RP_IFRAME);
|
|
2316
|
+
const promptNoneIFrame = rpIFrame?.contentDocument?.getElementById(
|
|
2317
|
+
PROMPT_NONE_IFRAME
|
|
2318
|
+
);
|
|
2319
|
+
if (SPAUtils.canSendPromptNoneRequest()) {
|
|
2320
|
+
SPAUtils.setPromptNoneRequestSent(true);
|
|
2321
|
+
const receiveMessageListener = (e) => {
|
|
2322
|
+
if (e?.data?.type === SET_SESSION_STATE_FROM_IFRAME) {
|
|
2323
|
+
_setSessionState(e?.data?.data ?? "");
|
|
2324
|
+
window?.removeEventListener("message", receiveMessageListener);
|
|
2325
|
+
}
|
|
2335
2326
|
};
|
|
2336
|
-
|
|
2337
|
-
|
|
2327
|
+
if (_storage === "browserMemory" /* BrowserMemory */ || _storage === "webWorker" /* WebWorker */) {
|
|
2328
|
+
window?.addEventListener("message", receiveMessageListener);
|
|
2329
|
+
}
|
|
2330
|
+
const promptNoneURL = await _getSignInUrl({
|
|
2331
|
+
prompt: "none",
|
|
2332
|
+
response_mode: "query",
|
|
2333
|
+
state: STATE
|
|
2334
|
+
});
|
|
2335
|
+
promptNoneIFrame.src = promptNoneURL;
|
|
2338
2336
|
}
|
|
2339
|
-
}
|
|
2340
|
-
async
|
|
2341
|
-
const
|
|
2342
|
-
const
|
|
2343
|
-
const
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2337
|
+
};
|
|
2338
|
+
const receivePromptNoneResponse = async (setSessionState) => {
|
|
2339
|
+
const state = new URL(window.location.href).searchParams.get(STATE_QUERY);
|
|
2340
|
+
const sessionState = new URL(window.location.href).searchParams.get(import_javascript2.OIDCRequestConstants.Params.SESSION_STATE);
|
|
2341
|
+
const parent = window.parent.parent;
|
|
2342
|
+
if (state !== null && (state.includes(STATE) || state.includes(SILENT_SIGN_IN_STATE))) {
|
|
2343
|
+
const code = new URL(window.location.href).searchParams.get("code");
|
|
2344
|
+
if (code !== null && code.length !== 0) {
|
|
2345
|
+
if (state.includes(SILENT_SIGN_IN_STATE)) {
|
|
2346
|
+
const message = {
|
|
2347
|
+
data: {
|
|
2348
|
+
code,
|
|
2349
|
+
sessionState: sessionState ?? "",
|
|
2350
|
+
state
|
|
2351
|
+
},
|
|
2352
|
+
type: CHECK_SESSION_SIGNED_IN
|
|
2353
|
+
};
|
|
2354
|
+
sessionStorage.setItem(INITIALIZED_SILENT_SIGN_IN, "false");
|
|
2355
|
+
parent.postMessage(message, parent.origin);
|
|
2356
|
+
SPAUtils.setPromptNoneRequestSent(false);
|
|
2357
|
+
window.location.href = "about:blank";
|
|
2358
|
+
await SPAUtils.waitTillPageRedirect();
|
|
2359
|
+
return true;
|
|
2354
2360
|
}
|
|
2355
|
-
|
|
2356
|
-
|
|
2361
|
+
const newSessionState = new URL(window.location.href).searchParams.get("session_state");
|
|
2362
|
+
if (_storage === "localStorage" /* LocalStorage */ || _storage === "sessionStorage" /* SessionStorage */) {
|
|
2363
|
+
setSessionState && await setSessionState(newSessionState);
|
|
2364
|
+
} else {
|
|
2365
|
+
const message = {
|
|
2366
|
+
data: newSessionState ?? "",
|
|
2367
|
+
type: SET_SESSION_STATE_FROM_IFRAME
|
|
2368
|
+
};
|
|
2369
|
+
window?.parent?.parent?.postMessage(message);
|
|
2370
|
+
}
|
|
2371
|
+
SPAUtils.setPromptNoneRequestSent(false);
|
|
2372
|
+
window.location.href = "about:blank";
|
|
2373
|
+
await SPAUtils.waitTillPageRedirect();
|
|
2374
|
+
return true;
|
|
2375
|
+
} else {
|
|
2376
|
+
if (state.includes(SILENT_SIGN_IN_STATE)) {
|
|
2377
|
+
const message = {
|
|
2378
|
+
type: CHECK_SESSION_SIGNED_OUT
|
|
2379
|
+
};
|
|
2380
|
+
window.parent.parent.postMessage(message, parent.origin);
|
|
2381
|
+
SPAUtils.setPromptNoneRequestSent(false);
|
|
2382
|
+
window.location.href = "about:blank";
|
|
2383
|
+
await SPAUtils.waitTillPageRedirect();
|
|
2384
|
+
return true;
|
|
2357
2385
|
}
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
for (const baseUrl of [...await config?.resourceServerURLs ?? [], config.baseUrl]) {
|
|
2366
|
-
if (baseUrl && requestConfig?.url?.startsWith(baseUrl)) {
|
|
2367
|
-
matches = true;
|
|
2368
|
-
break;
|
|
2369
|
-
}
|
|
2370
|
-
}
|
|
2371
|
-
if (matches) {
|
|
2372
|
-
return httpClient.request(requestConfig).then((response) => {
|
|
2373
|
-
return Promise.resolve(response);
|
|
2374
|
-
}).catch(async (error) => {
|
|
2375
|
-
if (error?.response?.status === 401 || !error?.response) {
|
|
2376
|
-
if (this._isTokenRefreshing) {
|
|
2377
|
-
return this.retryFailedRequests({
|
|
2378
|
-
enableRetrievingSignOutURLFromSession,
|
|
2379
|
-
httpClient,
|
|
2380
|
-
httpErrorCallback,
|
|
2381
|
-
httpFinishCallback,
|
|
2382
|
-
isHttpHandlerEnabled,
|
|
2383
|
-
requestConfig
|
|
2384
|
-
});
|
|
2385
|
-
}
|
|
2386
|
-
this._isTokenRefreshing = true;
|
|
2387
|
-
let refreshAccessTokenResponse;
|
|
2388
|
-
try {
|
|
2389
|
-
refreshAccessTokenResponse = await this.refreshAccessToken(enableRetrievingSignOutURLFromSession);
|
|
2390
|
-
this._isTokenRefreshing = false;
|
|
2391
|
-
} catch (refreshError) {
|
|
2392
|
-
this._isTokenRefreshing = false;
|
|
2393
|
-
if (isHttpHandlerEnabled) {
|
|
2394
|
-
if (typeof httpErrorCallback === "function") {
|
|
2395
|
-
await httpErrorCallback({
|
|
2396
|
-
...error,
|
|
2397
|
-
code: ACCESS_TOKEN_INVALID
|
|
2398
|
-
});
|
|
2399
|
-
}
|
|
2400
|
-
if (typeof httpFinishCallback === "function") {
|
|
2401
|
-
httpFinishCallback();
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
throw new import_javascript2.AsgardeoAuthException(
|
|
2405
|
-
"SPA-AUTH_HELPER-HR-SE01",
|
|
2406
|
-
refreshError?.name ?? "Refresh token request failed.",
|
|
2407
|
-
refreshError?.message ?? "An error occurred while trying to refresh the access token following a 401 response from the server."
|
|
2408
|
-
);
|
|
2409
|
-
}
|
|
2410
|
-
if (refreshAccessTokenResponse) {
|
|
2411
|
-
try {
|
|
2412
|
-
const httpResponse = await httpClient.request(requestConfig);
|
|
2413
|
-
return Promise.resolve(httpResponse);
|
|
2414
|
-
} catch (error2) {
|
|
2415
|
-
if (isHttpHandlerEnabled) {
|
|
2416
|
-
if (typeof httpErrorCallback === "function") {
|
|
2417
|
-
await httpErrorCallback(error2);
|
|
2418
|
-
}
|
|
2419
|
-
if (typeof httpFinishCallback === "function") {
|
|
2420
|
-
httpFinishCallback();
|
|
2421
|
-
}
|
|
2422
|
-
}
|
|
2423
|
-
return Promise.reject(error2);
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
}
|
|
2427
|
-
if (isHttpHandlerEnabled) {
|
|
2428
|
-
if (typeof httpErrorCallback === "function") {
|
|
2429
|
-
await httpErrorCallback(error);
|
|
2430
|
-
}
|
|
2431
|
-
if (typeof httpFinishCallback === "function") {
|
|
2432
|
-
httpFinishCallback();
|
|
2433
|
-
}
|
|
2434
|
-
}
|
|
2435
|
-
return Promise.reject(error);
|
|
2436
|
-
});
|
|
2437
|
-
} else {
|
|
2438
|
-
return Promise.reject(
|
|
2439
|
-
new import_javascript2.AsgardeoAuthException(
|
|
2440
|
-
"SPA-AUTH_HELPER-HR-IV02",
|
|
2441
|
-
"Request to the provided endpoint is prohibited.",
|
|
2442
|
-
"Requests can only be sent to resource servers specified by the `resourceServerURLs` attribute while initializing the SDK. The specified endpoint in this request cannot be found among the `resourceServerURLs`"
|
|
2443
|
-
)
|
|
2444
|
-
);
|
|
2445
|
-
}
|
|
2446
|
-
}
|
|
2447
|
-
async httpRequestAll(requestConfigs, httpClient, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback) {
|
|
2448
|
-
let matches = true;
|
|
2449
|
-
const config = await this._storageManager.getConfigData();
|
|
2450
|
-
for (const requestConfig of requestConfigs) {
|
|
2451
|
-
let urlMatches = false;
|
|
2452
|
-
for (const baseUrl of [...(await config)?.resourceServerURLs ?? [], config.baseUrl]) {
|
|
2453
|
-
if (baseUrl && requestConfig.url?.startsWith(baseUrl)) {
|
|
2454
|
-
urlMatches = true;
|
|
2455
|
-
break;
|
|
2456
|
-
}
|
|
2457
|
-
}
|
|
2458
|
-
if (!urlMatches) {
|
|
2459
|
-
matches = false;
|
|
2460
|
-
break;
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
const requests = [];
|
|
2464
|
-
if (matches) {
|
|
2465
|
-
requestConfigs.forEach((request) => {
|
|
2466
|
-
requests.push(httpClient.request(request));
|
|
2467
|
-
});
|
|
2468
|
-
return httpClient?.all && httpClient.all(requests).then((responses) => {
|
|
2469
|
-
return Promise.resolve(responses);
|
|
2470
|
-
}).catch(async (error) => {
|
|
2471
|
-
if (error?.response?.status === 401 || !error?.response) {
|
|
2472
|
-
let refreshTokenResponse;
|
|
2473
|
-
try {
|
|
2474
|
-
refreshTokenResponse = await this._authenticationClient.refreshAccessToken();
|
|
2475
|
-
} catch (refreshError) {
|
|
2476
|
-
if (isHttpHandlerEnabled) {
|
|
2477
|
-
if (typeof httpErrorCallback === "function") {
|
|
2478
|
-
await httpErrorCallback({
|
|
2479
|
-
...error,
|
|
2480
|
-
code: ACCESS_TOKEN_INVALID
|
|
2481
|
-
});
|
|
2482
|
-
}
|
|
2483
|
-
if (typeof httpFinishCallback === "function") {
|
|
2484
|
-
httpFinishCallback();
|
|
2485
|
-
}
|
|
2486
|
-
}
|
|
2487
|
-
throw new import_javascript2.AsgardeoAuthException(
|
|
2488
|
-
"SPA-AUTH_HELPER-HRA-SE01",
|
|
2489
|
-
refreshError?.name ?? "Refresh token request failed.",
|
|
2490
|
-
refreshError?.message ?? "An error occurred while trying to refresh the access token following a 401 response from the server."
|
|
2491
|
-
);
|
|
2492
|
-
}
|
|
2493
|
-
if (refreshTokenResponse) {
|
|
2494
|
-
return httpClient.all && httpClient.all(requests).then((response) => {
|
|
2495
|
-
return Promise.resolve(response);
|
|
2496
|
-
}).catch(async (error2) => {
|
|
2497
|
-
if (isHttpHandlerEnabled) {
|
|
2498
|
-
if (typeof httpErrorCallback === "function") {
|
|
2499
|
-
await httpErrorCallback(error2);
|
|
2500
|
-
}
|
|
2501
|
-
if (typeof httpFinishCallback === "function") {
|
|
2502
|
-
httpFinishCallback();
|
|
2503
|
-
}
|
|
2504
|
-
}
|
|
2505
|
-
return Promise.reject(error2);
|
|
2506
|
-
});
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
if (isHttpHandlerEnabled) {
|
|
2510
|
-
if (typeof httpErrorCallback === "function") {
|
|
2511
|
-
await httpErrorCallback(error);
|
|
2512
|
-
}
|
|
2513
|
-
if (typeof httpFinishCallback === "function") {
|
|
2514
|
-
httpFinishCallback();
|
|
2515
|
-
}
|
|
2516
|
-
}
|
|
2517
|
-
return Promise.reject(error);
|
|
2518
|
-
});
|
|
2519
|
-
} else {
|
|
2520
|
-
throw new import_javascript2.AsgardeoAuthException(
|
|
2521
|
-
"SPA-AUTH_HELPER-HRA-IV02",
|
|
2522
|
-
"Request to the provided endpoint is prohibited.",
|
|
2523
|
-
"Requests can only be sent to resource servers specified by the `resourceServerURLs` attribute while initializing the SDK. The specified endpoint in this request cannot be found among the `resourceServerURLs`"
|
|
2524
|
-
);
|
|
2525
|
-
}
|
|
2526
|
-
}
|
|
2527
|
-
async requestAccessToken(authorizationCode, sessionState, checkSession, pkce, state, tokenRequestConfig) {
|
|
2528
|
-
const config = await this._storageManager.getConfigData();
|
|
2529
|
-
if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE && sessionState) {
|
|
2530
|
-
const pkce2 = SPAUtils.getPKCE((0, import_javascript2.extractPkceStorageKeyFromState)(sessionState));
|
|
2531
|
-
await this._authenticationClient.setPKCECode((0, import_javascript2.extractPkceStorageKeyFromState)(sessionState), pkce2);
|
|
2532
|
-
} else if (config.storage === "webWorker" /* WebWorker */ && pkce) {
|
|
2533
|
-
await this._authenticationClient.setPKCECode(pkce, state ?? "");
|
|
2534
|
-
}
|
|
2535
|
-
if (authorizationCode) {
|
|
2536
|
-
return this._authenticationClient.requestAccessToken(authorizationCode, sessionState ?? "", state ?? "", void 0, tokenRequestConfig).then(async () => {
|
|
2537
|
-
if (config.storage !== "webWorker" /* WebWorker */) {
|
|
2538
|
-
SPAUtils.setSignOutURL(await this._authenticationClient.getSignOutUrl(), config.clientId, this._instanceID);
|
|
2539
|
-
if (this._spaHelper) {
|
|
2540
|
-
this._spaHelper.clearRefreshTokenTimeout();
|
|
2541
|
-
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2542
|
-
}
|
|
2543
|
-
if (checkSession && typeof checkSession === "function" && config.enableOIDCSessionManagement) {
|
|
2544
|
-
checkSession();
|
|
2545
|
-
}
|
|
2546
|
-
} else {
|
|
2547
|
-
if (this._spaHelper) {
|
|
2548
|
-
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2549
|
-
}
|
|
2550
|
-
}
|
|
2551
|
-
return this._authenticationClient.getUser();
|
|
2552
|
-
}).catch((error) => {
|
|
2553
|
-
return Promise.reject(error);
|
|
2554
|
-
});
|
|
2555
|
-
}
|
|
2556
|
-
return Promise.reject(
|
|
2557
|
-
new import_javascript2.AsgardeoAuthException(
|
|
2558
|
-
"SPA-AUTH_HELPER-RAT1-NF01",
|
|
2559
|
-
"No authorization code.",
|
|
2560
|
-
"No authorization code was found."
|
|
2561
|
-
)
|
|
2562
|
-
);
|
|
2563
|
-
}
|
|
2564
|
-
async trySignInSilently(constructSilentSignInUrl, requestAccessToken, sessionManagementHelper, additionalParams, tokenRequestConfig) {
|
|
2565
|
-
if (SPAUtils.isInitializedSilentSignIn()) {
|
|
2566
|
-
await sessionManagementHelper.receivePromptNoneResponse();
|
|
2567
|
-
return Promise.resolve({
|
|
2568
|
-
allowedScopes: "",
|
|
2569
|
-
displayName: "",
|
|
2570
|
-
email: "",
|
|
2571
|
-
sessionState: "",
|
|
2572
|
-
sub: "",
|
|
2573
|
-
tenantDomain: "",
|
|
2574
|
-
username: ""
|
|
2575
|
-
});
|
|
2576
|
-
}
|
|
2577
|
-
const rpIFrame = document.getElementById(RP_IFRAME);
|
|
2578
|
-
const promptNoneIFrame = rpIFrame?.contentDocument?.getElementById(
|
|
2579
|
-
PROMPT_NONE_IFRAME
|
|
2580
|
-
);
|
|
2581
|
-
try {
|
|
2582
|
-
const url = await constructSilentSignInUrl(additionalParams);
|
|
2583
|
-
promptNoneIFrame.src = url;
|
|
2584
|
-
} catch (error) {
|
|
2585
|
-
return Promise.reject(error);
|
|
2586
|
-
}
|
|
2587
|
-
return new Promise((resolve, reject) => {
|
|
2588
|
-
const timer = setTimeout(() => {
|
|
2589
|
-
resolve(false);
|
|
2590
|
-
}, 1e4);
|
|
2591
|
-
const listenToPromptNoneIFrame = async (e) => {
|
|
2592
|
-
const data = e.data;
|
|
2593
|
-
if (data?.type == CHECK_SESSION_SIGNED_OUT) {
|
|
2594
|
-
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
2595
|
-
clearTimeout(timer);
|
|
2596
|
-
resolve(false);
|
|
2597
|
-
}
|
|
2598
|
-
if (data?.type == CHECK_SESSION_SIGNED_IN && data?.data?.code) {
|
|
2599
|
-
requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.state, tokenRequestConfig).then((response) => {
|
|
2600
|
-
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
2601
|
-
resolve(response);
|
|
2602
|
-
}).catch((error) => {
|
|
2603
|
-
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
2604
|
-
reject(error);
|
|
2605
|
-
}).finally(() => {
|
|
2606
|
-
clearTimeout(timer);
|
|
2607
|
-
});
|
|
2608
|
-
}
|
|
2609
|
-
};
|
|
2610
|
-
window.addEventListener("message", listenToPromptNoneIFrame);
|
|
2611
|
-
});
|
|
2612
|
-
}
|
|
2613
|
-
async handleSignIn(shouldStopAuthn, checkSession, tryRetrievingUserInfo) {
|
|
2614
|
-
const config = await this._storageManager.getConfigData();
|
|
2615
|
-
if (await shouldStopAuthn()) {
|
|
2616
|
-
return Promise.resolve({
|
|
2617
|
-
allowedScopes: "",
|
|
2618
|
-
displayName: "",
|
|
2619
|
-
email: "",
|
|
2620
|
-
sessionState: "",
|
|
2621
|
-
sub: "",
|
|
2622
|
-
tenantDomain: "",
|
|
2623
|
-
username: ""
|
|
2624
|
-
});
|
|
2625
|
-
}
|
|
2626
|
-
if (config.storage !== "webWorker" /* WebWorker */) {
|
|
2627
|
-
if (await this._authenticationClient.isSignedIn()) {
|
|
2628
|
-
this._spaHelper.clearRefreshTokenTimeout();
|
|
2629
|
-
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
2630
|
-
if (config.enableOIDCSessionManagement) {
|
|
2631
|
-
checkSession();
|
|
2632
|
-
}
|
|
2633
|
-
return Promise.resolve(await this._authenticationClient.getUser());
|
|
2634
|
-
}
|
|
2635
|
-
}
|
|
2636
|
-
const error = new URL(window.location.href).searchParams.get(ERROR);
|
|
2637
|
-
const errorDescription = new URL(window.location.href).searchParams.get(ERROR_DESCRIPTION);
|
|
2638
|
-
if (error) {
|
|
2639
|
-
const url = new URL(window.location.href);
|
|
2640
|
-
url.searchParams.delete(ERROR);
|
|
2641
|
-
url.searchParams.delete(ERROR_DESCRIPTION);
|
|
2642
|
-
history.pushState(null, document.title, url.toString());
|
|
2643
|
-
throw new import_javascript2.AsgardeoAuthException("SPA-AUTH_HELPER-SI-SE01", error, errorDescription ?? "");
|
|
2644
|
-
}
|
|
2645
|
-
if (config.storage === "webWorker" /* WebWorker */ && tryRetrievingUserInfo) {
|
|
2646
|
-
const basicUserInfo = await tryRetrievingUserInfo();
|
|
2647
|
-
if (basicUserInfo) {
|
|
2648
|
-
return basicUserInfo;
|
|
2649
|
-
}
|
|
2650
|
-
}
|
|
2651
|
-
return Promise.resolve(void 0);
|
|
2652
|
-
}
|
|
2653
|
-
async attachTokenToRequestConfig(request) {
|
|
2654
|
-
const requestConfig = { attachToken: true, ...request };
|
|
2655
|
-
if (requestConfig.attachToken) {
|
|
2656
|
-
if (requestConfig.shouldAttachIDPAccessToken) {
|
|
2657
|
-
request.headers = {
|
|
2658
|
-
...request.headers,
|
|
2659
|
-
Authorization: `Bearer ${await this.getIDPAccessToken()}`
|
|
2660
|
-
};
|
|
2661
|
-
} else {
|
|
2662
|
-
request.headers = {
|
|
2663
|
-
...request.headers,
|
|
2664
|
-
Authorization: `Bearer ${await this.getAccessToken()}`
|
|
2665
|
-
};
|
|
2666
|
-
}
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
async getUser() {
|
|
2670
|
-
return this._authenticationClient.getUser();
|
|
2671
|
-
}
|
|
2672
|
-
async getDecodedIdToken() {
|
|
2673
|
-
return this._authenticationClient.getDecodedIdToken();
|
|
2674
|
-
}
|
|
2675
|
-
async getDecodedIDPIDToken() {
|
|
2676
|
-
return this._authenticationClient.getDecodedIdToken();
|
|
2677
|
-
}
|
|
2678
|
-
async getCrypto() {
|
|
2679
|
-
return this._authenticationClient.getCrypto();
|
|
2680
|
-
}
|
|
2681
|
-
async getIdToken() {
|
|
2682
|
-
return this._authenticationClient.getIdToken();
|
|
2683
|
-
}
|
|
2684
|
-
async getOpenIDProviderEndpoints() {
|
|
2685
|
-
return this._authenticationClient.getOpenIDProviderEndpoints();
|
|
2686
|
-
}
|
|
2687
|
-
async getAccessToken() {
|
|
2688
|
-
return this._authenticationClient.getAccessToken();
|
|
2689
|
-
}
|
|
2690
|
-
async getIDPAccessToken() {
|
|
2691
|
-
return (await this._storageManager.getSessionData())?.access_token;
|
|
2692
|
-
}
|
|
2693
|
-
getStorageManager() {
|
|
2694
|
-
return this._storageManager;
|
|
2695
|
-
}
|
|
2696
|
-
async isSignedIn() {
|
|
2697
|
-
return this._authenticationClient.isSignedIn();
|
|
2698
|
-
}
|
|
2699
|
-
};
|
|
2700
|
-
|
|
2701
|
-
// src/__legacy__/helpers/spa-helper.ts
|
|
2702
|
-
var import_javascript3 = require("@asgardeo/javascript");
|
|
2703
|
-
var SPAHelper = class {
|
|
2704
|
-
constructor(authClient) {
|
|
2705
|
-
__publicField(this, "_authenticationClient");
|
|
2706
|
-
__publicField(this, "_storageManager");
|
|
2707
|
-
this._authenticationClient = authClient;
|
|
2708
|
-
this._storageManager = this._authenticationClient.getStorageManager();
|
|
2709
|
-
}
|
|
2710
|
-
async refreshAccessTokenAutomatically(authenticationHelper) {
|
|
2711
|
-
const shouldRefreshAutomatically = (await this._storageManager.getConfigData())?.periodicTokenRefresh ?? false;
|
|
2712
|
-
if (!shouldRefreshAutomatically) {
|
|
2713
|
-
return;
|
|
2714
|
-
}
|
|
2715
|
-
const sessionData = await this._storageManager.getSessionData();
|
|
2716
|
-
if (sessionData.refresh_token) {
|
|
2717
|
-
const expiryTime = parseInt(sessionData.expires_in);
|
|
2718
|
-
const time = expiryTime <= 10 ? expiryTime : expiryTime - 10;
|
|
2719
|
-
const timer = setTimeout(async () => {
|
|
2720
|
-
await authenticationHelper.refreshAccessToken();
|
|
2721
|
-
}, time * 1e3);
|
|
2722
|
-
await this._storageManager.setTemporaryDataParameter(
|
|
2723
|
-
import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER,
|
|
2724
|
-
JSON.stringify(timer)
|
|
2725
|
-
);
|
|
2726
|
-
}
|
|
2727
|
-
}
|
|
2728
|
-
async getRefreshTimeoutTimer() {
|
|
2729
|
-
if (await this._storageManager.getTemporaryDataParameter(import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER)) {
|
|
2730
|
-
return JSON.parse(
|
|
2731
|
-
await this._storageManager.getTemporaryDataParameter(
|
|
2732
|
-
import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER
|
|
2733
|
-
)
|
|
2734
|
-
);
|
|
2735
|
-
}
|
|
2736
|
-
return -1;
|
|
2737
|
-
}
|
|
2738
|
-
async clearRefreshTokenTimeout(timer) {
|
|
2739
|
-
if (timer) {
|
|
2740
|
-
clearTimeout(timer);
|
|
2741
|
-
return;
|
|
2742
|
-
}
|
|
2743
|
-
const refreshTimer = await this.getRefreshTimeoutTimer();
|
|
2744
|
-
if (refreshTimer !== -1) {
|
|
2745
|
-
clearTimeout(refreshTimer);
|
|
2746
|
-
}
|
|
2747
|
-
}
|
|
2748
|
-
};
|
|
2749
|
-
|
|
2750
|
-
// src/__legacy__/helpers/session-management-helper.ts
|
|
2751
|
-
var import_javascript4 = require("@asgardeo/javascript");
|
|
2752
|
-
var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
2753
|
-
let _clientID;
|
|
2754
|
-
let _checkSessionEndpoint;
|
|
2755
|
-
let _sessionState;
|
|
2756
|
-
let _interval;
|
|
2757
|
-
let _redirectURL;
|
|
2758
|
-
let _sessionRefreshInterval;
|
|
2759
|
-
let _signOut;
|
|
2760
|
-
let _sessionRefreshIntervalTimeout;
|
|
2761
|
-
let _checkSessionIntervalTimeout;
|
|
2762
|
-
let _storage;
|
|
2763
|
-
let _setSessionState;
|
|
2764
|
-
let _getSignInUrl;
|
|
2765
|
-
const initialize = (clientId, checkSessionEndpoint, getSessionState, interval, sessionRefreshInterval, redirectURL, getSignInUrl) => {
|
|
2766
|
-
_clientID = clientId;
|
|
2767
|
-
_checkSessionEndpoint = checkSessionEndpoint;
|
|
2768
|
-
_sessionState = getSessionState;
|
|
2769
|
-
_interval = interval;
|
|
2770
|
-
_redirectURL = redirectURL;
|
|
2771
|
-
_sessionRefreshInterval = sessionRefreshInterval;
|
|
2772
|
-
_getSignInUrl = getSignInUrl;
|
|
2773
|
-
if (_interval > -1) {
|
|
2774
|
-
initiateCheckSession();
|
|
2775
|
-
}
|
|
2776
|
-
if (_sessionRefreshInterval > -1) {
|
|
2777
|
-
sessionRefreshInterval = setInterval(() => {
|
|
2778
|
-
sendPromptNoneRequest();
|
|
2779
|
-
}, _sessionRefreshInterval * 1e3);
|
|
2780
|
-
}
|
|
2781
|
-
};
|
|
2782
|
-
const initiateCheckSession = async () => {
|
|
2783
|
-
if (!_checkSessionEndpoint || !_clientID || !_redirectURL) {
|
|
2784
|
-
return;
|
|
2785
|
-
}
|
|
2786
|
-
const OP_IFRAME2 = "opIFrame";
|
|
2787
|
-
async function checkSession() {
|
|
2788
|
-
const sessionState = await _sessionState();
|
|
2789
|
-
if (Boolean(_clientID) && Boolean(sessionState)) {
|
|
2790
|
-
const message = `${_clientID} ${sessionState}`;
|
|
2791
|
-
const rpIFrame2 = document.getElementById(RP_IFRAME);
|
|
2792
|
-
const opIframe2 = rpIFrame2?.contentDocument?.getElementById(OP_IFRAME2);
|
|
2793
|
-
const win = opIframe2.contentWindow;
|
|
2794
|
-
win?.postMessage(message, _checkSessionEndpoint);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
const rpIFrame = document.getElementById(RP_IFRAME);
|
|
2798
|
-
const opIframe = rpIFrame?.contentDocument?.getElementById(OP_IFRAME2);
|
|
2799
|
-
opIframe.src = _checkSessionEndpoint + "?client_id=" + _clientID + "&redirect_uri=" + _redirectURL;
|
|
2800
|
-
_checkSessionIntervalTimeout = setInterval(checkSession, _interval * 1e3);
|
|
2801
|
-
listenToResponseFromOPIFrame();
|
|
2802
|
-
};
|
|
2803
|
-
const reset = () => {
|
|
2804
|
-
clearInterval(_checkSessionIntervalTimeout);
|
|
2805
|
-
clearInterval(_sessionRefreshIntervalTimeout);
|
|
2806
|
-
};
|
|
2807
|
-
const listenToResponseFromOPIFrame = () => {
|
|
2808
|
-
async function receiveMessage(e) {
|
|
2809
|
-
const targetOrigin = _checkSessionEndpoint;
|
|
2810
|
-
if (!targetOrigin || targetOrigin?.indexOf(e.origin) < 0 || e?.data?.type === SET_SESSION_STATE_FROM_IFRAME) {
|
|
2811
|
-
return;
|
|
2812
|
-
}
|
|
2813
|
-
if (e.data === "unchanged") {
|
|
2814
|
-
} else if (e.data === "error") {
|
|
2815
|
-
window.location.href = await _signOut();
|
|
2816
|
-
} else if (e.data === "changed") {
|
|
2817
|
-
sendPromptNoneRequest();
|
|
2818
|
-
}
|
|
2819
|
-
}
|
|
2820
|
-
window?.addEventListener("message", receiveMessage, false);
|
|
2821
|
-
};
|
|
2822
|
-
const sendPromptNoneRequest = async () => {
|
|
2823
|
-
const rpIFrame = document.getElementById(RP_IFRAME);
|
|
2824
|
-
const promptNoneIFrame = rpIFrame?.contentDocument?.getElementById(
|
|
2825
|
-
PROMPT_NONE_IFRAME
|
|
2826
|
-
);
|
|
2827
|
-
if (SPAUtils.canSendPromptNoneRequest()) {
|
|
2828
|
-
SPAUtils.setPromptNoneRequestSent(true);
|
|
2829
|
-
const receiveMessageListener = (e) => {
|
|
2830
|
-
if (e?.data?.type === SET_SESSION_STATE_FROM_IFRAME) {
|
|
2831
|
-
_setSessionState(e?.data?.data ?? "");
|
|
2832
|
-
window?.removeEventListener("message", receiveMessageListener);
|
|
2833
|
-
}
|
|
2834
|
-
};
|
|
2835
|
-
if (_storage === "browserMemory" /* BrowserMemory */ || _storage === "webWorker" /* WebWorker */) {
|
|
2836
|
-
window?.addEventListener("message", receiveMessageListener);
|
|
2837
|
-
}
|
|
2838
|
-
const promptNoneURL = await _getSignInUrl({
|
|
2839
|
-
prompt: "none",
|
|
2840
|
-
response_mode: "query",
|
|
2841
|
-
state: STATE
|
|
2842
|
-
});
|
|
2843
|
-
promptNoneIFrame.src = promptNoneURL;
|
|
2844
|
-
}
|
|
2845
|
-
};
|
|
2846
|
-
const receivePromptNoneResponse = async (setSessionState) => {
|
|
2847
|
-
const state = new URL(window.location.href).searchParams.get(STATE_QUERY);
|
|
2848
|
-
const sessionState = new URL(window.location.href).searchParams.get(import_javascript4.OIDCRequestConstants.Params.SESSION_STATE);
|
|
2849
|
-
const parent = window.parent.parent;
|
|
2850
|
-
if (state !== null && (state.includes(STATE) || state.includes(SILENT_SIGN_IN_STATE))) {
|
|
2851
|
-
const code = new URL(window.location.href).searchParams.get("code");
|
|
2852
|
-
if (code !== null && code.length !== 0) {
|
|
2853
|
-
if (state.includes(SILENT_SIGN_IN_STATE)) {
|
|
2854
|
-
const message = {
|
|
2855
|
-
data: {
|
|
2856
|
-
code,
|
|
2857
|
-
sessionState: sessionState ?? "",
|
|
2858
|
-
state
|
|
2859
|
-
},
|
|
2860
|
-
type: CHECK_SESSION_SIGNED_IN
|
|
2861
|
-
};
|
|
2862
|
-
sessionStorage.setItem(INITIALIZED_SILENT_SIGN_IN, "false");
|
|
2863
|
-
parent.postMessage(message, parent.origin);
|
|
2864
|
-
SPAUtils.setPromptNoneRequestSent(false);
|
|
2865
|
-
window.location.href = "about:blank";
|
|
2866
|
-
await SPAUtils.waitTillPageRedirect();
|
|
2867
|
-
return true;
|
|
2868
|
-
}
|
|
2869
|
-
const newSessionState = new URL(window.location.href).searchParams.get("session_state");
|
|
2870
|
-
if (_storage === "localStorage" /* LocalStorage */ || _storage === "sessionStorage" /* SessionStorage */) {
|
|
2871
|
-
setSessionState && await setSessionState(newSessionState);
|
|
2872
|
-
} else {
|
|
2873
|
-
const message = {
|
|
2874
|
-
data: newSessionState ?? "",
|
|
2875
|
-
type: SET_SESSION_STATE_FROM_IFRAME
|
|
2876
|
-
};
|
|
2877
|
-
window?.parent?.parent?.postMessage(message);
|
|
2878
|
-
}
|
|
2879
|
-
SPAUtils.setPromptNoneRequestSent(false);
|
|
2880
|
-
window.location.href = "about:blank";
|
|
2881
|
-
await SPAUtils.waitTillPageRedirect();
|
|
2882
|
-
return true;
|
|
2883
|
-
} else {
|
|
2884
|
-
if (state.includes(SILENT_SIGN_IN_STATE)) {
|
|
2885
|
-
const message = {
|
|
2886
|
-
type: CHECK_SESSION_SIGNED_OUT
|
|
2887
|
-
};
|
|
2888
|
-
window.parent.parent.postMessage(message, parent.origin);
|
|
2889
|
-
SPAUtils.setPromptNoneRequestSent(false);
|
|
2890
|
-
window.location.href = "about:blank";
|
|
2891
|
-
await SPAUtils.waitTillPageRedirect();
|
|
2892
|
-
return true;
|
|
2893
|
-
}
|
|
2894
|
-
SPAUtils.setPromptNoneRequestSent(false);
|
|
2895
|
-
const signOutURL = await _signOut();
|
|
2896
|
-
await import_javascript4.AsgardeoAuthClient.clearSession();
|
|
2897
|
-
parent.location.href = signOutURL;
|
|
2898
|
-
window.location.href = "about:blank";
|
|
2899
|
-
await SPAUtils.waitTillPageRedirect();
|
|
2900
|
-
return true;
|
|
2386
|
+
SPAUtils.setPromptNoneRequestSent(false);
|
|
2387
|
+
const signOutURL = await _signOut();
|
|
2388
|
+
await import_javascript2.AsgardeoAuthClient.clearSession();
|
|
2389
|
+
parent.location.href = signOutURL;
|
|
2390
|
+
window.location.href = "about:blank";
|
|
2391
|
+
await SPAUtils.waitTillPageRedirect();
|
|
2392
|
+
return true;
|
|
2901
2393
|
}
|
|
2902
2394
|
}
|
|
2903
2395
|
return false;
|
|
@@ -2942,6 +2434,55 @@ var SessionManagementHelper = /* @__PURE__ */ (() => {
|
|
|
2942
2434
|
};
|
|
2943
2435
|
})();
|
|
2944
2436
|
|
|
2437
|
+
// src/__legacy__/helpers/spa-helper.ts
|
|
2438
|
+
var import_javascript3 = require("@asgardeo/javascript");
|
|
2439
|
+
var SPAHelper = class {
|
|
2440
|
+
constructor(authClient) {
|
|
2441
|
+
__publicField(this, "_authenticationClient");
|
|
2442
|
+
__publicField(this, "_storageManager");
|
|
2443
|
+
this._authenticationClient = authClient;
|
|
2444
|
+
this._storageManager = this._authenticationClient.getStorageManager();
|
|
2445
|
+
}
|
|
2446
|
+
async refreshAccessTokenAutomatically(authenticationHelper) {
|
|
2447
|
+
const shouldRefreshAutomatically = (await this._storageManager.getConfigData())?.periodicTokenRefresh ?? false;
|
|
2448
|
+
if (!shouldRefreshAutomatically) {
|
|
2449
|
+
return;
|
|
2450
|
+
}
|
|
2451
|
+
const sessionData = await this._storageManager.getSessionData();
|
|
2452
|
+
if (sessionData.refresh_token) {
|
|
2453
|
+
const expiryTime = parseInt(sessionData.expires_in);
|
|
2454
|
+
const time = expiryTime <= 10 ? expiryTime : expiryTime - 10;
|
|
2455
|
+
const timer = setTimeout(async () => {
|
|
2456
|
+
await authenticationHelper.refreshAccessToken();
|
|
2457
|
+
}, time * 1e3);
|
|
2458
|
+
await this._storageManager.setTemporaryDataParameter(
|
|
2459
|
+
import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER,
|
|
2460
|
+
JSON.stringify(timer)
|
|
2461
|
+
);
|
|
2462
|
+
}
|
|
2463
|
+
}
|
|
2464
|
+
async getRefreshTimeoutTimer() {
|
|
2465
|
+
if (await this._storageManager.getTemporaryDataParameter(import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER)) {
|
|
2466
|
+
return JSON.parse(
|
|
2467
|
+
await this._storageManager.getTemporaryDataParameter(
|
|
2468
|
+
import_javascript3.TokenConstants.Storage.StorageKeys.REFRESH_TOKEN_TIMER
|
|
2469
|
+
)
|
|
2470
|
+
);
|
|
2471
|
+
}
|
|
2472
|
+
return -1;
|
|
2473
|
+
}
|
|
2474
|
+
async clearRefreshTokenTimeout(timer) {
|
|
2475
|
+
if (timer) {
|
|
2476
|
+
clearTimeout(timer);
|
|
2477
|
+
return;
|
|
2478
|
+
}
|
|
2479
|
+
const refreshTimer = await this.getRefreshTimeoutTimer();
|
|
2480
|
+
if (refreshTimer !== -1) {
|
|
2481
|
+
clearTimeout(refreshTimer);
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
|
|
2945
2486
|
// src/__legacy__/http-client/clients/axios-http-client.ts
|
|
2946
2487
|
var import_axios = __toESM(require("axios"), 1);
|
|
2947
2488
|
|
|
@@ -3094,456 +2635,873 @@ var HttpClient = class {
|
|
|
3094
2635
|
HttpClient.isHandlerEnabled = false;
|
|
3095
2636
|
}
|
|
3096
2637
|
/**
|
|
3097
|
-
* Disables the handler for a given period of time.
|
|
2638
|
+
* Disables the handler for a given period of time.
|
|
2639
|
+
*
|
|
2640
|
+
* @param {number} timeout - Timeout in milliseconds.
|
|
2641
|
+
*/
|
|
2642
|
+
disableHandlerWithTimeout(timeout = HttpClient.DEFAULT_HANDLER_DISABLE_TIMEOUT) {
|
|
2643
|
+
HttpClient.isHandlerEnabled = false;
|
|
2644
|
+
setTimeout(() => {
|
|
2645
|
+
HttpClient.isHandlerEnabled = true;
|
|
2646
|
+
}, timeout);
|
|
2647
|
+
}
|
|
2648
|
+
setHttpRequestStartCallback(callback) {
|
|
2649
|
+
this.requestStartCallback = callback;
|
|
2650
|
+
}
|
|
2651
|
+
setHttpRequestSuccessCallback(callback) {
|
|
2652
|
+
this.requestSuccessCallback = callback;
|
|
2653
|
+
}
|
|
2654
|
+
setHttpRequestErrorCallback(callback) {
|
|
2655
|
+
this.requestErrorCallback = callback;
|
|
2656
|
+
}
|
|
2657
|
+
setHttpRequestFinishCallback(callback) {
|
|
2658
|
+
this.requestFinishCallback = callback;
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
__publicField(HttpClient, "axiosInstance");
|
|
2662
|
+
__publicField(HttpClient, "clientInstance");
|
|
2663
|
+
__publicField(HttpClient, "isHandlerEnabled");
|
|
2664
|
+
__publicField(HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
|
|
2665
|
+
HttpClient = __decorateClass([
|
|
2666
|
+
staticDecorator()
|
|
2667
|
+
], HttpClient);
|
|
2668
|
+
|
|
2669
|
+
// src/__legacy__/stores/local-store.ts
|
|
2670
|
+
var LocalStore = class {
|
|
2671
|
+
async setData(key, value) {
|
|
2672
|
+
localStorage.setItem(key, value);
|
|
2673
|
+
}
|
|
2674
|
+
async getData(key) {
|
|
2675
|
+
return localStorage.getItem(key) ?? "{}";
|
|
2676
|
+
}
|
|
2677
|
+
async removeData(key) {
|
|
2678
|
+
localStorage.removeItem(key);
|
|
2679
|
+
}
|
|
2680
|
+
};
|
|
2681
|
+
|
|
2682
|
+
// src/__legacy__/stores/memory-store.ts
|
|
2683
|
+
var MemoryStore = class {
|
|
2684
|
+
constructor() {
|
|
2685
|
+
__publicField(this, "_data");
|
|
2686
|
+
this._data = /* @__PURE__ */ new Map();
|
|
2687
|
+
}
|
|
2688
|
+
async setData(key, value) {
|
|
2689
|
+
this._data.set(key, value);
|
|
2690
|
+
}
|
|
2691
|
+
async getData(key) {
|
|
2692
|
+
return this._data?.get(key) ?? "{}";
|
|
2693
|
+
}
|
|
2694
|
+
async removeData(key) {
|
|
2695
|
+
this._data.delete(key);
|
|
2696
|
+
}
|
|
2697
|
+
};
|
|
2698
|
+
|
|
2699
|
+
// src/__legacy__/stores/session-store.ts
|
|
2700
|
+
var SessionStore = class {
|
|
2701
|
+
async setData(key, value) {
|
|
2702
|
+
sessionStorage.setItem(key, value);
|
|
2703
|
+
}
|
|
2704
|
+
async getData(key) {
|
|
2705
|
+
return sessionStorage.getItem(key) ?? "{}";
|
|
2706
|
+
}
|
|
2707
|
+
async removeData(key) {
|
|
2708
|
+
sessionStorage.removeItem(key);
|
|
2709
|
+
}
|
|
2710
|
+
};
|
|
2711
|
+
|
|
2712
|
+
// src/__legacy__/utils/crypto-utils.ts
|
|
2713
|
+
var import_buffer = __toESM(require_buffer(), 1);
|
|
2714
|
+
var import_javascript4 = require("@asgardeo/javascript");
|
|
2715
|
+
var import_base64url = __toESM(require("base64url"), 1);
|
|
2716
|
+
var import_fast_sha256 = __toESM(require("fast-sha256"), 1);
|
|
2717
|
+
var import_jose = require("jose");
|
|
2718
|
+
var import_randombytes = __toESM(require_browser(), 1);
|
|
2719
|
+
var SPACryptoUtils = class {
|
|
2720
|
+
/**
|
|
2721
|
+
* Get URL encoded string.
|
|
3098
2722
|
*
|
|
3099
|
-
* @
|
|
2723
|
+
* @returns {string} base 64 url encoded value.
|
|
3100
2724
|
*/
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
setTimeout(() => {
|
|
3104
|
-
HttpClient.isHandlerEnabled = true;
|
|
3105
|
-
}, timeout);
|
|
2725
|
+
base64URLEncode(value) {
|
|
2726
|
+
return import_base64url.default.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
3106
2727
|
}
|
|
3107
|
-
|
|
3108
|
-
|
|
2728
|
+
base64URLDecode(value) {
|
|
2729
|
+
return import_base64url.default.decode(value).toString();
|
|
3109
2730
|
}
|
|
3110
|
-
|
|
3111
|
-
|
|
2731
|
+
hashSha256(data) {
|
|
2732
|
+
return import_buffer.Buffer.from((0, import_fast_sha256.default)(new TextEncoder().encode(data)));
|
|
3112
2733
|
}
|
|
3113
|
-
|
|
3114
|
-
|
|
2734
|
+
generateRandomBytes(length) {
|
|
2735
|
+
return (0, import_randombytes.default)(length);
|
|
3115
2736
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
2737
|
+
verifyJwt(idToken, jwk, algorithms, clientId, issuer, subject, clockTolerance, validateJwtIssuer) {
|
|
2738
|
+
const jwtVerifyOptions = {
|
|
2739
|
+
algorithms,
|
|
2740
|
+
audience: clientId,
|
|
2741
|
+
clockTolerance,
|
|
2742
|
+
subject
|
|
2743
|
+
};
|
|
2744
|
+
if (validateJwtIssuer ?? true) {
|
|
2745
|
+
jwtVerifyOptions["issuer"] = issuer;
|
|
2746
|
+
}
|
|
2747
|
+
return (0, import_jose.jwtVerify)(
|
|
2748
|
+
idToken,
|
|
2749
|
+
(0, import_jose.createLocalJWKSet)({
|
|
2750
|
+
keys: [jwk]
|
|
2751
|
+
}),
|
|
2752
|
+
jwtVerifyOptions
|
|
2753
|
+
).then(() => {
|
|
2754
|
+
return Promise.resolve(true);
|
|
2755
|
+
}).catch((error) => {
|
|
2756
|
+
return Promise.reject(
|
|
2757
|
+
new import_javascript4.AsgardeoAuthException(
|
|
2758
|
+
"SPA-CRYPTO-UTILS-VJ-IV01",
|
|
2759
|
+
error?.reason ?? JSON.stringify(error),
|
|
2760
|
+
`${error?.code} ${error?.claim}`
|
|
2761
|
+
)
|
|
2762
|
+
);
|
|
2763
|
+
});
|
|
3118
2764
|
}
|
|
3119
2765
|
};
|
|
3120
|
-
__publicField(HttpClient, "axiosInstance");
|
|
3121
|
-
__publicField(HttpClient, "clientInstance");
|
|
3122
|
-
__publicField(HttpClient, "isHandlerEnabled");
|
|
3123
|
-
__publicField(HttpClient, "DEFAULT_HANDLER_DISABLE_TIMEOUT", 1e3);
|
|
3124
|
-
HttpClient = __decorateClass([
|
|
3125
|
-
staticDecorator()
|
|
3126
|
-
], HttpClient);
|
|
3127
2766
|
|
|
3128
|
-
// src/__legacy__/
|
|
3129
|
-
var
|
|
3130
|
-
|
|
3131
|
-
localStorage
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
2767
|
+
// src/__legacy__/clients/main-thread-client.ts
|
|
2768
|
+
var initiateStore = (store) => {
|
|
2769
|
+
switch (store) {
|
|
2770
|
+
case "localStorage" /* LocalStorage */:
|
|
2771
|
+
return new LocalStore();
|
|
2772
|
+
case "sessionStorage" /* SessionStorage */:
|
|
2773
|
+
return new SessionStore();
|
|
2774
|
+
case "browserMemory" /* BrowserMemory */:
|
|
2775
|
+
return new MemoryStore();
|
|
2776
|
+
default:
|
|
2777
|
+
return new SessionStore();
|
|
3138
2778
|
}
|
|
3139
2779
|
};
|
|
2780
|
+
var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
2781
|
+
const _store = initiateStore(config.storage);
|
|
2782
|
+
const _cryptoUtils = new SPACryptoUtils();
|
|
2783
|
+
const _authenticationClient = new import_javascript5.AsgardeoAuthClient();
|
|
2784
|
+
await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
|
|
2785
|
+
const _spaHelper = new SPAHelper(_authenticationClient);
|
|
2786
|
+
const _dataLayer = _authenticationClient.getStorageManager();
|
|
2787
|
+
const _sessionManagementHelper = await SessionManagementHelper(
|
|
2788
|
+
async () => _authenticationClient.getSignOutUrl(),
|
|
2789
|
+
config.storage ?? "sessionStorage" /* SessionStorage */,
|
|
2790
|
+
(sessionState) => _dataLayer.setSessionDataParameter(
|
|
2791
|
+
import_javascript5.OIDCRequestConstants.Params.SESSION_STATE,
|
|
2792
|
+
sessionState ?? ""
|
|
2793
|
+
)
|
|
2794
|
+
);
|
|
2795
|
+
const _authenticationHelper = getAuthHelper(_authenticationClient, _spaHelper);
|
|
2796
|
+
let _getSignOutURLFromSessionStorage = false;
|
|
2797
|
+
const _httpClient = HttpClient.getInstance();
|
|
2798
|
+
let _isHttpHandlerEnabled = true;
|
|
2799
|
+
let _httpErrorCallback;
|
|
2800
|
+
let _httpFinishCallback;
|
|
2801
|
+
const attachToken = async (request) => {
|
|
2802
|
+
await _authenticationHelper.attachTokenToRequestConfig(request);
|
|
2803
|
+
};
|
|
2804
|
+
_httpClient?.init && await _httpClient.init(true, attachToken);
|
|
2805
|
+
const setHttpRequestStartCallback = (callback) => {
|
|
2806
|
+
_httpClient?.setHttpRequestStartCallback && _httpClient.setHttpRequestStartCallback(callback);
|
|
2807
|
+
};
|
|
2808
|
+
const setHttpRequestSuccessCallback = (callback) => {
|
|
2809
|
+
_httpClient?.setHttpRequestSuccessCallback && _httpClient.setHttpRequestSuccessCallback(callback);
|
|
2810
|
+
};
|
|
2811
|
+
const setHttpRequestFinishCallback = (callback) => {
|
|
2812
|
+
_httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
|
|
2813
|
+
};
|
|
2814
|
+
const setHttpRequestErrorCallback = (callback) => {
|
|
2815
|
+
_httpErrorCallback = callback;
|
|
2816
|
+
};
|
|
2817
|
+
const httpRequest = async (requestConfig) => _authenticationHelper.httpRequest(
|
|
2818
|
+
_httpClient,
|
|
2819
|
+
requestConfig,
|
|
2820
|
+
_isHttpHandlerEnabled,
|
|
2821
|
+
_httpErrorCallback,
|
|
2822
|
+
_httpFinishCallback
|
|
2823
|
+
);
|
|
2824
|
+
const httpRequestAll = async (requestConfigs) => _authenticationHelper.httpRequestAll(
|
|
2825
|
+
requestConfigs,
|
|
2826
|
+
_httpClient,
|
|
2827
|
+
_isHttpHandlerEnabled,
|
|
2828
|
+
_httpErrorCallback,
|
|
2829
|
+
_httpFinishCallback
|
|
2830
|
+
);
|
|
2831
|
+
const getHttpClient = () => _httpClient;
|
|
2832
|
+
const enableHttpHandler = () => {
|
|
2833
|
+
_authenticationHelper.enableHttpHandler(_httpClient);
|
|
2834
|
+
_isHttpHandlerEnabled = true;
|
|
2835
|
+
return true;
|
|
2836
|
+
};
|
|
2837
|
+
const disableHttpHandler = () => {
|
|
2838
|
+
_authenticationHelper.disableHttpHandler(_httpClient);
|
|
2839
|
+
_isHttpHandlerEnabled = false;
|
|
2840
|
+
return true;
|
|
2841
|
+
};
|
|
2842
|
+
const checkSession = async () => {
|
|
2843
|
+
const oidcEndpoints = await _authenticationClient.getOpenIDProviderEndpoints();
|
|
2844
|
+
const config2 = await _dataLayer.getConfigData();
|
|
2845
|
+
_authenticationHelper.initializeSessionManger(
|
|
2846
|
+
config2,
|
|
2847
|
+
oidcEndpoints,
|
|
2848
|
+
async () => (await _authenticationClient.getUserSession()).sessionState,
|
|
2849
|
+
async (params) => _authenticationClient.getSignInUrl(params),
|
|
2850
|
+
_sessionManagementHelper
|
|
2851
|
+
);
|
|
2852
|
+
};
|
|
2853
|
+
const shouldStopAuthn = async () => _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
|
|
2854
|
+
await _dataLayer.setSessionDataParameter(
|
|
2855
|
+
import_javascript5.OIDCRequestConstants.Params.SESSION_STATE,
|
|
2856
|
+
sessionState ?? ""
|
|
2857
|
+
);
|
|
2858
|
+
});
|
|
2859
|
+
const setSessionStatus = async (sessionStatus) => {
|
|
2860
|
+
await _dataLayer.setSessionStatus(sessionStatus);
|
|
2861
|
+
};
|
|
2862
|
+
const signIn = async (signInConfig, authorizationCode, sessionState, state, tokenRequestConfig) => {
|
|
2863
|
+
const basicUserInfo = await _authenticationHelper.handleSignIn(shouldStopAuthn, checkSession, void 0);
|
|
2864
|
+
if (basicUserInfo) {
|
|
2865
|
+
return basicUserInfo;
|
|
2866
|
+
}
|
|
2867
|
+
let resolvedAuthorizationCode;
|
|
2868
|
+
let resolvedSessionState;
|
|
2869
|
+
let resolvedState;
|
|
2870
|
+
let resolvedTokenRequestConfig = { params: {} };
|
|
2871
|
+
if (config?.responseMode === "form_post" && authorizationCode) {
|
|
2872
|
+
resolvedAuthorizationCode = authorizationCode;
|
|
2873
|
+
resolvedSessionState = sessionState ?? "";
|
|
2874
|
+
resolvedState = state ?? "";
|
|
2875
|
+
} else {
|
|
2876
|
+
resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(import_javascript5.OIDCRequestConstants.Params.AUTHORIZATION_CODE) ?? "";
|
|
2877
|
+
resolvedSessionState = new URL(window.location.href).searchParams.get(import_javascript5.OIDCRequestConstants.Params.SESSION_STATE) ?? "";
|
|
2878
|
+
resolvedState = new URL(window.location.href).searchParams.get(import_javascript5.OIDCRequestConstants.Params.STATE) ?? "";
|
|
2879
|
+
SPAUtils.removeAuthorizationCode();
|
|
2880
|
+
}
|
|
2881
|
+
if (resolvedAuthorizationCode && resolvedState) {
|
|
2882
|
+
setSessionStatus("true");
|
|
2883
|
+
const storedTokenRequestConfig = await _dataLayer.getTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY);
|
|
2884
|
+
if (storedTokenRequestConfig && typeof storedTokenRequestConfig === "string") {
|
|
2885
|
+
resolvedTokenRequestConfig = JSON.parse(storedTokenRequestConfig);
|
|
2886
|
+
}
|
|
2887
|
+
return requestAccessToken(
|
|
2888
|
+
resolvedAuthorizationCode,
|
|
2889
|
+
resolvedSessionState,
|
|
2890
|
+
resolvedState,
|
|
2891
|
+
resolvedTokenRequestConfig
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
return _authenticationClient.getSignInUrl(signInConfig).then(async (url) => {
|
|
2895
|
+
if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE) {
|
|
2896
|
+
const pkceKey = (0, import_javascript5.extractPkceStorageKeyFromState)(resolvedState);
|
|
2897
|
+
SPAUtils.setPKCE(pkceKey, await _authenticationClient.getPKCECode(resolvedState));
|
|
2898
|
+
}
|
|
2899
|
+
if (tokenRequestConfig) {
|
|
2900
|
+
_dataLayer.setTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY, JSON.stringify(tokenRequestConfig));
|
|
2901
|
+
}
|
|
2902
|
+
if (signInConfig && signInConfig["response_mode"] === "direct") {
|
|
2903
|
+
const authorizeUrl = new URL(url);
|
|
2904
|
+
return (0, import_javascript5.initializeEmbeddedSignInFlow)({
|
|
2905
|
+
url: `${authorizeUrl.origin}${authorizeUrl.pathname}`,
|
|
2906
|
+
payload: Object.fromEntries(authorizeUrl.searchParams.entries())
|
|
2907
|
+
});
|
|
2908
|
+
}
|
|
2909
|
+
location.href = url;
|
|
2910
|
+
await SPAUtils.waitTillPageRedirect();
|
|
2911
|
+
return Promise.resolve({
|
|
2912
|
+
allowedScopes: "",
|
|
2913
|
+
displayName: "",
|
|
2914
|
+
email: "",
|
|
2915
|
+
sessionState: "",
|
|
2916
|
+
sub: "",
|
|
2917
|
+
tenantDomain: "",
|
|
2918
|
+
username: ""
|
|
2919
|
+
});
|
|
2920
|
+
});
|
|
2921
|
+
};
|
|
2922
|
+
const signOut = async () => {
|
|
2923
|
+
if (await _authenticationClient.isSignedIn() && !_getSignOutURLFromSessionStorage) {
|
|
2924
|
+
location.href = await _authenticationClient.getSignOutUrl();
|
|
2925
|
+
} else {
|
|
2926
|
+
location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
|
|
2927
|
+
}
|
|
2928
|
+
_spaHelper.clearRefreshTokenTimeout();
|
|
2929
|
+
await _dataLayer.removeOIDCProviderMetaData();
|
|
2930
|
+
await _dataLayer.removeTemporaryData();
|
|
2931
|
+
await _dataLayer.removeSessionData();
|
|
2932
|
+
await _dataLayer.removeSessionStatus();
|
|
2933
|
+
await SPAUtils.waitTillPageRedirect();
|
|
2934
|
+
return true;
|
|
2935
|
+
};
|
|
2936
|
+
const enableRetrievingSignOutURLFromSession = (config2) => {
|
|
2937
|
+
if (config2.preventSignOutURLUpdate) {
|
|
2938
|
+
_getSignOutURLFromSessionStorage = true;
|
|
2939
|
+
}
|
|
2940
|
+
};
|
|
2941
|
+
const exchangeToken = async (config2) => _authenticationHelper.exchangeToken(config2, enableRetrievingSignOutURLFromSession);
|
|
2942
|
+
const refreshAccessToken = async () => {
|
|
2943
|
+
try {
|
|
2944
|
+
return await _authenticationHelper.refreshAccessToken(enableRetrievingSignOutURLFromSession);
|
|
2945
|
+
} catch (error) {
|
|
2946
|
+
return Promise.reject(error);
|
|
2947
|
+
}
|
|
2948
|
+
};
|
|
2949
|
+
const revokeAccessToken = async () => {
|
|
2950
|
+
const timer = await _spaHelper.getRefreshTimeoutTimer();
|
|
2951
|
+
return _authenticationClient.revokeAccessToken().then(() => {
|
|
2952
|
+
_sessionManagementHelper.reset();
|
|
2953
|
+
_spaHelper.clearRefreshTokenTimeout(timer);
|
|
2954
|
+
return Promise.resolve(true);
|
|
2955
|
+
}).catch((error) => Promise.reject(error));
|
|
2956
|
+
};
|
|
2957
|
+
const requestAccessToken = async (resolvedAuthorizationCode, resolvedSessionState, resolvedState, tokenRequestConfig) => _authenticationHelper.requestAccessToken(
|
|
2958
|
+
resolvedAuthorizationCode,
|
|
2959
|
+
resolvedSessionState,
|
|
2960
|
+
checkSession,
|
|
2961
|
+
void 0,
|
|
2962
|
+
resolvedState,
|
|
2963
|
+
tokenRequestConfig
|
|
2964
|
+
);
|
|
2965
|
+
const constructSilentSignInUrl = async (additionalParams = {}) => {
|
|
2966
|
+
const config2 = await _dataLayer.getConfigData();
|
|
2967
|
+
const urlString = await _authenticationClient.getSignInUrl({
|
|
2968
|
+
prompt: "none",
|
|
2969
|
+
state: SILENT_SIGN_IN_STATE,
|
|
2970
|
+
...additionalParams
|
|
2971
|
+
});
|
|
2972
|
+
const urlObject = new URL(urlString);
|
|
2973
|
+
urlObject.searchParams.set("response_mode", "query");
|
|
2974
|
+
const url = urlObject.toString();
|
|
2975
|
+
if (config2.storage === "browserMemory" /* BrowserMemory */ && config2.enablePKCE) {
|
|
2976
|
+
const state = urlObject.searchParams.get(import_javascript5.OIDCRequestConstants.Params.STATE);
|
|
2977
|
+
SPAUtils.setPKCE(
|
|
2978
|
+
(0, import_javascript5.extractPkceStorageKeyFromState)(state ?? ""),
|
|
2979
|
+
await _authenticationClient.getPKCECode(state ?? "")
|
|
2980
|
+
);
|
|
2981
|
+
}
|
|
2982
|
+
return url;
|
|
2983
|
+
};
|
|
2984
|
+
const trySignInSilently = async (additionalParams, tokenRequestConfig) => _authenticationHelper.trySignInSilently(
|
|
2985
|
+
constructSilentSignInUrl,
|
|
2986
|
+
requestAccessToken,
|
|
2987
|
+
_sessionManagementHelper,
|
|
2988
|
+
additionalParams,
|
|
2989
|
+
tokenRequestConfig
|
|
2990
|
+
);
|
|
2991
|
+
const getUser = async () => _authenticationHelper.getUser();
|
|
2992
|
+
const getDecodedIdToken = async (sessionId) => _authenticationHelper.getDecodedIdToken(sessionId);
|
|
2993
|
+
const getCrypto = async () => _authenticationHelper.getCrypto();
|
|
2994
|
+
const getIdToken = async () => _authenticationHelper.getIdToken();
|
|
2995
|
+
const getOpenIDProviderEndpoints = async () => _authenticationHelper.getOpenIDProviderEndpoints();
|
|
2996
|
+
const getAccessToken = async () => _authenticationHelper.getAccessToken();
|
|
2997
|
+
const getStorageManager = async () => _authenticationHelper.getStorageManager();
|
|
2998
|
+
const getConfigData = async () => _dataLayer.getConfigData();
|
|
2999
|
+
const isSignedIn = async () => _authenticationHelper.isSignedIn();
|
|
3000
|
+
const isSessionActive = async () => await _dataLayer.getSessionStatus() === "true";
|
|
3001
|
+
const reInitialize = async (newConfig) => {
|
|
3002
|
+
const existingConfig = await _dataLayer.getConfigData();
|
|
3003
|
+
const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
|
|
3004
|
+
const config2 = { ...existingConfig, ...newConfig };
|
|
3005
|
+
await _authenticationClient.reInitialize(config2);
|
|
3006
|
+
if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
|
|
3007
|
+
_sessionManagementHelper.reset();
|
|
3008
|
+
checkSession();
|
|
3009
|
+
}
|
|
3010
|
+
};
|
|
3011
|
+
return {
|
|
3012
|
+
disableHttpHandler,
|
|
3013
|
+
enableHttpHandler,
|
|
3014
|
+
getAccessToken,
|
|
3015
|
+
getUser,
|
|
3016
|
+
getConfigData,
|
|
3017
|
+
getCrypto,
|
|
3018
|
+
getStorageManager,
|
|
3019
|
+
getDecodedIdToken,
|
|
3020
|
+
getHttpClient,
|
|
3021
|
+
getIdToken,
|
|
3022
|
+
getOpenIDProviderEndpoints,
|
|
3023
|
+
httpRequest,
|
|
3024
|
+
httpRequestAll,
|
|
3025
|
+
isSignedIn,
|
|
3026
|
+
isSessionActive,
|
|
3027
|
+
refreshAccessToken,
|
|
3028
|
+
exchangeToken,
|
|
3029
|
+
revokeAccessToken,
|
|
3030
|
+
setHttpRequestErrorCallback,
|
|
3031
|
+
setHttpRequestFinishCallback,
|
|
3032
|
+
setHttpRequestStartCallback,
|
|
3033
|
+
setHttpRequestSuccessCallback,
|
|
3034
|
+
signIn,
|
|
3035
|
+
signOut,
|
|
3036
|
+
trySignInSilently,
|
|
3037
|
+
reInitialize
|
|
3038
|
+
};
|
|
3039
|
+
};
|
|
3140
3040
|
|
|
3141
|
-
// src/__legacy__/
|
|
3142
|
-
var
|
|
3143
|
-
constructor() {
|
|
3144
|
-
__publicField(this, "_data");
|
|
3145
|
-
this._data = /* @__PURE__ */ new Map();
|
|
3146
|
-
}
|
|
3147
|
-
async setData(key, value) {
|
|
3148
|
-
this._data.set(key, value);
|
|
3149
|
-
}
|
|
3150
|
-
async getData(key) {
|
|
3151
|
-
return this._data?.get(key) ?? "{}";
|
|
3152
|
-
}
|
|
3153
|
-
async removeData(key) {
|
|
3154
|
-
this._data.delete(key);
|
|
3155
|
-
}
|
|
3156
|
-
};
|
|
3041
|
+
// src/__legacy__/clients/web-worker-client.ts
|
|
3042
|
+
var import_javascript7 = require("@asgardeo/javascript");
|
|
3157
3043
|
|
|
3158
|
-
// src/__legacy__/
|
|
3159
|
-
var
|
|
3160
|
-
|
|
3161
|
-
|
|
3044
|
+
// src/__legacy__/helpers/authentication-helper.ts
|
|
3045
|
+
var import_javascript6 = require("@asgardeo/javascript");
|
|
3046
|
+
var AuthenticationHelper = class {
|
|
3047
|
+
constructor(authClient, spaHelper) {
|
|
3048
|
+
__publicField(this, "_authenticationClient");
|
|
3049
|
+
__publicField(this, "_storageManager");
|
|
3050
|
+
__publicField(this, "_spaHelper");
|
|
3051
|
+
__publicField(this, "_instanceID");
|
|
3052
|
+
__publicField(this, "_isTokenRefreshing");
|
|
3053
|
+
this._authenticationClient = authClient;
|
|
3054
|
+
this._storageManager = this._authenticationClient.getStorageManager();
|
|
3055
|
+
this._spaHelper = spaHelper;
|
|
3056
|
+
this._instanceID = this._authenticationClient.getInstanceId();
|
|
3057
|
+
this._isTokenRefreshing = false;
|
|
3162
3058
|
}
|
|
3163
|
-
|
|
3164
|
-
|
|
3059
|
+
enableHttpHandler(httpClient) {
|
|
3060
|
+
httpClient?.enableHandler && httpClient.enableHandler();
|
|
3165
3061
|
}
|
|
3166
|
-
|
|
3167
|
-
|
|
3062
|
+
disableHttpHandler(httpClient) {
|
|
3063
|
+
httpClient?.disableHandler && httpClient.disableHandler();
|
|
3168
3064
|
}
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
/**
|
|
3180
|
-
* Get URL encoded string.
|
|
3181
|
-
*
|
|
3182
|
-
* @returns {string} base 64 url encoded value.
|
|
3183
|
-
*/
|
|
3184
|
-
base64URLEncode(value) {
|
|
3185
|
-
return import_base64url.default.encode(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
|
|
3065
|
+
initializeSessionManger(config, oidcEndpoints, getSessionState, getAuthzURL, sessionManagementHelper) {
|
|
3066
|
+
sessionManagementHelper.initialize(
|
|
3067
|
+
config.clientId,
|
|
3068
|
+
oidcEndpoints.checkSessionIframe ?? "",
|
|
3069
|
+
getSessionState,
|
|
3070
|
+
config.checkSessionInterval ?? 3,
|
|
3071
|
+
config.sessionRefreshInterval ?? 300,
|
|
3072
|
+
config.afterSignInUrl,
|
|
3073
|
+
getAuthzURL
|
|
3074
|
+
);
|
|
3186
3075
|
}
|
|
3187
|
-
|
|
3188
|
-
|
|
3076
|
+
async exchangeToken(config, enableRetrievingSignOutURLFromSession) {
|
|
3077
|
+
let useDefaultEndpoint = true;
|
|
3078
|
+
let matches = false;
|
|
3079
|
+
if (config?.tokenEndpoint) {
|
|
3080
|
+
useDefaultEndpoint = false;
|
|
3081
|
+
for (const baseUrl of [
|
|
3082
|
+
...(await this._storageManager.getConfigData())?.resourceServerURLs ?? [],
|
|
3083
|
+
config.baseUrl
|
|
3084
|
+
]) {
|
|
3085
|
+
if (baseUrl && config.tokenEndpoint?.startsWith(baseUrl)) {
|
|
3086
|
+
matches = true;
|
|
3087
|
+
break;
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
if (config.shouldReplayAfterRefresh) {
|
|
3092
|
+
this._storageManager.setTemporaryDataParameter(CUSTOM_GRANT_CONFIG, JSON.stringify(config));
|
|
3093
|
+
}
|
|
3094
|
+
if (useDefaultEndpoint || matches) {
|
|
3095
|
+
return this._authenticationClient.exchangeToken(config).then(async (response) => {
|
|
3096
|
+
if (enableRetrievingSignOutURLFromSession && typeof enableRetrievingSignOutURLFromSession === "function") {
|
|
3097
|
+
enableRetrievingSignOutURLFromSession(config);
|
|
3098
|
+
}
|
|
3099
|
+
if (config.returnsSession) {
|
|
3100
|
+
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
3101
|
+
return this._authenticationClient.getUser();
|
|
3102
|
+
} else {
|
|
3103
|
+
return response;
|
|
3104
|
+
}
|
|
3105
|
+
}).catch((error) => {
|
|
3106
|
+
return Promise.reject(error);
|
|
3107
|
+
});
|
|
3108
|
+
} else {
|
|
3109
|
+
return Promise.reject(
|
|
3110
|
+
new import_javascript6.AsgardeoAuthException(
|
|
3111
|
+
"SPA-MAIN_THREAD_CLIENT-RCG-IV01",
|
|
3112
|
+
"Request to the provided endpoint is prohibited.",
|
|
3113
|
+
"Requests can only be sent to resource servers specified by the `resourceServerURLs` attribute while initializing the SDK. The specified token endpoint in this request cannot be found among the `resourceServerURLs`"
|
|
3114
|
+
)
|
|
3115
|
+
);
|
|
3116
|
+
}
|
|
3189
3117
|
}
|
|
3190
|
-
|
|
3191
|
-
|
|
3118
|
+
async getCustomGrantConfigData() {
|
|
3119
|
+
const configString = await this._storageManager.getTemporaryDataParameter(CUSTOM_GRANT_CONFIG);
|
|
3120
|
+
if (configString) {
|
|
3121
|
+
return JSON.parse(configString);
|
|
3122
|
+
} else {
|
|
3123
|
+
return null;
|
|
3124
|
+
}
|
|
3192
3125
|
}
|
|
3193
|
-
|
|
3194
|
-
|
|
3126
|
+
async refreshAccessToken(enableRetrievingSignOutURLFromSession) {
|
|
3127
|
+
try {
|
|
3128
|
+
await this._authenticationClient.refreshAccessToken();
|
|
3129
|
+
const customGrantConfig = await this.getCustomGrantConfigData();
|
|
3130
|
+
if (customGrantConfig) {
|
|
3131
|
+
await this.exchangeToken(customGrantConfig, enableRetrievingSignOutURLFromSession);
|
|
3132
|
+
}
|
|
3133
|
+
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
3134
|
+
return this._authenticationClient.getUser();
|
|
3135
|
+
} catch (error) {
|
|
3136
|
+
const refreshTokenError = {
|
|
3137
|
+
type: REFRESH_ACCESS_TOKEN_ERR0R
|
|
3138
|
+
};
|
|
3139
|
+
window.postMessage(refreshTokenError);
|
|
3140
|
+
return Promise.reject(error);
|
|
3141
|
+
}
|
|
3195
3142
|
}
|
|
3196
|
-
|
|
3197
|
-
const
|
|
3198
|
-
|
|
3199
|
-
|
|
3200
|
-
|
|
3201
|
-
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3143
|
+
async retryFailedRequests(failedRequest) {
|
|
3144
|
+
const httpClient = failedRequest.httpClient;
|
|
3145
|
+
const requestConfig = failedRequest.requestConfig;
|
|
3146
|
+
const isHttpHandlerEnabled = failedRequest.isHttpHandlerEnabled;
|
|
3147
|
+
const httpErrorCallback = failedRequest.httpErrorCallback;
|
|
3148
|
+
const httpFinishCallback = failedRequest.httpFinishCallback;
|
|
3149
|
+
await SPAUtils.until(() => !this._isTokenRefreshing);
|
|
3150
|
+
try {
|
|
3151
|
+
const httpResponse = await httpClient.request(requestConfig);
|
|
3152
|
+
return Promise.resolve(httpResponse);
|
|
3153
|
+
} catch (error) {
|
|
3154
|
+
if (isHttpHandlerEnabled) {
|
|
3155
|
+
if (typeof httpErrorCallback === "function") {
|
|
3156
|
+
await httpErrorCallback(error);
|
|
3157
|
+
}
|
|
3158
|
+
if (typeof httpFinishCallback === "function") {
|
|
3159
|
+
httpFinishCallback();
|
|
3160
|
+
}
|
|
3161
|
+
}
|
|
3162
|
+
return Promise.reject(error);
|
|
3205
3163
|
}
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
|
|
3213
|
-
|
|
3214
|
-
|
|
3164
|
+
}
|
|
3165
|
+
async httpRequest(httpClient, requestConfig, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback, enableRetrievingSignOutURLFromSession) {
|
|
3166
|
+
let matches = false;
|
|
3167
|
+
const config = await this._storageManager.getConfigData();
|
|
3168
|
+
for (const baseUrl of [...await config?.resourceServerURLs ?? [], config.baseUrl]) {
|
|
3169
|
+
if (baseUrl && requestConfig?.url?.startsWith(baseUrl)) {
|
|
3170
|
+
matches = true;
|
|
3171
|
+
break;
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
if (matches) {
|
|
3175
|
+
return httpClient.request(requestConfig).then((response) => {
|
|
3176
|
+
return Promise.resolve(response);
|
|
3177
|
+
}).catch(async (error) => {
|
|
3178
|
+
if (error?.response?.status === 401 || !error?.response) {
|
|
3179
|
+
if (this._isTokenRefreshing) {
|
|
3180
|
+
return this.retryFailedRequests({
|
|
3181
|
+
enableRetrievingSignOutURLFromSession,
|
|
3182
|
+
httpClient,
|
|
3183
|
+
httpErrorCallback,
|
|
3184
|
+
httpFinishCallback,
|
|
3185
|
+
isHttpHandlerEnabled,
|
|
3186
|
+
requestConfig
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
this._isTokenRefreshing = true;
|
|
3190
|
+
let refreshAccessTokenResponse;
|
|
3191
|
+
try {
|
|
3192
|
+
refreshAccessTokenResponse = await this.refreshAccessToken(enableRetrievingSignOutURLFromSession);
|
|
3193
|
+
this._isTokenRefreshing = false;
|
|
3194
|
+
} catch (refreshError) {
|
|
3195
|
+
this._isTokenRefreshing = false;
|
|
3196
|
+
if (isHttpHandlerEnabled) {
|
|
3197
|
+
if (typeof httpErrorCallback === "function") {
|
|
3198
|
+
await httpErrorCallback({
|
|
3199
|
+
...error,
|
|
3200
|
+
code: ACCESS_TOKEN_INVALID
|
|
3201
|
+
});
|
|
3202
|
+
}
|
|
3203
|
+
if (typeof httpFinishCallback === "function") {
|
|
3204
|
+
httpFinishCallback();
|
|
3205
|
+
}
|
|
3206
|
+
}
|
|
3207
|
+
throw new import_javascript6.AsgardeoAuthException(
|
|
3208
|
+
"SPA-AUTH_HELPER-HR-SE01",
|
|
3209
|
+
refreshError?.name ?? "Refresh token request failed.",
|
|
3210
|
+
refreshError?.message ?? "An error occurred while trying to refresh the access token following a 401 response from the server."
|
|
3211
|
+
);
|
|
3212
|
+
}
|
|
3213
|
+
if (refreshAccessTokenResponse) {
|
|
3214
|
+
try {
|
|
3215
|
+
const httpResponse = await httpClient.request(requestConfig);
|
|
3216
|
+
return Promise.resolve(httpResponse);
|
|
3217
|
+
} catch (error2) {
|
|
3218
|
+
if (isHttpHandlerEnabled) {
|
|
3219
|
+
if (typeof httpErrorCallback === "function") {
|
|
3220
|
+
await httpErrorCallback(error2);
|
|
3221
|
+
}
|
|
3222
|
+
if (typeof httpFinishCallback === "function") {
|
|
3223
|
+
httpFinishCallback();
|
|
3224
|
+
}
|
|
3225
|
+
}
|
|
3226
|
+
return Promise.reject(error2);
|
|
3227
|
+
}
|
|
3228
|
+
}
|
|
3229
|
+
}
|
|
3230
|
+
if (isHttpHandlerEnabled) {
|
|
3231
|
+
if (typeof httpErrorCallback === "function") {
|
|
3232
|
+
await httpErrorCallback(error);
|
|
3233
|
+
}
|
|
3234
|
+
if (typeof httpFinishCallback === "function") {
|
|
3235
|
+
httpFinishCallback();
|
|
3236
|
+
}
|
|
3237
|
+
}
|
|
3238
|
+
return Promise.reject(error);
|
|
3239
|
+
});
|
|
3240
|
+
} else {
|
|
3215
3241
|
return Promise.reject(
|
|
3216
|
-
new
|
|
3217
|
-
"SPA-
|
|
3218
|
-
|
|
3219
|
-
|
|
3242
|
+
new import_javascript6.AsgardeoAuthException(
|
|
3243
|
+
"SPA-AUTH_HELPER-HR-IV02",
|
|
3244
|
+
"Request to the provided endpoint is prohibited.",
|
|
3245
|
+
"Requests can only be sent to resource servers specified by the `resourceServerURLs` attribute while initializing the SDK. The specified endpoint in this request cannot be found among the `resourceServerURLs`"
|
|
3220
3246
|
)
|
|
3221
3247
|
);
|
|
3222
|
-
});
|
|
3223
|
-
}
|
|
3224
|
-
};
|
|
3225
|
-
|
|
3226
|
-
// src/__legacy__/clients/main-thread-client.ts
|
|
3227
|
-
var initiateStore = (store) => {
|
|
3228
|
-
switch (store) {
|
|
3229
|
-
case "localStorage" /* LocalStorage */:
|
|
3230
|
-
return new LocalStore();
|
|
3231
|
-
case "sessionStorage" /* SessionStorage */:
|
|
3232
|
-
return new SessionStore();
|
|
3233
|
-
case "browserMemory" /* BrowserMemory */:
|
|
3234
|
-
return new MemoryStore();
|
|
3235
|
-
default:
|
|
3236
|
-
return new SessionStore();
|
|
3237
|
-
}
|
|
3238
|
-
};
|
|
3239
|
-
var MainThreadClient = async (instanceID, config, getAuthHelper) => {
|
|
3240
|
-
const _store = initiateStore(config.storage);
|
|
3241
|
-
const _cryptoUtils = new SPACryptoUtils();
|
|
3242
|
-
const _authenticationClient = new import_javascript6.AsgardeoAuthClient();
|
|
3243
|
-
await _authenticationClient.initialize(config, _store, _cryptoUtils, instanceID);
|
|
3244
|
-
const _spaHelper = new SPAHelper(_authenticationClient);
|
|
3245
|
-
const _dataLayer = _authenticationClient.getStorageManager();
|
|
3246
|
-
const _sessionManagementHelper = await SessionManagementHelper(
|
|
3247
|
-
async () => {
|
|
3248
|
-
return _authenticationClient.getSignOutUrl();
|
|
3249
|
-
},
|
|
3250
|
-
config.storage ?? "sessionStorage" /* SessionStorage */,
|
|
3251
|
-
(sessionState) => _dataLayer.setSessionDataParameter(
|
|
3252
|
-
import_javascript6.OIDCRequestConstants.Params.SESSION_STATE,
|
|
3253
|
-
sessionState ?? ""
|
|
3254
|
-
)
|
|
3255
|
-
);
|
|
3256
|
-
const _authenticationHelper = getAuthHelper(_authenticationClient, _spaHelper);
|
|
3257
|
-
let _getSignOutURLFromSessionStorage = false;
|
|
3258
|
-
const _httpClient = HttpClient.getInstance();
|
|
3259
|
-
let _isHttpHandlerEnabled = true;
|
|
3260
|
-
let _httpErrorCallback;
|
|
3261
|
-
let _httpFinishCallback;
|
|
3262
|
-
const attachToken = async (request) => {
|
|
3263
|
-
await _authenticationHelper.attachTokenToRequestConfig(request);
|
|
3264
|
-
};
|
|
3265
|
-
_httpClient?.init && await _httpClient.init(true, attachToken);
|
|
3266
|
-
const setHttpRequestStartCallback = (callback) => {
|
|
3267
|
-
_httpClient?.setHttpRequestStartCallback && _httpClient.setHttpRequestStartCallback(callback);
|
|
3268
|
-
};
|
|
3269
|
-
const setHttpRequestSuccessCallback = (callback) => {
|
|
3270
|
-
_httpClient?.setHttpRequestSuccessCallback && _httpClient.setHttpRequestSuccessCallback(callback);
|
|
3271
|
-
};
|
|
3272
|
-
const setHttpRequestFinishCallback = (callback) => {
|
|
3273
|
-
_httpClient?.setHttpRequestFinishCallback && _httpClient.setHttpRequestFinishCallback(callback);
|
|
3274
|
-
};
|
|
3275
|
-
const setHttpRequestErrorCallback = (callback) => {
|
|
3276
|
-
_httpErrorCallback = callback;
|
|
3277
|
-
};
|
|
3278
|
-
const httpRequest = async (requestConfig) => {
|
|
3279
|
-
return await _authenticationHelper.httpRequest(
|
|
3280
|
-
_httpClient,
|
|
3281
|
-
requestConfig,
|
|
3282
|
-
_isHttpHandlerEnabled,
|
|
3283
|
-
_httpErrorCallback,
|
|
3284
|
-
_httpFinishCallback
|
|
3285
|
-
);
|
|
3286
|
-
};
|
|
3287
|
-
const httpRequestAll = async (requestConfigs) => {
|
|
3288
|
-
return await _authenticationHelper.httpRequestAll(
|
|
3289
|
-
requestConfigs,
|
|
3290
|
-
_httpClient,
|
|
3291
|
-
_isHttpHandlerEnabled,
|
|
3292
|
-
_httpErrorCallback,
|
|
3293
|
-
_httpFinishCallback
|
|
3294
|
-
);
|
|
3295
|
-
};
|
|
3296
|
-
const getHttpClient = () => {
|
|
3297
|
-
return _httpClient;
|
|
3298
|
-
};
|
|
3299
|
-
const enableHttpHandler = () => {
|
|
3300
|
-
_authenticationHelper.enableHttpHandler(_httpClient);
|
|
3301
|
-
_isHttpHandlerEnabled = true;
|
|
3302
|
-
return true;
|
|
3303
|
-
};
|
|
3304
|
-
const disableHttpHandler = () => {
|
|
3305
|
-
_authenticationHelper.disableHttpHandler(_httpClient);
|
|
3306
|
-
_isHttpHandlerEnabled = false;
|
|
3307
|
-
return true;
|
|
3308
|
-
};
|
|
3309
|
-
const checkSession = async () => {
|
|
3310
|
-
const oidcEndpoints = await _authenticationClient.getOpenIDProviderEndpoints();
|
|
3311
|
-
const config2 = await _dataLayer.getConfigData();
|
|
3312
|
-
_authenticationHelper.initializeSessionManger(
|
|
3313
|
-
config2,
|
|
3314
|
-
oidcEndpoints,
|
|
3315
|
-
async () => (await _authenticationClient.getUserSession()).sessionState,
|
|
3316
|
-
async (params) => _authenticationClient.getSignInUrl(params),
|
|
3317
|
-
_sessionManagementHelper
|
|
3318
|
-
);
|
|
3319
|
-
};
|
|
3320
|
-
const shouldStopAuthn = async () => {
|
|
3321
|
-
return await _sessionManagementHelper.receivePromptNoneResponse(async (sessionState) => {
|
|
3322
|
-
await _dataLayer.setSessionDataParameter(
|
|
3323
|
-
import_javascript6.OIDCRequestConstants.Params.SESSION_STATE,
|
|
3324
|
-
sessionState ?? ""
|
|
3325
|
-
);
|
|
3326
|
-
return;
|
|
3327
|
-
});
|
|
3328
|
-
};
|
|
3329
|
-
const setSessionStatus = async (sessionStatus) => {
|
|
3330
|
-
await _dataLayer.setSessionStatus(sessionStatus);
|
|
3331
|
-
};
|
|
3332
|
-
const signIn = async (signInConfig, authorizationCode, sessionState, state, tokenRequestConfig) => {
|
|
3333
|
-
if (signInConfig["flow"]) {
|
|
3334
|
-
return (0, import_javascript6.handleApplicationNativeAuthentication)({
|
|
3335
|
-
url: signInConfig["flow"]["requestConfig"]["url"],
|
|
3336
|
-
payload: signInConfig["flow"]["payload"]
|
|
3337
|
-
});
|
|
3338
3248
|
}
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
let
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
resolvedSessionState = sessionState ?? "";
|
|
3350
|
-
resolvedState = state ?? "";
|
|
3351
|
-
} else {
|
|
3352
|
-
resolvedAuthorizationCode = new URL(window.location.href).searchParams.get(import_javascript6.OIDCRequestConstants.Params.AUTHORIZATION_CODE) ?? "";
|
|
3353
|
-
resolvedSessionState = new URL(window.location.href).searchParams.get(import_javascript6.OIDCRequestConstants.Params.SESSION_STATE) ?? "";
|
|
3354
|
-
resolvedState = new URL(window.location.href).searchParams.get(import_javascript6.OIDCRequestConstants.Params.STATE) ?? "";
|
|
3355
|
-
SPAUtils.removeAuthorizationCode();
|
|
3356
|
-
}
|
|
3357
|
-
if (resolvedAuthorizationCode && resolvedState) {
|
|
3358
|
-
setSessionStatus("true");
|
|
3359
|
-
const storedTokenRequestConfig = await _dataLayer.getTemporaryDataParameter(TOKEN_REQUEST_CONFIG_KEY);
|
|
3360
|
-
if (storedTokenRequestConfig && typeof storedTokenRequestConfig === "string") {
|
|
3361
|
-
resolvedTokenRequestConfig = JSON.parse(storedTokenRequestConfig);
|
|
3249
|
+
}
|
|
3250
|
+
async httpRequestAll(requestConfigs, httpClient, isHttpHandlerEnabled, httpErrorCallback, httpFinishCallback) {
|
|
3251
|
+
let matches = true;
|
|
3252
|
+
const config = await this._storageManager.getConfigData();
|
|
3253
|
+
for (const requestConfig of requestConfigs) {
|
|
3254
|
+
let urlMatches = false;
|
|
3255
|
+
for (const baseUrl of [...(await config)?.resourceServerURLs ?? [], config.baseUrl]) {
|
|
3256
|
+
if (baseUrl && requestConfig.url?.startsWith(baseUrl)) {
|
|
3257
|
+
urlMatches = true;
|
|
3258
|
+
break;
|
|
3362
3259
|
}
|
|
3363
|
-
return requestAccessToken(
|
|
3364
|
-
resolvedAuthorizationCode,
|
|
3365
|
-
resolvedSessionState,
|
|
3366
|
-
resolvedState,
|
|
3367
|
-
resolvedTokenRequestConfig
|
|
3368
|
-
);
|
|
3369
3260
|
}
|
|
3370
|
-
|
|
3371
|
-
|
|
3372
|
-
|
|
3373
|
-
|
|
3261
|
+
if (!urlMatches) {
|
|
3262
|
+
matches = false;
|
|
3263
|
+
break;
|
|
3264
|
+
}
|
|
3265
|
+
}
|
|
3266
|
+
const requests = [];
|
|
3267
|
+
if (matches) {
|
|
3268
|
+
requestConfigs.forEach((request) => {
|
|
3269
|
+
requests.push(httpClient.request(request));
|
|
3270
|
+
});
|
|
3271
|
+
return httpClient?.all && httpClient.all(requests).then((responses) => {
|
|
3272
|
+
return Promise.resolve(responses);
|
|
3273
|
+
}).catch(async (error) => {
|
|
3274
|
+
if (error?.response?.status === 401 || !error?.response) {
|
|
3275
|
+
let refreshTokenResponse;
|
|
3276
|
+
try {
|
|
3277
|
+
refreshTokenResponse = await this._authenticationClient.refreshAccessToken();
|
|
3278
|
+
} catch (refreshError) {
|
|
3279
|
+
if (isHttpHandlerEnabled) {
|
|
3280
|
+
if (typeof httpErrorCallback === "function") {
|
|
3281
|
+
await httpErrorCallback({
|
|
3282
|
+
...error,
|
|
3283
|
+
code: ACCESS_TOKEN_INVALID
|
|
3284
|
+
});
|
|
3285
|
+
}
|
|
3286
|
+
if (typeof httpFinishCallback === "function") {
|
|
3287
|
+
httpFinishCallback();
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
throw new import_javascript6.AsgardeoAuthException(
|
|
3291
|
+
"SPA-AUTH_HELPER-HRA-SE01",
|
|
3292
|
+
refreshError?.name ?? "Refresh token request failed.",
|
|
3293
|
+
refreshError?.message ?? "An error occurred while trying to refresh the access token following a 401 response from the server."
|
|
3294
|
+
);
|
|
3295
|
+
}
|
|
3296
|
+
if (refreshTokenResponse) {
|
|
3297
|
+
return httpClient.all && httpClient.all(requests).then((response) => {
|
|
3298
|
+
return Promise.resolve(response);
|
|
3299
|
+
}).catch(async (error2) => {
|
|
3300
|
+
if (isHttpHandlerEnabled) {
|
|
3301
|
+
if (typeof httpErrorCallback === "function") {
|
|
3302
|
+
await httpErrorCallback(error2);
|
|
3303
|
+
}
|
|
3304
|
+
if (typeof httpFinishCallback === "function") {
|
|
3305
|
+
httpFinishCallback();
|
|
3306
|
+
}
|
|
3307
|
+
}
|
|
3308
|
+
return Promise.reject(error2);
|
|
3309
|
+
});
|
|
3310
|
+
}
|
|
3374
3311
|
}
|
|
3375
|
-
if (
|
|
3376
|
-
|
|
3312
|
+
if (isHttpHandlerEnabled) {
|
|
3313
|
+
if (typeof httpErrorCallback === "function") {
|
|
3314
|
+
await httpErrorCallback(error);
|
|
3315
|
+
}
|
|
3316
|
+
if (typeof httpFinishCallback === "function") {
|
|
3317
|
+
httpFinishCallback();
|
|
3318
|
+
}
|
|
3377
3319
|
}
|
|
3378
|
-
|
|
3379
|
-
|
|
3380
|
-
|
|
3381
|
-
|
|
3382
|
-
|
|
3383
|
-
|
|
3320
|
+
return Promise.reject(error);
|
|
3321
|
+
});
|
|
3322
|
+
} else {
|
|
3323
|
+
throw new import_javascript6.AsgardeoAuthException(
|
|
3324
|
+
"SPA-AUTH_HELPER-HRA-IV02",
|
|
3325
|
+
"Request to the provided endpoint is prohibited.",
|
|
3326
|
+
"Requests can only be sent to resource servers specified by the `resourceServerURLs` attribute while initializing the SDK. The specified endpoint in this request cannot be found among the `resourceServerURLs`"
|
|
3327
|
+
);
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
async requestAccessToken(authorizationCode, sessionState, checkSession, pkce, state, tokenRequestConfig) {
|
|
3331
|
+
const config = await this._storageManager.getConfigData();
|
|
3332
|
+
if (config.storage === "browserMemory" /* BrowserMemory */ && config.enablePKCE && sessionState) {
|
|
3333
|
+
const pkce2 = SPAUtils.getPKCE((0, import_javascript6.extractPkceStorageKeyFromState)(sessionState));
|
|
3334
|
+
await this._authenticationClient.setPKCECode((0, import_javascript6.extractPkceStorageKeyFromState)(sessionState), pkce2);
|
|
3335
|
+
} else if (config.storage === "webWorker" /* WebWorker */ && pkce) {
|
|
3336
|
+
await this._authenticationClient.setPKCECode(pkce, state ?? "");
|
|
3337
|
+
}
|
|
3338
|
+
if (authorizationCode) {
|
|
3339
|
+
return this._authenticationClient.requestAccessToken(authorizationCode, sessionState ?? "", state ?? "", void 0, tokenRequestConfig).then(async () => {
|
|
3340
|
+
if (config.storage !== "webWorker" /* WebWorker */) {
|
|
3341
|
+
SPAUtils.setSignOutURL(await this._authenticationClient.getSignOutUrl(), config.clientId, this._instanceID);
|
|
3342
|
+
if (this._spaHelper) {
|
|
3343
|
+
this._spaHelper.clearRefreshTokenTimeout();
|
|
3344
|
+
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
3345
|
+
}
|
|
3346
|
+
if (checkSession && typeof checkSession === "function" && config.enableOIDCSessionManagement) {
|
|
3347
|
+
checkSession();
|
|
3348
|
+
}
|
|
3384
3349
|
} else {
|
|
3385
|
-
|
|
3350
|
+
if (this._spaHelper) {
|
|
3351
|
+
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
3352
|
+
}
|
|
3386
3353
|
}
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3354
|
+
return this._authenticationClient.getUser();
|
|
3355
|
+
}).catch((error) => {
|
|
3356
|
+
return Promise.reject(error);
|
|
3357
|
+
});
|
|
3358
|
+
}
|
|
3359
|
+
return Promise.reject(
|
|
3360
|
+
new import_javascript6.AsgardeoAuthException(
|
|
3361
|
+
"SPA-AUTH_HELPER-RAT1-NF01",
|
|
3362
|
+
"No authorization code.",
|
|
3363
|
+
"No authorization code was found."
|
|
3364
|
+
)
|
|
3365
|
+
);
|
|
3366
|
+
}
|
|
3367
|
+
async trySignInSilently(constructSilentSignInUrl, requestAccessToken, sessionManagementHelper, additionalParams, tokenRequestConfig) {
|
|
3368
|
+
if (SPAUtils.isInitializedSilentSignIn()) {
|
|
3369
|
+
await sessionManagementHelper.receivePromptNoneResponse();
|
|
3370
|
+
return Promise.resolve({
|
|
3371
|
+
allowedScopes: "",
|
|
3372
|
+
displayName: "",
|
|
3373
|
+
email: "",
|
|
3374
|
+
sessionState: "",
|
|
3375
|
+
sub: "",
|
|
3376
|
+
tenantDomain: "",
|
|
3377
|
+
username: ""
|
|
3397
3378
|
});
|
|
3398
3379
|
}
|
|
3399
|
-
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
} else {
|
|
3404
|
-
location.href = SPAUtils.getSignOutUrl(config.clientId, instanceID);
|
|
3405
|
-
}
|
|
3406
|
-
_spaHelper.clearRefreshTokenTimeout();
|
|
3407
|
-
await _dataLayer.removeOIDCProviderMetaData();
|
|
3408
|
-
await _dataLayer.removeTemporaryData();
|
|
3409
|
-
await _dataLayer.removeSessionData();
|
|
3410
|
-
await _dataLayer.removeSessionStatus();
|
|
3411
|
-
await SPAUtils.waitTillPageRedirect();
|
|
3412
|
-
return true;
|
|
3413
|
-
};
|
|
3414
|
-
const enableRetrievingSignOutURLFromSession = (config2) => {
|
|
3415
|
-
if (config2.preventSignOutURLUpdate) {
|
|
3416
|
-
_getSignOutURLFromSessionStorage = true;
|
|
3417
|
-
}
|
|
3418
|
-
};
|
|
3419
|
-
const exchangeToken = async (config2) => {
|
|
3420
|
-
return await _authenticationHelper.exchangeToken(config2, enableRetrievingSignOutURLFromSession);
|
|
3421
|
-
};
|
|
3422
|
-
const refreshAccessToken = async () => {
|
|
3380
|
+
const rpIFrame = document.getElementById(RP_IFRAME);
|
|
3381
|
+
const promptNoneIFrame = rpIFrame?.contentDocument?.getElementById(
|
|
3382
|
+
PROMPT_NONE_IFRAME
|
|
3383
|
+
);
|
|
3423
3384
|
try {
|
|
3424
|
-
|
|
3385
|
+
const url = await constructSilentSignInUrl(additionalParams);
|
|
3386
|
+
promptNoneIFrame.src = url;
|
|
3425
3387
|
} catch (error) {
|
|
3426
3388
|
return Promise.reject(error);
|
|
3427
3389
|
}
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3450
|
-
|
|
3451
|
-
|
|
3452
|
-
...additionalParams
|
|
3390
|
+
return new Promise((resolve, reject) => {
|
|
3391
|
+
const timer = setTimeout(() => {
|
|
3392
|
+
resolve(false);
|
|
3393
|
+
}, 1e4);
|
|
3394
|
+
const listenToPromptNoneIFrame = async (e) => {
|
|
3395
|
+
const data = e.data;
|
|
3396
|
+
if (data?.type == CHECK_SESSION_SIGNED_OUT) {
|
|
3397
|
+
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
3398
|
+
clearTimeout(timer);
|
|
3399
|
+
resolve(false);
|
|
3400
|
+
}
|
|
3401
|
+
if (data?.type == CHECK_SESSION_SIGNED_IN && data?.data?.code) {
|
|
3402
|
+
requestAccessToken(data?.data?.code, data?.data?.sessionState, data?.data?.state, tokenRequestConfig).then((response) => {
|
|
3403
|
+
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
3404
|
+
resolve(response);
|
|
3405
|
+
}).catch((error) => {
|
|
3406
|
+
window.removeEventListener("message", listenToPromptNoneIFrame);
|
|
3407
|
+
reject(error);
|
|
3408
|
+
}).finally(() => {
|
|
3409
|
+
clearTimeout(timer);
|
|
3410
|
+
});
|
|
3411
|
+
}
|
|
3412
|
+
};
|
|
3413
|
+
window.addEventListener("message", listenToPromptNoneIFrame);
|
|
3453
3414
|
});
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
const
|
|
3457
|
-
if (
|
|
3458
|
-
|
|
3459
|
-
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3415
|
+
}
|
|
3416
|
+
async handleSignIn(shouldStopAuthn, checkSession, tryRetrievingUserInfo) {
|
|
3417
|
+
const config = await this._storageManager.getConfigData();
|
|
3418
|
+
if (await shouldStopAuthn()) {
|
|
3419
|
+
return Promise.resolve({
|
|
3420
|
+
allowedScopes: "",
|
|
3421
|
+
displayName: "",
|
|
3422
|
+
email: "",
|
|
3423
|
+
sessionState: "",
|
|
3424
|
+
sub: "",
|
|
3425
|
+
tenantDomain: "",
|
|
3426
|
+
username: ""
|
|
3427
|
+
});
|
|
3463
3428
|
}
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
);
|
|
3474
|
-
};
|
|
3475
|
-
const getUser = async () => {
|
|
3476
|
-
return _authenticationHelper.getUser();
|
|
3477
|
-
};
|
|
3478
|
-
const getDecodedIdToken = async () => {
|
|
3479
|
-
return _authenticationHelper.getDecodedIdToken();
|
|
3480
|
-
};
|
|
3481
|
-
const getCrypto = async () => {
|
|
3482
|
-
return _authenticationHelper.getCrypto();
|
|
3483
|
-
};
|
|
3484
|
-
const getIdToken = async () => {
|
|
3485
|
-
return _authenticationHelper.getIdToken();
|
|
3486
|
-
};
|
|
3487
|
-
const getOpenIDProviderEndpoints = async () => {
|
|
3488
|
-
return _authenticationHelper.getOpenIDProviderEndpoints();
|
|
3489
|
-
};
|
|
3490
|
-
const getAccessToken = async () => {
|
|
3491
|
-
return _authenticationHelper.getAccessToken();
|
|
3492
|
-
};
|
|
3493
|
-
const getStorageManager = async () => {
|
|
3494
|
-
return _authenticationHelper.getStorageManager();
|
|
3495
|
-
};
|
|
3496
|
-
const getConfigData = async () => {
|
|
3497
|
-
return await _dataLayer.getConfigData();
|
|
3498
|
-
};
|
|
3499
|
-
const isSignedIn = async () => {
|
|
3500
|
-
return _authenticationHelper.isSignedIn();
|
|
3501
|
-
};
|
|
3502
|
-
const isSessionActive = async () => {
|
|
3503
|
-
return await _dataLayer.getSessionStatus() === "true";
|
|
3504
|
-
};
|
|
3505
|
-
const reInitialize = async (newConfig) => {
|
|
3506
|
-
const existingConfig = await _dataLayer.getConfigData();
|
|
3507
|
-
const isCheckSessionIframeDifferent = !(existingConfig && existingConfig.endpoints && existingConfig.endpoints.checkSessionIframe && newConfig && newConfig.endpoints && newConfig.endpoints.checkSessionIframe && existingConfig.endpoints.checkSessionIframe === newConfig.endpoints.checkSessionIframe);
|
|
3508
|
-
const config2 = { ...existingConfig, ...newConfig };
|
|
3509
|
-
await _authenticationClient.reInitialize(config2);
|
|
3510
|
-
if (config2.enableOIDCSessionManagement && isCheckSessionIframeDifferent) {
|
|
3511
|
-
_sessionManagementHelper.reset();
|
|
3512
|
-
checkSession();
|
|
3429
|
+
if (config.storage !== "webWorker" /* WebWorker */) {
|
|
3430
|
+
if (await this._authenticationClient.isSignedIn()) {
|
|
3431
|
+
this._spaHelper.clearRefreshTokenTimeout();
|
|
3432
|
+
this._spaHelper.refreshAccessTokenAutomatically(this);
|
|
3433
|
+
if (config.enableOIDCSessionManagement) {
|
|
3434
|
+
checkSession();
|
|
3435
|
+
}
|
|
3436
|
+
return Promise.resolve(await this._authenticationClient.getUser());
|
|
3437
|
+
}
|
|
3513
3438
|
}
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3439
|
+
const error = new URL(window.location.href).searchParams.get(ERROR);
|
|
3440
|
+
const errorDescription = new URL(window.location.href).searchParams.get(ERROR_DESCRIPTION);
|
|
3441
|
+
if (error) {
|
|
3442
|
+
const url = new URL(window.location.href);
|
|
3443
|
+
url.searchParams.delete(ERROR);
|
|
3444
|
+
url.searchParams.delete(ERROR_DESCRIPTION);
|
|
3445
|
+
history.pushState(null, document.title, url.toString());
|
|
3446
|
+
throw new import_javascript6.AsgardeoAuthException("SPA-AUTH_HELPER-SI-SE01", error, errorDescription ?? "");
|
|
3447
|
+
}
|
|
3448
|
+
if (config.storage === "webWorker" /* WebWorker */ && tryRetrievingUserInfo) {
|
|
3449
|
+
const basicUserInfo = await tryRetrievingUserInfo();
|
|
3450
|
+
if (basicUserInfo) {
|
|
3451
|
+
return basicUserInfo;
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
return Promise.resolve(void 0);
|
|
3455
|
+
}
|
|
3456
|
+
async attachTokenToRequestConfig(request) {
|
|
3457
|
+
const requestConfig = { attachToken: true, ...request };
|
|
3458
|
+
if (requestConfig.attachToken) {
|
|
3459
|
+
if (requestConfig.shouldAttachIDPAccessToken) {
|
|
3460
|
+
request.headers = {
|
|
3461
|
+
...request.headers,
|
|
3462
|
+
Authorization: `Bearer ${await this.getIDPAccessToken()}`
|
|
3463
|
+
};
|
|
3464
|
+
} else {
|
|
3465
|
+
request.headers = {
|
|
3466
|
+
...request.headers,
|
|
3467
|
+
Authorization: `Bearer ${await this.getAccessToken()}`
|
|
3468
|
+
};
|
|
3469
|
+
}
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
async getUser() {
|
|
3473
|
+
return this._authenticationClient.getUser();
|
|
3474
|
+
}
|
|
3475
|
+
async getDecodedIdToken(sessionId) {
|
|
3476
|
+
return this._authenticationClient.getDecodedIdToken(sessionId);
|
|
3477
|
+
}
|
|
3478
|
+
async getDecodedIDPIDToken() {
|
|
3479
|
+
return this._authenticationClient.getDecodedIdToken();
|
|
3480
|
+
}
|
|
3481
|
+
async getCrypto() {
|
|
3482
|
+
return this._authenticationClient.getCrypto();
|
|
3483
|
+
}
|
|
3484
|
+
async getIdToken() {
|
|
3485
|
+
return this._authenticationClient.getIdToken();
|
|
3486
|
+
}
|
|
3487
|
+
async getOpenIDProviderEndpoints() {
|
|
3488
|
+
return this._authenticationClient.getOpenIDProviderEndpoints();
|
|
3489
|
+
}
|
|
3490
|
+
async getAccessToken() {
|
|
3491
|
+
return this._authenticationClient.getAccessToken();
|
|
3492
|
+
}
|
|
3493
|
+
async getIDPAccessToken() {
|
|
3494
|
+
return (await this._storageManager.getSessionData())?.access_token;
|
|
3495
|
+
}
|
|
3496
|
+
getStorageManager() {
|
|
3497
|
+
return this._storageManager;
|
|
3498
|
+
}
|
|
3499
|
+
async isSignedIn() {
|
|
3500
|
+
return this._authenticationClient.isSignedIn();
|
|
3501
|
+
}
|
|
3543
3502
|
};
|
|
3544
3503
|
|
|
3545
3504
|
// src/__legacy__/clients/web-worker-client.ts
|
|
3546
|
-
var import_javascript7 = require("@asgardeo/javascript");
|
|
3547
3505
|
var initiateStore2 = (store) => {
|
|
3548
3506
|
switch (store) {
|
|
3549
3507
|
case "localStorage" /* LocalStorage */:
|
|
@@ -3949,7 +3907,7 @@ var WebWorkerClient = async (instanceID, config, webWorker, getAuthHelper) => {
|
|
|
3949
3907
|
return Promise.reject(error);
|
|
3950
3908
|
});
|
|
3951
3909
|
};
|
|
3952
|
-
const getDecodedIdToken = () => {
|
|
3910
|
+
const getDecodedIdToken = (sessionId) => {
|
|
3953
3911
|
const message = {
|
|
3954
3912
|
type: GET_DECODED_ID_TOKEN
|
|
3955
3913
|
};
|
|
@@ -4069,7 +4027,7 @@ var WebWorkerClient = async (instanceID, config, webWorker, getAuthHelper) => {
|
|
|
4069
4027
|
|
|
4070
4028
|
// src/__legacy__/client.ts
|
|
4071
4029
|
var DefaultConfig = {
|
|
4072
|
-
autoLogoutOnTokenRefreshError:
|
|
4030
|
+
autoLogoutOnTokenRefreshError: false,
|
|
4073
4031
|
checkSessionInterval: 3,
|
|
4074
4032
|
enableOIDCSessionManagement: false,
|
|
4075
4033
|
periodicTokenRefresh: false,
|
|
@@ -4648,9 +4606,9 @@ var _AsgardeoSPAClient = class _AsgardeoSPAClient {
|
|
|
4648
4606
|
*
|
|
4649
4607
|
* @preserve
|
|
4650
4608
|
*/
|
|
4651
|
-
async getDecodedIdToken() {
|
|
4609
|
+
async getDecodedIdToken(sessionId) {
|
|
4652
4610
|
await this._validateMethod();
|
|
4653
|
-
return this._client?.getDecodedIdToken();
|
|
4611
|
+
return this._client?.getDecodedIdToken(sessionId);
|
|
4654
4612
|
}
|
|
4655
4613
|
/**
|
|
4656
4614
|
* This method returns the IsomorphicCrypto instance.
|
|
@@ -5112,8 +5070,8 @@ var WebWorkerCore = async (config, getAuthHelper) => {
|
|
|
5112
5070
|
const getUser = async () => {
|
|
5113
5071
|
return _authenticationHelper.getUser();
|
|
5114
5072
|
};
|
|
5115
|
-
const getDecodedIdToken = async () => {
|
|
5116
|
-
return _authenticationHelper.getDecodedIdToken();
|
|
5073
|
+
const getDecodedIdToken = async (sessionId) => {
|
|
5074
|
+
return _authenticationHelper.getDecodedIdToken(sessionId);
|
|
5117
5075
|
};
|
|
5118
5076
|
const getCrypto = async () => {
|
|
5119
5077
|
return _authenticationHelper.getCrypto();
|
|
@@ -5385,17 +5343,6 @@ var workerReceiver = (getAuthHelper) => {
|
|
|
5385
5343
|
};
|
|
5386
5344
|
};
|
|
5387
5345
|
|
|
5388
|
-
// src/constants/StyleConstants.ts
|
|
5389
|
-
var StyleConstants = class {
|
|
5390
|
-
constructor() {
|
|
5391
|
-
}
|
|
5392
|
-
};
|
|
5393
|
-
/**
|
|
5394
|
-
* CSS class prefix for out of the box components.
|
|
5395
|
-
*/
|
|
5396
|
-
__publicField(StyleConstants, "VENDOR_CSS_CLASS_PREFIX", "asgardeo");
|
|
5397
|
-
var StyleConstants_default = StyleConstants;
|
|
5398
|
-
|
|
5399
5346
|
// src/utils/hasAuthParamsInUrl.ts
|
|
5400
5347
|
var hasAuthParamsInUrl = (params = window.location.search) => {
|
|
5401
5348
|
const MATCHER = /[?&]code=[^&]+/;
|
|
@@ -5403,12 +5350,6 @@ var hasAuthParamsInUrl = (params = window.location.search) => {
|
|
|
5403
5350
|
};
|
|
5404
5351
|
var hasAuthParamsInUrl_default = hasAuthParamsInUrl;
|
|
5405
5352
|
|
|
5406
|
-
// src/utils/withVendorCSSClassPrefix.ts
|
|
5407
|
-
var withVendorCSSClassPrefix = (className) => {
|
|
5408
|
-
return `${StyleConstants_default.VENDOR_CSS_CLASS_PREFIX}-${className}`;
|
|
5409
|
-
};
|
|
5410
|
-
var withVendorCSSClassPrefix_default = withVendorCSSClassPrefix;
|
|
5411
|
-
|
|
5412
5353
|
// src/AsgardeoBrowserClient.ts
|
|
5413
5354
|
var import_javascript11 = require("@asgardeo/javascript");
|
|
5414
5355
|
var AsgardeoBrowserClient = class extends import_javascript11.AsgardeoJavaScriptClient {
|
|
@@ -5417,6 +5358,73 @@ var AsgardeoBrowserClient_default = AsgardeoBrowserClient;
|
|
|
5417
5358
|
|
|
5418
5359
|
// src/index.ts
|
|
5419
5360
|
__reExport(index_exports, require("@asgardeo/javascript"), module.exports);
|
|
5361
|
+
|
|
5362
|
+
// src/theme/themeDetection.ts
|
|
5363
|
+
var detectThemeMode = (mode, config = {}) => {
|
|
5364
|
+
const {
|
|
5365
|
+
darkClass = "dark",
|
|
5366
|
+
lightClass = "light",
|
|
5367
|
+
targetElement = typeof document !== "undefined" ? document.documentElement : null
|
|
5368
|
+
} = config;
|
|
5369
|
+
if (mode === "light") return "light";
|
|
5370
|
+
if (mode === "dark") return "dark";
|
|
5371
|
+
if (mode === "system") {
|
|
5372
|
+
if (typeof window !== "undefined" && window.matchMedia) {
|
|
5373
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
5374
|
+
}
|
|
5375
|
+
return "light";
|
|
5376
|
+
}
|
|
5377
|
+
if (mode === "class") {
|
|
5378
|
+
if (!targetElement) {
|
|
5379
|
+
console.warn("ThemeDetection: targetElement is required for class-based detection, falling back to light mode");
|
|
5380
|
+
return "light";
|
|
5381
|
+
}
|
|
5382
|
+
const classList = targetElement.classList;
|
|
5383
|
+
if (classList.contains(darkClass)) {
|
|
5384
|
+
return "dark";
|
|
5385
|
+
}
|
|
5386
|
+
if (classList.contains(lightClass)) {
|
|
5387
|
+
return "light";
|
|
5388
|
+
}
|
|
5389
|
+
return "light";
|
|
5390
|
+
}
|
|
5391
|
+
return "light";
|
|
5392
|
+
};
|
|
5393
|
+
var createClassObserver = (targetElement, callback, config = {}) => {
|
|
5394
|
+
const { darkClass = "dark", lightClass = "light" } = config;
|
|
5395
|
+
const observer = new MutationObserver((mutations) => {
|
|
5396
|
+
mutations.forEach((mutation) => {
|
|
5397
|
+
if (mutation.type === "attributes" && mutation.attributeName === "class") {
|
|
5398
|
+
const classList = targetElement.classList;
|
|
5399
|
+
if (classList.contains(darkClass)) {
|
|
5400
|
+
callback(true);
|
|
5401
|
+
} else if (classList.contains(lightClass)) {
|
|
5402
|
+
callback(false);
|
|
5403
|
+
}
|
|
5404
|
+
}
|
|
5405
|
+
});
|
|
5406
|
+
});
|
|
5407
|
+
observer.observe(targetElement, {
|
|
5408
|
+
attributes: true,
|
|
5409
|
+
attributeFilter: ["class"]
|
|
5410
|
+
});
|
|
5411
|
+
return observer;
|
|
5412
|
+
};
|
|
5413
|
+
var createMediaQueryListener = (callback) => {
|
|
5414
|
+
if (typeof window === "undefined" || !window.matchMedia) {
|
|
5415
|
+
return null;
|
|
5416
|
+
}
|
|
5417
|
+
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
5418
|
+
const handleChange = (e) => {
|
|
5419
|
+
callback(e.matches);
|
|
5420
|
+
};
|
|
5421
|
+
if (mediaQuery.addEventListener) {
|
|
5422
|
+
mediaQuery.addEventListener("change", handleChange);
|
|
5423
|
+
} else {
|
|
5424
|
+
mediaQuery.addListener(handleChange);
|
|
5425
|
+
}
|
|
5426
|
+
return mediaQuery;
|
|
5427
|
+
};
|
|
5420
5428
|
/*! Bundled license information:
|
|
5421
5429
|
|
|
5422
5430
|
ieee754/index.js:
|