@asgardeo/react 0.6.6 → 0.6.8
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 +148 -17
- package/dist/cjs/index.js.map +2 -2
- package/dist/index.js +156 -23
- package/dist/index.js.map +3 -3
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -742,12 +742,21 @@ var AsgardeoReactClient = class extends AsgardeoBrowserClient {
|
|
|
742
742
|
const arg1 = args[0];
|
|
743
743
|
const arg2 = args[1];
|
|
744
744
|
const config = await this.asgardeo.getConfigData();
|
|
745
|
-
|
|
746
|
-
|
|
745
|
+
const platformFromStorage = sessionStorage.getItem("asgardeo_platform");
|
|
746
|
+
const isV2Platform = config && config.platform === Platform.AsgardeoV2 || platformFromStorage === "AsgardeoV2";
|
|
747
|
+
if (isV2Platform && typeof arg1 === "object" && arg1 !== null && arg1.callOnlyOnRedirect === true) {
|
|
748
|
+
return void 0;
|
|
749
|
+
}
|
|
750
|
+
if (isV2Platform && typeof arg1 === "object" && arg1 !== null && !isEmpty(arg1) && ("flowId" in arg1 || "applicationId" in arg1)) {
|
|
751
|
+
const sessionDataKeyFromUrl = new URL(window.location.href).searchParams.get("sessionDataKey");
|
|
752
|
+
const sessionDataKeyFromStorage = sessionStorage.getItem("asgardeo_session_data_key");
|
|
753
|
+
const sessionDataKey = sessionDataKeyFromUrl || sessionDataKeyFromStorage;
|
|
754
|
+
const baseUrlFromStorage = sessionStorage.getItem("asgardeo_base_url");
|
|
755
|
+
const baseUrl = config?.baseUrl || baseUrlFromStorage;
|
|
747
756
|
return executeEmbeddedSignInFlowV2({
|
|
748
757
|
payload: arg1,
|
|
749
758
|
url: arg2?.url,
|
|
750
|
-
baseUrl
|
|
759
|
+
baseUrl,
|
|
751
760
|
sessionDataKey
|
|
752
761
|
});
|
|
753
762
|
}
|
|
@@ -1503,7 +1512,14 @@ var AsgardeoProvider = ({
|
|
|
1503
1512
|
useEffect5(() => {
|
|
1504
1513
|
(async () => {
|
|
1505
1514
|
await asgardeo.initialize(config);
|
|
1506
|
-
|
|
1515
|
+
const initializedConfig = await asgardeo.getConfiguration();
|
|
1516
|
+
setConfig(initializedConfig);
|
|
1517
|
+
if (initializedConfig?.platform) {
|
|
1518
|
+
sessionStorage.setItem("asgardeo_platform", initializedConfig.platform);
|
|
1519
|
+
}
|
|
1520
|
+
if (initializedConfig?.baseUrl) {
|
|
1521
|
+
sessionStorage.setItem("asgardeo_base_url", initializedConfig.baseUrl);
|
|
1522
|
+
}
|
|
1507
1523
|
})();
|
|
1508
1524
|
}, []);
|
|
1509
1525
|
useEffect5(() => {
|
|
@@ -1519,7 +1535,8 @@ var AsgardeoProvider = ({
|
|
|
1519
1535
|
}
|
|
1520
1536
|
const currentUrl = new URL(window.location.href);
|
|
1521
1537
|
const hasAuthParamsResult = hasAuthParams(currentUrl, afterSignInUrl);
|
|
1522
|
-
|
|
1538
|
+
const isV2Platform = config.platform === Platform2.AsgardeoV2;
|
|
1539
|
+
if (hasAuthParamsResult && !isV2Platform) {
|
|
1523
1540
|
try {
|
|
1524
1541
|
await signIn(
|
|
1525
1542
|
{ callOnlyOnRedirect: true }
|
|
@@ -1674,19 +1691,28 @@ var AsgardeoProvider = ({
|
|
|
1674
1691
|
fetchBranding
|
|
1675
1692
|
]);
|
|
1676
1693
|
const signIn = async (...args) => {
|
|
1694
|
+
const arg1 = args[0];
|
|
1695
|
+
const isV2FlowRequest = config.platform === Platform2.AsgardeoV2 && typeof arg1 === "object" && arg1 !== null && ("flowId" in arg1 || "applicationId" in arg1);
|
|
1677
1696
|
try {
|
|
1678
|
-
|
|
1679
|
-
|
|
1697
|
+
if (!isV2FlowRequest) {
|
|
1698
|
+
setIsUpdatingSession(true);
|
|
1699
|
+
setIsLoadingSync(true);
|
|
1700
|
+
}
|
|
1680
1701
|
const response = await asgardeo.signIn(...args);
|
|
1702
|
+
if (isV2FlowRequest || response && typeof response === "object" && "flowStatus" in response) {
|
|
1703
|
+
return response;
|
|
1704
|
+
}
|
|
1681
1705
|
if (await asgardeo.isSignedIn()) {
|
|
1682
1706
|
await updateSession();
|
|
1683
1707
|
}
|
|
1684
1708
|
return response;
|
|
1685
1709
|
} catch (error) {
|
|
1686
|
-
throw new Error(`Error while signing in: ${error}`);
|
|
1710
|
+
throw new Error(`Error while signing in: ${error instanceof Error ? error.message : String(error)}`);
|
|
1687
1711
|
} finally {
|
|
1688
|
-
|
|
1689
|
-
|
|
1712
|
+
if (!isV2FlowRequest) {
|
|
1713
|
+
setIsUpdatingSession(false);
|
|
1714
|
+
setIsLoadingSync(asgardeo.isLoading());
|
|
1715
|
+
}
|
|
1690
1716
|
}
|
|
1691
1717
|
};
|
|
1692
1718
|
const signInSilently = async (options) => {
|
|
@@ -7412,7 +7438,8 @@ import { useState as useState16, useEffect as useEffect13, useRef as useRef4 } f
|
|
|
7412
7438
|
import {
|
|
7413
7439
|
AsgardeoRuntimeError as AsgardeoRuntimeError8,
|
|
7414
7440
|
EmbeddedFlowType,
|
|
7415
|
-
EmbeddedSignInFlowStatusV2
|
|
7441
|
+
EmbeddedSignInFlowStatusV2,
|
|
7442
|
+
EmbeddedSignInFlowTypeV2
|
|
7416
7443
|
} from "@asgardeo/browser";
|
|
7417
7444
|
|
|
7418
7445
|
// src/components/presentation/SignIn/component-driven/transformer.ts
|
|
@@ -7541,16 +7568,62 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7541
7568
|
const [flowError, setFlowError] = useState16(null);
|
|
7542
7569
|
const [isSubmitting, setIsSubmitting] = useState16(false);
|
|
7543
7570
|
const initializationAttemptedRef = useRef4(false);
|
|
7571
|
+
const oauthCodeProcessedRef = useRef4(false);
|
|
7572
|
+
const handleRedirection = (response) => {
|
|
7573
|
+
if (response.type === EmbeddedSignInFlowTypeV2.Redirection) {
|
|
7574
|
+
const redirectURL = response.data?.redirectURL || response?.redirectURL;
|
|
7575
|
+
if (redirectURL) {
|
|
7576
|
+
if (response.flowId) {
|
|
7577
|
+
sessionStorage.setItem("asgardeo_flow_id", response.flowId);
|
|
7578
|
+
}
|
|
7579
|
+
const urlParams = new URL(window.location.href).searchParams;
|
|
7580
|
+
const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
|
|
7581
|
+
if (sessionDataKeyFromUrl) {
|
|
7582
|
+
sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
|
|
7583
|
+
}
|
|
7584
|
+
window.location.href = redirectURL;
|
|
7585
|
+
return true;
|
|
7586
|
+
}
|
|
7587
|
+
}
|
|
7588
|
+
return false;
|
|
7589
|
+
};
|
|
7544
7590
|
useEffect13(() => {
|
|
7545
|
-
|
|
7591
|
+
const storedFlowId = sessionStorage.getItem("asgardeo_flow_id");
|
|
7592
|
+
const urlParams = new URL(window.location.href).searchParams;
|
|
7593
|
+
const code = urlParams.get("code");
|
|
7594
|
+
const state = urlParams.get("state");
|
|
7595
|
+
const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
|
|
7596
|
+
if (sessionDataKeyFromUrl) {
|
|
7597
|
+
sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
|
|
7598
|
+
}
|
|
7599
|
+
if (code) {
|
|
7600
|
+
const flowIdFromUrl = urlParams.get("flowId");
|
|
7601
|
+
const flowIdFromState = state || flowIdFromUrl || storedFlowId;
|
|
7602
|
+
if (flowIdFromState) {
|
|
7603
|
+
setCurrentFlowId(flowIdFromState);
|
|
7604
|
+
setIsFlowInitialized(true);
|
|
7605
|
+
sessionStorage.setItem("asgardeo_flow_id", flowIdFromState);
|
|
7606
|
+
initializationAttemptedRef.current = true;
|
|
7607
|
+
}
|
|
7608
|
+
return;
|
|
7609
|
+
}
|
|
7610
|
+
if (isInitialized && !isLoading && !isFlowInitialized && !initializationAttemptedRef.current && !currentFlowId) {
|
|
7546
7611
|
initializationAttemptedRef.current = true;
|
|
7547
7612
|
initializeFlow();
|
|
7548
7613
|
}
|
|
7549
|
-
}, [isInitialized, isLoading, isFlowInitialized]);
|
|
7614
|
+
}, [isInitialized, isLoading, isFlowInitialized, currentFlowId]);
|
|
7550
7615
|
const initializeFlow = async () => {
|
|
7551
7616
|
const urlParams = new URL(window.location.href).searchParams;
|
|
7617
|
+
const code = urlParams.get("code");
|
|
7618
|
+
if (code) {
|
|
7619
|
+
return;
|
|
7620
|
+
}
|
|
7552
7621
|
const flowIdFromUrl = urlParams.get("flowId");
|
|
7553
7622
|
const applicationIdFromUrl = urlParams.get("applicationId");
|
|
7623
|
+
const sessionDataKeyFromUrl = urlParams.get("sessionDataKey");
|
|
7624
|
+
if (sessionDataKeyFromUrl) {
|
|
7625
|
+
sessionStorage.setItem("asgardeo_session_data_key", sessionDataKeyFromUrl);
|
|
7626
|
+
}
|
|
7554
7627
|
const effectiveApplicationId = applicationId || applicationIdFromUrl;
|
|
7555
7628
|
if (!flowIdFromUrl && !effectiveApplicationId) {
|
|
7556
7629
|
const error = new AsgardeoRuntimeError8(
|
|
@@ -7575,6 +7648,9 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7575
7648
|
flowType: EmbeddedFlowType.Authentication
|
|
7576
7649
|
});
|
|
7577
7650
|
}
|
|
7651
|
+
if (handleRedirection(response)) {
|
|
7652
|
+
return;
|
|
7653
|
+
}
|
|
7578
7654
|
const { flowId, components: components2 } = normalizeFlowResponse(response, t);
|
|
7579
7655
|
if (flowId && components2) {
|
|
7580
7656
|
setCurrentFlowId(flowId);
|
|
@@ -7594,29 +7670,53 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7594
7670
|
}
|
|
7595
7671
|
};
|
|
7596
7672
|
const handleSubmit = async (payload) => {
|
|
7597
|
-
|
|
7673
|
+
const effectiveFlowId = payload.flowId || currentFlowId;
|
|
7674
|
+
if (!effectiveFlowId) {
|
|
7675
|
+
console.error("[SignIn] handleSubmit - ERROR: No flowId available", {
|
|
7676
|
+
payloadFlowId: payload.flowId,
|
|
7677
|
+
currentFlowId
|
|
7678
|
+
});
|
|
7598
7679
|
throw new Error("No active flow ID");
|
|
7599
7680
|
}
|
|
7600
7681
|
try {
|
|
7601
7682
|
setIsSubmitting(true);
|
|
7602
7683
|
setFlowError(null);
|
|
7603
7684
|
const response = await signIn({
|
|
7604
|
-
flowId:
|
|
7685
|
+
flowId: effectiveFlowId,
|
|
7605
7686
|
...payload
|
|
7606
7687
|
});
|
|
7688
|
+
if (handleRedirection(response)) {
|
|
7689
|
+
return;
|
|
7690
|
+
}
|
|
7607
7691
|
const { flowId, components: components2 } = normalizeFlowResponse(response, t);
|
|
7608
7692
|
if (response.flowStatus === EmbeddedSignInFlowStatusV2.Complete) {
|
|
7693
|
+
const redirectUrl = response.redirectUrl || response.redirect_uri;
|
|
7694
|
+
sessionStorage.removeItem("asgardeo_flow_id");
|
|
7695
|
+
if (redirectUrl) {
|
|
7696
|
+
sessionStorage.removeItem("asgardeo_session_data_key");
|
|
7697
|
+
}
|
|
7698
|
+
const url = new URL(window.location.href);
|
|
7699
|
+
url.searchParams.delete("code");
|
|
7700
|
+
url.searchParams.delete("state");
|
|
7701
|
+
url.searchParams.delete("nonce");
|
|
7702
|
+
window.history.replaceState({}, "", url.toString());
|
|
7703
|
+
const finalRedirectUrl = redirectUrl || afterSignInUrl;
|
|
7609
7704
|
onSuccess && onSuccess({
|
|
7610
|
-
redirectUrl:
|
|
7705
|
+
redirectUrl: finalRedirectUrl,
|
|
7611
7706
|
...response.data
|
|
7612
7707
|
});
|
|
7613
|
-
|
|
7708
|
+
if (finalRedirectUrl) {
|
|
7709
|
+
window.location.href = finalRedirectUrl;
|
|
7710
|
+
}
|
|
7614
7711
|
return;
|
|
7615
7712
|
}
|
|
7616
7713
|
if (flowId && components2) {
|
|
7617
7714
|
setCurrentFlowId(flowId);
|
|
7618
7715
|
setComponents(components2);
|
|
7619
7716
|
}
|
|
7717
|
+
if (!currentFlowId && effectiveFlowId) {
|
|
7718
|
+
setCurrentFlowId(effectiveFlowId);
|
|
7719
|
+
}
|
|
7620
7720
|
} catch (error) {
|
|
7621
7721
|
const err = error;
|
|
7622
7722
|
setFlowError(err);
|
|
@@ -7636,6 +7736,36 @@ var SignIn = ({ className, size = "medium", onSuccess, onError, variant, childre
|
|
|
7636
7736
|
setFlowError(error);
|
|
7637
7737
|
onError?.(error);
|
|
7638
7738
|
};
|
|
7739
|
+
useEffect13(() => {
|
|
7740
|
+
const urlParams = new URL(window.location.href).searchParams;
|
|
7741
|
+
const code = urlParams.get("code");
|
|
7742
|
+
const nonce = urlParams.get("nonce");
|
|
7743
|
+
const state = urlParams.get("state");
|
|
7744
|
+
const flowIdFromUrl = urlParams.get("flowId");
|
|
7745
|
+
const storedFlowId = sessionStorage.getItem("asgardeo_flow_id");
|
|
7746
|
+
if (!code || oauthCodeProcessedRef.current || isSubmitting) {
|
|
7747
|
+
return;
|
|
7748
|
+
}
|
|
7749
|
+
const flowIdToUse = currentFlowId || state || flowIdFromUrl || storedFlowId;
|
|
7750
|
+
if (!flowIdToUse || !signIn) {
|
|
7751
|
+
return;
|
|
7752
|
+
}
|
|
7753
|
+
oauthCodeProcessedRef.current = true;
|
|
7754
|
+
if (!currentFlowId) {
|
|
7755
|
+
setCurrentFlowId(flowIdToUse);
|
|
7756
|
+
setIsFlowInitialized(true);
|
|
7757
|
+
}
|
|
7758
|
+
const submitPayload = {
|
|
7759
|
+
flowId: flowIdToUse,
|
|
7760
|
+
inputs: {
|
|
7761
|
+
code,
|
|
7762
|
+
...nonce && { nonce }
|
|
7763
|
+
}
|
|
7764
|
+
};
|
|
7765
|
+
handleSubmit(submitPayload).catch(() => {
|
|
7766
|
+
oauthCodeProcessedRef.current = false;
|
|
7767
|
+
});
|
|
7768
|
+
}, [isFlowInitialized, currentFlowId, isInitialized, isLoading, isSubmitting, signIn]);
|
|
7639
7769
|
if (children) {
|
|
7640
7770
|
const renderProps = {
|
|
7641
7771
|
initialize: initializeFlow,
|
|
@@ -7720,7 +7850,8 @@ import {
|
|
|
7720
7850
|
EmbeddedFlowStatus,
|
|
7721
7851
|
EmbeddedFlowComponentType as EmbeddedFlowComponentType5,
|
|
7722
7852
|
EmbeddedFlowResponseType,
|
|
7723
|
-
withVendorCSSClassPrefix as withVendorCSSClassPrefix21
|
|
7853
|
+
withVendorCSSClassPrefix as withVendorCSSClassPrefix21,
|
|
7854
|
+
Platform as Platform5
|
|
7724
7855
|
} from "@asgardeo/browser";
|
|
7725
7856
|
import { cx as cx21 } from "@emotion/css";
|
|
7726
7857
|
import { useEffect as useEffect14, useState as useState17, useCallback as useCallback11, useRef as useRef5 } from "react";
|
|
@@ -8439,6 +8570,7 @@ var BaseSignUpContent = ({
|
|
|
8439
8570
|
const { theme, colorScheme } = useTheme_default();
|
|
8440
8571
|
const { t } = useTranslation_default();
|
|
8441
8572
|
const { subtitle: flowSubtitle, title: flowTitle, messages: flowMessages, addMessage, clearMessages } = useFlow_default();
|
|
8573
|
+
const { platform } = useAsgardeo_default();
|
|
8442
8574
|
const styles = BaseSignUp_styles_default(theme, colorScheme);
|
|
8443
8575
|
const handleError = useCallback11(
|
|
8444
8576
|
(error) => {
|
|
@@ -8564,11 +8696,12 @@ var BaseSignUpContent = ({
|
|
|
8564
8696
|
}
|
|
8565
8697
|
});
|
|
8566
8698
|
}
|
|
8699
|
+
const actionId = platform === Platform5.AsgardeoV2 ? component.config?.actionId : component.id;
|
|
8567
8700
|
const payload = {
|
|
8568
8701
|
...currentFlow.flowId && { flowId: currentFlow.flowId },
|
|
8569
8702
|
flowType: currentFlow.flowType || "REGISTRATION",
|
|
8570
8703
|
inputs: filteredInputs,
|
|
8571
|
-
actionId
|
|
8704
|
+
...actionId && { actionId }
|
|
8572
8705
|
};
|
|
8573
8706
|
const rawResponse = await onSubmit(payload);
|
|
8574
8707
|
const response = normalizeFlowResponse2(rawResponse);
|
|
@@ -8851,7 +8984,7 @@ var BaseSignUp_default = BaseSignUp;
|
|
|
8851
8984
|
import {
|
|
8852
8985
|
EmbeddedFlowResponseType as EmbeddedFlowResponseType2,
|
|
8853
8986
|
EmbeddedFlowType as EmbeddedFlowType2,
|
|
8854
|
-
Platform as
|
|
8987
|
+
Platform as Platform6
|
|
8855
8988
|
} from "@asgardeo/browser";
|
|
8856
8989
|
import { jsx as jsx68 } from "react/jsx-runtime";
|
|
8857
8990
|
var SignUp = ({
|
|
@@ -8871,7 +9004,7 @@ var SignUp = ({
|
|
|
8871
9004
|
const effectiveApplicationId = applicationId || applicationIdFromUrl;
|
|
8872
9005
|
const initialPayload = payload || {
|
|
8873
9006
|
flowType: EmbeddedFlowType2.Registration,
|
|
8874
|
-
...platform ===
|
|
9007
|
+
...platform === Platform6.AsgardeoV2 && effectiveApplicationId && { applicationId: effectiveApplicationId }
|
|
8875
9008
|
};
|
|
8876
9009
|
return await signUp(initialPayload);
|
|
8877
9010
|
};
|
|
@@ -8899,8 +9032,8 @@ var SignUp = ({
|
|
|
8899
9032
|
isInitialized,
|
|
8900
9033
|
children,
|
|
8901
9034
|
showLogo: true,
|
|
8902
|
-
showTitle: platform ===
|
|
8903
|
-
showSubtitle: platform ===
|
|
9035
|
+
showTitle: platform === Platform6.AsgardeoV2,
|
|
9036
|
+
showSubtitle: platform === Platform6.AsgardeoV2,
|
|
8904
9037
|
...rest
|
|
8905
9038
|
}
|
|
8906
9039
|
);
|