@asgardeo/react 0.11.3 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +724 -482
- package/dist/cjs/index.js.map +4 -4
- package/dist/components/auth/Callback/Callback.d.ts +51 -0
- package/dist/components/presentation/auth/AcceptInvite/v2/BaseAcceptInvite.d.ts +1 -0
- package/dist/hooks/useBrowserUrl.d.ts +8 -0
- package/dist/hooks/v2/useOAuthCallback.d.ts +82 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +311 -69
- package/dist/index.js.map +4 -4
- package/dist/utils/oauth.d.ts +24 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -886,11 +886,12 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
|
|
|
886
886
|
var AsgardeoReactClient_default = AsgardeoReactClient;
|
|
887
887
|
|
|
888
888
|
// src/hooks/useBrowserUrl.ts
|
|
889
|
-
import { hasAuthParamsInUrl } from "@asgardeo/browser";
|
|
889
|
+
import { hasAuthParamsInUrl, hasCalledForThisInstanceInUrl } from "@asgardeo/browser";
|
|
890
890
|
var useBrowserUrl = () => {
|
|
891
891
|
const hasAuthParams = (url, afterSignInUrl) => hasAuthParamsInUrl() && new URL(url.origin + url.pathname).toString() === new URL(afterSignInUrl).toString() || // authParams?.authorizationCode || // FIXME: These are sent externally. Need to see what we can do about this.
|
|
892
892
|
url.searchParams.get("error") !== null;
|
|
893
|
-
|
|
893
|
+
const hasCalledForThisInstance = (url, instanceId) => hasCalledForThisInstanceInUrl(instanceId, url.search);
|
|
894
|
+
return { hasAuthParams, hasCalledForThisInstance };
|
|
894
895
|
};
|
|
895
896
|
var useBrowserUrl_default = useBrowserUrl;
|
|
896
897
|
|
|
@@ -1550,7 +1551,7 @@ var AsgardeoProvider = ({
|
|
|
1550
1551
|
}) => {
|
|
1551
1552
|
const reRenderCheckRef = useRef(false);
|
|
1552
1553
|
const asgardeo = useMemo6(() => new AsgardeoReactClient_default(instanceId), [instanceId]);
|
|
1553
|
-
const { hasAuthParams } = useBrowserUrl_default();
|
|
1554
|
+
const { hasAuthParams, hasCalledForThisInstance } = useBrowserUrl_default();
|
|
1554
1555
|
const [user, setUser] = useState6(null);
|
|
1555
1556
|
const [currentOrganization, setCurrentOrganization] = useState6(null);
|
|
1556
1557
|
const [isSignedInSync, setIsSignedInSync] = useState6(false);
|
|
@@ -1689,7 +1690,7 @@ var AsgardeoProvider = ({
|
|
|
1689
1690
|
return;
|
|
1690
1691
|
}
|
|
1691
1692
|
const currentUrl = new URL(window.location.href);
|
|
1692
|
-
const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl);
|
|
1693
|
+
const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl) && hasCalledForThisInstance(currentUrl, instanceId ?? 0);
|
|
1693
1694
|
const isV2Platform = config.platform === Platform2.AsgardeoV2;
|
|
1694
1695
|
if (hasAuthParamsResult) {
|
|
1695
1696
|
try {
|
|
@@ -7854,7 +7855,134 @@ import {
|
|
|
7854
7855
|
EmbeddedSignInFlowStatusV2 as EmbeddedSignInFlowStatusV22,
|
|
7855
7856
|
EmbeddedSignInFlowTypeV2
|
|
7856
7857
|
} from "@asgardeo/browser";
|
|
7857
|
-
import { useState as useState15, useEffect as
|
|
7858
|
+
import { useState as useState15, useEffect as useEffect13, useRef as useRef5 } from "react";
|
|
7859
|
+
|
|
7860
|
+
// src/hooks/v2/useOAuthCallback.ts
|
|
7861
|
+
import { useEffect as useEffect12, useRef as useRef4 } from "react";
|
|
7862
|
+
function cleanupUrlParams() {
|
|
7863
|
+
if (typeof window === "undefined") return;
|
|
7864
|
+
const url = new URL(window.location.href);
|
|
7865
|
+
url.searchParams.delete("code");
|
|
7866
|
+
url.searchParams.delete("nonce");
|
|
7867
|
+
url.searchParams.delete("state");
|
|
7868
|
+
url.searchParams.delete("error");
|
|
7869
|
+
url.searchParams.delete("error_description");
|
|
7870
|
+
window.history.replaceState({}, "", url.toString());
|
|
7871
|
+
}
|
|
7872
|
+
function useOAuthCallback({
|
|
7873
|
+
currentFlowId,
|
|
7874
|
+
flowIdStorageKey = "asgardeo_flow_id",
|
|
7875
|
+
isInitialized,
|
|
7876
|
+
isSubmitting = false,
|
|
7877
|
+
onComplete,
|
|
7878
|
+
onError,
|
|
7879
|
+
onFlowChange,
|
|
7880
|
+
onProcessingStart,
|
|
7881
|
+
onSubmit,
|
|
7882
|
+
processedRef,
|
|
7883
|
+
setFlowId,
|
|
7884
|
+
tokenValidationAttemptedRef
|
|
7885
|
+
}) {
|
|
7886
|
+
const internalRef = useRef4(false);
|
|
7887
|
+
const oauthCodeProcessedRef = processedRef ?? internalRef;
|
|
7888
|
+
useEffect12(() => {
|
|
7889
|
+
if (!isInitialized || isSubmitting) {
|
|
7890
|
+
return;
|
|
7891
|
+
}
|
|
7892
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
7893
|
+
const code = urlParams.get("code");
|
|
7894
|
+
const nonce = urlParams.get("nonce");
|
|
7895
|
+
const state = urlParams.get("state");
|
|
7896
|
+
const flowIdFromUrl = urlParams.get("flowId");
|
|
7897
|
+
const error = urlParams.get("error");
|
|
7898
|
+
const errorDescription = urlParams.get("error_description");
|
|
7899
|
+
if (error) {
|
|
7900
|
+
oauthCodeProcessedRef.current = true;
|
|
7901
|
+
if (tokenValidationAttemptedRef) {
|
|
7902
|
+
tokenValidationAttemptedRef.current = true;
|
|
7903
|
+
}
|
|
7904
|
+
onError?.(new Error(errorDescription || error || "OAuth authentication failed"));
|
|
7905
|
+
cleanupUrlParams();
|
|
7906
|
+
return;
|
|
7907
|
+
}
|
|
7908
|
+
if (!code || oauthCodeProcessedRef.current) {
|
|
7909
|
+
return;
|
|
7910
|
+
}
|
|
7911
|
+
if (tokenValidationAttemptedRef?.current) {
|
|
7912
|
+
return;
|
|
7913
|
+
}
|
|
7914
|
+
const storedFlowId = sessionStorage.getItem(flowIdStorageKey);
|
|
7915
|
+
const flowIdToUse = currentFlowId || storedFlowId || flowIdFromUrl || state || null;
|
|
7916
|
+
if (!flowIdToUse) {
|
|
7917
|
+
oauthCodeProcessedRef.current = true;
|
|
7918
|
+
onError?.(new Error("Invalid flow. Missing flowId."));
|
|
7919
|
+
cleanupUrlParams();
|
|
7920
|
+
return;
|
|
7921
|
+
}
|
|
7922
|
+
oauthCodeProcessedRef.current = true;
|
|
7923
|
+
if (tokenValidationAttemptedRef) {
|
|
7924
|
+
tokenValidationAttemptedRef.current = true;
|
|
7925
|
+
}
|
|
7926
|
+
onProcessingStart?.();
|
|
7927
|
+
if (!currentFlowId && setFlowId) {
|
|
7928
|
+
setFlowId(flowIdToUse);
|
|
7929
|
+
}
|
|
7930
|
+
(async () => {
|
|
7931
|
+
try {
|
|
7932
|
+
const payload = {
|
|
7933
|
+
flowId: flowIdToUse,
|
|
7934
|
+
inputs: {
|
|
7935
|
+
code,
|
|
7936
|
+
...nonce && { nonce }
|
|
7937
|
+
}
|
|
7938
|
+
};
|
|
7939
|
+
const response = await onSubmit(payload);
|
|
7940
|
+
onFlowChange?.(response);
|
|
7941
|
+
if (response?.flowStatus === "COMPLETE" || response?.status === "COMPLETE") {
|
|
7942
|
+
onComplete?.();
|
|
7943
|
+
}
|
|
7944
|
+
if (response?.flowStatus === "ERROR" || response?.status === "ERROR") {
|
|
7945
|
+
onError?.(response);
|
|
7946
|
+
}
|
|
7947
|
+
cleanupUrlParams();
|
|
7948
|
+
} catch (err) {
|
|
7949
|
+
onError?.(err);
|
|
7950
|
+
cleanupUrlParams();
|
|
7951
|
+
}
|
|
7952
|
+
})();
|
|
7953
|
+
}, [
|
|
7954
|
+
isInitialized,
|
|
7955
|
+
currentFlowId,
|
|
7956
|
+
isSubmitting,
|
|
7957
|
+
onSubmit,
|
|
7958
|
+
onComplete,
|
|
7959
|
+
onError,
|
|
7960
|
+
onFlowChange,
|
|
7961
|
+
setFlowId,
|
|
7962
|
+
flowIdStorageKey
|
|
7963
|
+
]);
|
|
7964
|
+
}
|
|
7965
|
+
|
|
7966
|
+
// src/utils/oauth.ts
|
|
7967
|
+
import { navigate as navigate4 } from "@asgardeo/browser";
|
|
7968
|
+
function initiateOAuthRedirect(redirectURL) {
|
|
7969
|
+
const basePath = document.querySelector("base")?.getAttribute("href") || "";
|
|
7970
|
+
let returnPath = window.location.pathname;
|
|
7971
|
+
if (basePath && returnPath.startsWith(basePath)) {
|
|
7972
|
+
returnPath = returnPath.slice(basePath.length) || "/";
|
|
7973
|
+
}
|
|
7974
|
+
const state = crypto.randomUUID();
|
|
7975
|
+
sessionStorage.setItem(
|
|
7976
|
+
`asgardeo_oauth_${state}`,
|
|
7977
|
+
JSON.stringify({
|
|
7978
|
+
path: returnPath,
|
|
7979
|
+
timestamp: Date.now()
|
|
7980
|
+
})
|
|
7981
|
+
);
|
|
7982
|
+
const redirectUrlObj = new URL(redirectURL);
|
|
7983
|
+
redirectUrlObj.searchParams.set("state", state);
|
|
7984
|
+
navigate4(redirectUrlObj.toString());
|
|
7985
|
+
}
|
|
7858
7986
|
|
|
7859
7987
|
// src/utils/v2/passkey.ts
|
|
7860
7988
|
import { AsgardeoRuntimeError as AsgardeoRuntimeError7, arrayBufferToBase64url, base64urlToArrayBuffer } from "@asgardeo/browser";
|
|
@@ -8027,9 +8155,9 @@ var SignIn = ({
|
|
|
8027
8155
|
flowId: null,
|
|
8028
8156
|
isActive: false
|
|
8029
8157
|
});
|
|
8030
|
-
const initializationAttemptedRef =
|
|
8031
|
-
const oauthCodeProcessedRef =
|
|
8032
|
-
const passkeyProcessedRef =
|
|
8158
|
+
const initializationAttemptedRef = useRef5(false);
|
|
8159
|
+
const oauthCodeProcessedRef = useRef5(false);
|
|
8160
|
+
const passkeyProcessedRef = useRef5(false);
|
|
8033
8161
|
const setFlowId = (flowId) => {
|
|
8034
8162
|
setCurrentFlowId(flowId);
|
|
8035
8163
|
if (flowId) {
|
|
@@ -8062,7 +8190,6 @@ var SignIn = ({
|
|
|
8062
8190
|
sessionStorage.setItem("asgardeo_auth_id", authId);
|
|
8063
8191
|
}
|
|
8064
8192
|
};
|
|
8065
|
-
const resolveFlowId = (activeFlowId, state, flowIdFromUrl, storedFlowId) => activeFlowId || state || flowIdFromUrl || storedFlowId || null;
|
|
8066
8193
|
const cleanupOAuthUrlParams = (includeNonce = false) => {
|
|
8067
8194
|
if (!window?.location?.href) return;
|
|
8068
8195
|
const url = new URL(window.location.href);
|
|
@@ -8104,7 +8231,7 @@ var SignIn = ({
|
|
|
8104
8231
|
}
|
|
8105
8232
|
const urlParams = getUrlParams2();
|
|
8106
8233
|
handleAuthId(urlParams.authId);
|
|
8107
|
-
|
|
8234
|
+
initiateOAuthRedirect(redirectURL);
|
|
8108
8235
|
return true;
|
|
8109
8236
|
}
|
|
8110
8237
|
}
|
|
@@ -8157,7 +8284,7 @@ var SignIn = ({
|
|
|
8157
8284
|
initializationAttemptedRef.current = false;
|
|
8158
8285
|
}
|
|
8159
8286
|
};
|
|
8160
|
-
|
|
8287
|
+
useEffect13(() => {
|
|
8161
8288
|
const urlParams = getUrlParams2();
|
|
8162
8289
|
if (urlParams.error) {
|
|
8163
8290
|
handleOAuthError(urlParams.error, urlParams.errorDescription);
|
|
@@ -8254,37 +8381,19 @@ var SignIn = ({
|
|
|
8254
8381
|
const handleError = (error) => {
|
|
8255
8382
|
setError(error);
|
|
8256
8383
|
};
|
|
8257
|
-
|
|
8258
|
-
|
|
8259
|
-
|
|
8260
|
-
|
|
8261
|
-
|
|
8262
|
-
|
|
8263
|
-
|
|
8264
|
-
}
|
|
8265
|
-
|
|
8266
|
-
|
|
8267
|
-
|
|
8268
|
-
|
|
8269
|
-
|
|
8270
|
-
return;
|
|
8271
|
-
}
|
|
8272
|
-
oauthCodeProcessedRef.current = true;
|
|
8273
|
-
if (!currentFlowId) {
|
|
8274
|
-
setFlowId(flowIdToUse);
|
|
8275
|
-
}
|
|
8276
|
-
const submitPayload = {
|
|
8277
|
-
flowId: flowIdToUse,
|
|
8278
|
-
inputs: {
|
|
8279
|
-
code: urlParams.code,
|
|
8280
|
-
...urlParams.nonce && { nonce: urlParams.nonce }
|
|
8281
|
-
}
|
|
8282
|
-
};
|
|
8283
|
-
handleSubmit(submitPayload).catch(() => {
|
|
8284
|
-
cleanupOAuthUrlParams(true);
|
|
8285
|
-
});
|
|
8286
|
-
}, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
|
|
8287
|
-
useEffect12(() => {
|
|
8384
|
+
useOAuthCallback({
|
|
8385
|
+
currentFlowId,
|
|
8386
|
+
isInitialized: isInitialized && !isLoading,
|
|
8387
|
+
isSubmitting,
|
|
8388
|
+
onError: (err) => {
|
|
8389
|
+
clearFlowState();
|
|
8390
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
8391
|
+
},
|
|
8392
|
+
onSubmit: async (payload) => handleSubmit({ flowId: payload.flowId, inputs: payload.inputs }),
|
|
8393
|
+
processedRef: oauthCodeProcessedRef,
|
|
8394
|
+
setFlowId
|
|
8395
|
+
});
|
|
8396
|
+
useEffect13(() => {
|
|
8288
8397
|
if (!passkeyState.isActive || !passkeyState.challenge && !passkeyState.creationOptions || !passkeyState.flowId) {
|
|
8289
8398
|
return;
|
|
8290
8399
|
}
|
|
@@ -8423,7 +8532,7 @@ import {
|
|
|
8423
8532
|
createPackageComponentLogger as createPackageComponentLogger6
|
|
8424
8533
|
} from "@asgardeo/browser";
|
|
8425
8534
|
import { cx as cx21 } from "@emotion/css";
|
|
8426
|
-
import { useEffect as
|
|
8535
|
+
import { useEffect as useEffect14, useState as useState16, useCallback as useCallback10, useRef as useRef6 } from "react";
|
|
8427
8536
|
|
|
8428
8537
|
// src/components/presentation/auth/SignUp/v1/SignUpOptionFactory.tsx
|
|
8429
8538
|
import { EmbeddedFlowComponentType as EmbeddedFlowComponentType2 } from "@asgardeo/browser";
|
|
@@ -9171,7 +9280,7 @@ var BaseSignUpContent = ({
|
|
|
9171
9280
|
const [isLoading, setIsLoading] = useState16(false);
|
|
9172
9281
|
const [isFlowInitialized, setIsFlowInitialized] = useState16(false);
|
|
9173
9282
|
const [currentFlow, setCurrentFlow] = useState16(null);
|
|
9174
|
-
const initializationAttemptedRef =
|
|
9283
|
+
const initializationAttemptedRef = useRef6(false);
|
|
9175
9284
|
const extractFormFields = useCallback10(
|
|
9176
9285
|
(components) => {
|
|
9177
9286
|
const fields = [];
|
|
@@ -9457,7 +9566,7 @@ var BaseSignUpContent = ({
|
|
|
9457
9566
|
handleSubmit
|
|
9458
9567
|
]
|
|
9459
9568
|
);
|
|
9460
|
-
|
|
9569
|
+
useEffect14(() => {
|
|
9461
9570
|
if (isInitialized && !isFlowInitialized && !initializationAttemptedRef.current) {
|
|
9462
9571
|
initializationAttemptedRef.current = true;
|
|
9463
9572
|
(async () => {
|
|
@@ -9558,7 +9667,7 @@ import {
|
|
|
9558
9667
|
createPackageComponentLogger as createPackageComponentLogger7
|
|
9559
9668
|
} from "@asgardeo/browser";
|
|
9560
9669
|
import { cx as cx22 } from "@emotion/css";
|
|
9561
|
-
import { useEffect as
|
|
9670
|
+
import { useEffect as useEffect15, useState as useState17, useCallback as useCallback11, useRef as useRef7 } from "react";
|
|
9562
9671
|
import { jsx as jsx68, jsxs as jsxs29 } from "react/jsx-runtime";
|
|
9563
9672
|
var logger7 = createPackageComponentLogger7(
|
|
9564
9673
|
"@asgardeo/react",
|
|
@@ -9600,8 +9709,8 @@ var BaseSignUpContent2 = ({
|
|
|
9600
9709
|
flowId: null,
|
|
9601
9710
|
isActive: false
|
|
9602
9711
|
});
|
|
9603
|
-
const initializationAttemptedRef =
|
|
9604
|
-
const passkeyProcessedRef =
|
|
9712
|
+
const initializationAttemptedRef = useRef7(false);
|
|
9713
|
+
const passkeyProcessedRef = useRef7(false);
|
|
9605
9714
|
const handleError = useCallback11(
|
|
9606
9715
|
(error) => {
|
|
9607
9716
|
const errorMessage = error?.failureReason || extractErrorMessage(error, t);
|
|
@@ -9889,7 +9998,7 @@ var BaseSignUpContent2 = ({
|
|
|
9889
9998
|
setIsLoading(false);
|
|
9890
9999
|
}
|
|
9891
10000
|
};
|
|
9892
|
-
|
|
10001
|
+
useEffect15(() => {
|
|
9893
10002
|
if (!passkeyState.isActive || !passkeyState.creationOptions || !passkeyState.flowId) {
|
|
9894
10003
|
return;
|
|
9895
10004
|
}
|
|
@@ -9995,7 +10104,7 @@ var BaseSignUpContent2 = ({
|
|
|
9995
10104
|
state: urlParams.get("state")
|
|
9996
10105
|
};
|
|
9997
10106
|
};
|
|
9998
|
-
|
|
10107
|
+
useEffect15(() => {
|
|
9999
10108
|
const urlParams = getUrlParams2();
|
|
10000
10109
|
if (urlParams.code || urlParams.state) {
|
|
10001
10110
|
return;
|
|
@@ -10257,7 +10366,7 @@ import { EmbeddedFlowType as EmbeddedFlowType5 } from "@asgardeo/browser";
|
|
|
10257
10366
|
// src/components/presentation/auth/InviteUser/v2/BaseInviteUser.tsx
|
|
10258
10367
|
import { EmbeddedFlowType as EmbeddedFlowType4 } from "@asgardeo/browser";
|
|
10259
10368
|
import { cx as cx23 } from "@emotion/css";
|
|
10260
|
-
import { useCallback as useCallback12, useEffect as
|
|
10369
|
+
import { useCallback as useCallback12, useEffect as useEffect16, useRef as useRef8, useState as useState18 } from "react";
|
|
10261
10370
|
|
|
10262
10371
|
// src/components/presentation/auth/InviteUser/v2/BaseInviteUser.styles.ts
|
|
10263
10372
|
import { css as css18 } from "@emotion/css";
|
|
@@ -10326,7 +10435,7 @@ var BaseInviteUser = ({
|
|
|
10326
10435
|
const [inviteLink, setInviteLink] = useState18();
|
|
10327
10436
|
const [inviteLinkCopied, setInviteLinkCopied] = useState18(false);
|
|
10328
10437
|
const [isFormValid, setIsFormValid] = useState18(true);
|
|
10329
|
-
const initializationAttemptedRef =
|
|
10438
|
+
const initializationAttemptedRef = useRef8(false);
|
|
10330
10439
|
const handleError = useCallback12(
|
|
10331
10440
|
(error) => {
|
|
10332
10441
|
const errorMessage = error?.failureReason || extractErrorMessage(error, t, "components.inviteUser.errors.generic");
|
|
@@ -10484,7 +10593,7 @@ var BaseInviteUser = ({
|
|
|
10484
10593
|
setInviteLinkCopied(false);
|
|
10485
10594
|
initializationAttemptedRef.current = false;
|
|
10486
10595
|
}, []);
|
|
10487
|
-
|
|
10596
|
+
useEffect16(() => {
|
|
10488
10597
|
if (isInitialized && !isFlowInitialized && !initializationAttemptedRef.current) {
|
|
10489
10598
|
initializationAttemptedRef.current = true;
|
|
10490
10599
|
(async () => {
|
|
@@ -10511,7 +10620,7 @@ var BaseInviteUser = ({
|
|
|
10511
10620
|
})();
|
|
10512
10621
|
}
|
|
10513
10622
|
}, [isInitialized, isFlowInitialized, onInitialize, onFlowChange, handleError, normalizeFlowResponseLocal]);
|
|
10514
|
-
|
|
10623
|
+
useEffect16(() => {
|
|
10515
10624
|
if (currentFlow && isFlowInitialized) {
|
|
10516
10625
|
const components2 = currentFlow.data?.components || [];
|
|
10517
10626
|
if (components2.length > 0) {
|
|
@@ -10724,7 +10833,7 @@ import { useMemo as useMemo27 } from "react";
|
|
|
10724
10833
|
|
|
10725
10834
|
// src/components/presentation/auth/AcceptInvite/v2/BaseAcceptInvite.tsx
|
|
10726
10835
|
import { cx as cx24 } from "@emotion/css";
|
|
10727
|
-
import { useCallback as useCallback13, useEffect as
|
|
10836
|
+
import { useCallback as useCallback13, useEffect as useEffect17, useRef as useRef9, useState as useState19 } from "react";
|
|
10728
10837
|
|
|
10729
10838
|
// src/components/presentation/auth/AcceptInvite/v2/BaseAcceptInvite.styles.ts
|
|
10730
10839
|
import { css as css19 } from "@emotion/css";
|
|
@@ -10795,7 +10904,7 @@ var BaseAcceptInvite = ({
|
|
|
10795
10904
|
const [touchedFields, setTouchedFields] = useState19({});
|
|
10796
10905
|
const [isFormValid, setIsFormValid] = useState19(true);
|
|
10797
10906
|
const [completionTitle, setCompletionTitle] = useState19(void 0);
|
|
10798
|
-
const tokenValidationAttemptedRef =
|
|
10907
|
+
const tokenValidationAttemptedRef = useRef9(false);
|
|
10799
10908
|
const handleError = useCallback13(
|
|
10800
10909
|
(error) => {
|
|
10801
10910
|
const errorMessage = error?.failureReason || extractErrorMessage(error, t, "components.acceptInvite.errors.generic");
|
|
@@ -10827,6 +10936,38 @@ var BaseAcceptInvite = ({
|
|
|
10827
10936
|
},
|
|
10828
10937
|
[t, children]
|
|
10829
10938
|
);
|
|
10939
|
+
useOAuthCallback({
|
|
10940
|
+
currentFlowId: flowId ?? null,
|
|
10941
|
+
isInitialized: true,
|
|
10942
|
+
onComplete: () => {
|
|
10943
|
+
setIsComplete(true);
|
|
10944
|
+
setIsValidatingToken(false);
|
|
10945
|
+
onComplete?.();
|
|
10946
|
+
},
|
|
10947
|
+
onError: (error) => {
|
|
10948
|
+
setIsTokenInvalid(true);
|
|
10949
|
+
setIsValidatingToken(false);
|
|
10950
|
+
handleError(error);
|
|
10951
|
+
},
|
|
10952
|
+
onFlowChange: (response) => {
|
|
10953
|
+
onFlowChange?.(response);
|
|
10954
|
+
if (response.flowStatus !== "COMPLETE") {
|
|
10955
|
+
setCurrentFlow(response);
|
|
10956
|
+
setFormValues({});
|
|
10957
|
+
setFormErrors({});
|
|
10958
|
+
setTouchedFields({});
|
|
10959
|
+
}
|
|
10960
|
+
},
|
|
10961
|
+
onProcessingStart: () => {
|
|
10962
|
+
setIsValidatingToken(true);
|
|
10963
|
+
},
|
|
10964
|
+
onSubmit: async (payload) => {
|
|
10965
|
+
const rawResponse = await onSubmit(payload);
|
|
10966
|
+
const response = normalizeFlowResponseLocal(rawResponse);
|
|
10967
|
+
return response;
|
|
10968
|
+
},
|
|
10969
|
+
tokenValidationAttemptedRef
|
|
10970
|
+
});
|
|
10830
10971
|
const handleInputChange = useCallback13((name, value) => {
|
|
10831
10972
|
setFormValues((prev) => ({ ...prev, [name]: value }));
|
|
10832
10973
|
setFormErrors((prev) => {
|
|
@@ -10892,6 +11033,13 @@ var BaseAcceptInvite = ({
|
|
|
10892
11033
|
const rawResponse = await onSubmit(payload);
|
|
10893
11034
|
const response = normalizeFlowResponseLocal(rawResponse);
|
|
10894
11035
|
onFlowChange?.(response);
|
|
11036
|
+
if (response.type === "REDIRECTION") {
|
|
11037
|
+
const redirectURL = response.data?.redirectURL || response?.redirectURL;
|
|
11038
|
+
if (redirectURL && typeof window !== "undefined") {
|
|
11039
|
+
initiateOAuthRedirect(redirectURL);
|
|
11040
|
+
return;
|
|
11041
|
+
}
|
|
11042
|
+
}
|
|
10895
11043
|
if (currentFlow?.data?.components || currentFlow?.data?.meta?.components) {
|
|
10896
11044
|
const currentComponents = currentFlow.data.components || currentFlow.data.meta?.components || [];
|
|
10897
11045
|
const heading = currentComponents.find(
|
|
@@ -10931,13 +11079,14 @@ var BaseAcceptInvite = ({
|
|
|
10931
11079
|
normalizeFlowResponseLocal
|
|
10932
11080
|
]
|
|
10933
11081
|
);
|
|
10934
|
-
|
|
10935
|
-
if (
|
|
10936
|
-
|
|
10937
|
-
|
|
10938
|
-
|
|
10939
|
-
|
|
10940
|
-
|
|
11082
|
+
useEffect17(() => {
|
|
11083
|
+
if (tokenValidationAttemptedRef.current) {
|
|
11084
|
+
return;
|
|
11085
|
+
}
|
|
11086
|
+
if (!flowId || !inviteToken) {
|
|
11087
|
+
setIsValidatingToken(false);
|
|
11088
|
+
setIsTokenInvalid(true);
|
|
11089
|
+
handleError(new Error("Invalid invite link. Missing flowId or inviteToken."));
|
|
10941
11090
|
return;
|
|
10942
11091
|
}
|
|
10943
11092
|
tokenValidationAttemptedRef.current = true;
|
|
@@ -10945,6 +11094,9 @@ var BaseAcceptInvite = ({
|
|
|
10945
11094
|
setIsValidatingToken(true);
|
|
10946
11095
|
setApiError(null);
|
|
10947
11096
|
try {
|
|
11097
|
+
if (flowId) {
|
|
11098
|
+
sessionStorage.setItem("asgardeo_flow_id", flowId);
|
|
11099
|
+
}
|
|
10948
11100
|
const payload = {
|
|
10949
11101
|
flowId,
|
|
10950
11102
|
inputs: {
|
|
@@ -11171,6 +11323,95 @@ var AcceptInvite = ({
|
|
|
11171
11323
|
};
|
|
11172
11324
|
var AcceptInvite_default = AcceptInvite;
|
|
11173
11325
|
|
|
11326
|
+
// src/components/auth/Callback/Callback.tsx
|
|
11327
|
+
import { navigate as browserNavigate } from "@asgardeo/browser";
|
|
11328
|
+
import { useEffect as useEffect18, useRef as useRef10 } from "react";
|
|
11329
|
+
var Callback = ({ onNavigate, onError }) => {
|
|
11330
|
+
const processingRef = useRef10(false);
|
|
11331
|
+
const navigate6 = (path) => {
|
|
11332
|
+
if (onNavigate) {
|
|
11333
|
+
onNavigate(path);
|
|
11334
|
+
} else {
|
|
11335
|
+
browserNavigate(path);
|
|
11336
|
+
}
|
|
11337
|
+
};
|
|
11338
|
+
useEffect18(() => {
|
|
11339
|
+
const processOAuthCallback = () => {
|
|
11340
|
+
if (processingRef.current) {
|
|
11341
|
+
return;
|
|
11342
|
+
}
|
|
11343
|
+
processingRef.current = true;
|
|
11344
|
+
let returnPath = "/";
|
|
11345
|
+
try {
|
|
11346
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
11347
|
+
const code = urlParams.get("code");
|
|
11348
|
+
const state = urlParams.get("state");
|
|
11349
|
+
const nonce = urlParams.get("nonce");
|
|
11350
|
+
const oauthError = urlParams.get("error");
|
|
11351
|
+
const errorDescription = urlParams.get("error_description");
|
|
11352
|
+
if (!state) {
|
|
11353
|
+
throw new Error("Missing OAuth state parameter - possible security issue");
|
|
11354
|
+
}
|
|
11355
|
+
const storedData = sessionStorage.getItem(`asgardeo_oauth_${state}`);
|
|
11356
|
+
if (!storedData) {
|
|
11357
|
+
if (oauthError) {
|
|
11358
|
+
const errorMsg = errorDescription || oauthError || "OAuth authentication failed";
|
|
11359
|
+
const err = new Error(errorMsg);
|
|
11360
|
+
onError?.(err);
|
|
11361
|
+
const params2 = new URLSearchParams();
|
|
11362
|
+
params2.set("error", oauthError);
|
|
11363
|
+
if (errorDescription) {
|
|
11364
|
+
params2.set("error_description", errorDescription);
|
|
11365
|
+
}
|
|
11366
|
+
navigate6(`/?${params2.toString()}`);
|
|
11367
|
+
return;
|
|
11368
|
+
}
|
|
11369
|
+
throw new Error("Invalid OAuth state - possible CSRF attack");
|
|
11370
|
+
}
|
|
11371
|
+
const { path, timestamp } = JSON.parse(storedData);
|
|
11372
|
+
returnPath = path || "/";
|
|
11373
|
+
const MAX_STATE_AGE = 6e5;
|
|
11374
|
+
if (Date.now() - timestamp > MAX_STATE_AGE) {
|
|
11375
|
+
sessionStorage.removeItem(`asgardeo_oauth_${state}`);
|
|
11376
|
+
throw new Error("OAuth state expired - please try again");
|
|
11377
|
+
}
|
|
11378
|
+
sessionStorage.removeItem(`asgardeo_oauth_${state}`);
|
|
11379
|
+
if (oauthError) {
|
|
11380
|
+
const errorMsg = errorDescription || oauthError || "OAuth authentication failed";
|
|
11381
|
+
const err = new Error(errorMsg);
|
|
11382
|
+
onError?.(err);
|
|
11383
|
+
const params2 = new URLSearchParams();
|
|
11384
|
+
params2.set("error", oauthError);
|
|
11385
|
+
if (errorDescription) {
|
|
11386
|
+
params2.set("error_description", errorDescription);
|
|
11387
|
+
}
|
|
11388
|
+
navigate6(`${returnPath}?${params2.toString()}`);
|
|
11389
|
+
return;
|
|
11390
|
+
}
|
|
11391
|
+
if (!code) {
|
|
11392
|
+
throw new Error("Missing OAuth authorization code");
|
|
11393
|
+
}
|
|
11394
|
+
const params = new URLSearchParams();
|
|
11395
|
+
params.set("code", code);
|
|
11396
|
+
if (nonce) {
|
|
11397
|
+
params.set("nonce", nonce);
|
|
11398
|
+
}
|
|
11399
|
+
navigate6(`${returnPath}?${params.toString()}`);
|
|
11400
|
+
} catch (err) {
|
|
11401
|
+
const errorMessage = err instanceof Error ? err.message : "OAuth callback processing failed";
|
|
11402
|
+
console.error("OAuth callback error:", err);
|
|
11403
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11404
|
+
const params = new URLSearchParams();
|
|
11405
|
+
params.set("error", "callback_error");
|
|
11406
|
+
params.set("error_description", errorMessage);
|
|
11407
|
+
navigate6(`${returnPath}?${params.toString()}`);
|
|
11408
|
+
}
|
|
11409
|
+
};
|
|
11410
|
+
processOAuthCallback();
|
|
11411
|
+
}, [onNavigate, onError]);
|
|
11412
|
+
return null;
|
|
11413
|
+
};
|
|
11414
|
+
|
|
11174
11415
|
// src/components/presentation/User/BaseUser.tsx
|
|
11175
11416
|
import { Fragment as Fragment13, jsx as jsx77 } from "react/jsx-runtime";
|
|
11176
11417
|
var BaseUser = ({ user, children, fallback = null }) => {
|
|
@@ -14271,7 +14512,7 @@ var CreateOrganization = ({
|
|
|
14271
14512
|
|
|
14272
14513
|
// src/components/presentation/OrganizationList/OrganizationList.tsx
|
|
14273
14514
|
import { cx as cx33 } from "@emotion/css";
|
|
14274
|
-
import { useEffect as
|
|
14515
|
+
import { useEffect as useEffect19, useState as useState29 } from "react";
|
|
14275
14516
|
|
|
14276
14517
|
// src/components/presentation/OrganizationList/BaseOrganizationList.tsx
|
|
14277
14518
|
import { cx as cx32 } from "@emotion/css";
|
|
@@ -14729,7 +14970,7 @@ var OrganizationList = (props) => {
|
|
|
14729
14970
|
const [allOrganizations, setAllOrganizations] = useState29({
|
|
14730
14971
|
organizations: []
|
|
14731
14972
|
});
|
|
14732
|
-
|
|
14973
|
+
useEffect19(() => {
|
|
14733
14974
|
(async () => {
|
|
14734
14975
|
setAllOrganizations(await getAllOrganizations2());
|
|
14735
14976
|
})();
|
|
@@ -14750,7 +14991,7 @@ var OrganizationList_default = OrganizationList;
|
|
|
14750
14991
|
|
|
14751
14992
|
// src/components/presentation/OrganizationProfile/OrganizationProfile.tsx
|
|
14752
14993
|
import { createPackageComponentLogger as createPackageComponentLogger9 } from "@asgardeo/browser";
|
|
14753
|
-
import { useEffect as
|
|
14994
|
+
import { useEffect as useEffect20, useState as useState32 } from "react";
|
|
14754
14995
|
|
|
14755
14996
|
// src/components/presentation/OrganizationProfile/BaseOrganizationProfile.tsx
|
|
14756
14997
|
import { formatDate } from "@asgardeo/browser";
|
|
@@ -15661,7 +15902,7 @@ var OrganizationProfile = ({
|
|
|
15661
15902
|
setOrganization(null);
|
|
15662
15903
|
}
|
|
15663
15904
|
};
|
|
15664
|
-
|
|
15905
|
+
useEffect20(() => {
|
|
15665
15906
|
fetchOrganization();
|
|
15666
15907
|
}, [baseUrl, organizationId]);
|
|
15667
15908
|
const handleOrganizationUpdate = async (payload) => {
|
|
@@ -15811,7 +16052,7 @@ import {
|
|
|
15811
16052
|
AsgardeoRuntimeError as AsgardeoRuntimeError9,
|
|
15812
16053
|
http,
|
|
15813
16054
|
getActiveTheme as getActiveTheme2,
|
|
15814
|
-
navigate as
|
|
16055
|
+
navigate as navigate5,
|
|
15815
16056
|
EmbeddedFlowComponentTypeV2,
|
|
15816
16057
|
EmbeddedFlowActionVariantV2,
|
|
15817
16058
|
EmbeddedFlowTextVariantV2,
|
|
@@ -15844,6 +16085,7 @@ export {
|
|
|
15844
16085
|
BrandingProvider_default as BrandingProvider,
|
|
15845
16086
|
BuildingAlt_default as BuildingAlt,
|
|
15846
16087
|
Button_default as Button,
|
|
16088
|
+
Callback,
|
|
15847
16089
|
Card_default as Card,
|
|
15848
16090
|
Checkbox_default as Checkbox,
|
|
15849
16091
|
CircleAlert_default as CircleAlert,
|
|
@@ -15926,7 +16168,7 @@ export {
|
|
|
15926
16168
|
getOrganization_default as getOrganization,
|
|
15927
16169
|
getSchemas_default as getSchemas,
|
|
15928
16170
|
http,
|
|
15929
|
-
|
|
16171
|
+
navigate5 as navigate,
|
|
15930
16172
|
updateMeProfile_default as updateMeProfile,
|
|
15931
16173
|
updateOrganization_default as updateOrganization,
|
|
15932
16174
|
useAsgardeo_default as useAsgardeo,
|