Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/slow-colts-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@asgardeo/react': patch
'@asgardeo/javascript': patch
---

Rename sessionDataKey to authId for V2
8 changes: 4 additions & 4 deletions packages/javascript/src/api/v2/executeEmbeddedSignInFlowV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const executeEmbeddedSignInFlowV2 = async ({
url,
baseUrl,
payload,
sessionDataKey,
authId,
...requestConfig
}: EmbeddedFlowExecuteRequestConfigV2): Promise<EmbeddedSignInFlowResponseV2> => {
if (!payload) {
Expand Down Expand Up @@ -68,11 +68,11 @@ const executeEmbeddedSignInFlowV2 = async ({
const flowResponse: EmbeddedSignInFlowResponseV2 = await response.json();

// IMPORTANT: Only applicable for Asgardeo V2 platform.
// Check if the flow is complete and has an assertion and sessionDataKey is provided, then call OAuth2 authorize.
// Check if the flow is complete and has an assertion and authId is provided, then call OAuth2 authorize.
if (
flowResponse.flowStatus === EmbeddedSignInFlowStatusV2.Complete &&
(flowResponse as any).assertion &&
sessionDataKey
authId
) {
try {
const oauth2Response: Response = await fetch(`${baseUrl}/oauth2/authorize`, {
Expand All @@ -84,7 +84,7 @@ const executeEmbeddedSignInFlowV2 = async ({
},
body: JSON.stringify({
assertion: (flowResponse as any).assertion,
sessionDataKey,
authId,
}),
credentials: 'include',
});
Expand Down
8 changes: 4 additions & 4 deletions packages/javascript/src/api/v2/executeEmbeddedSignUpFlowV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const executeEmbeddedSignUpFlowV2 = async ({
url,
baseUrl,
payload,
sessionDataKey,
authId,
...requestConfig
}: EmbeddedFlowExecuteRequestConfigV2): Promise<EmbeddedSignUpFlowResponseV2> => {
if (!payload) {
Expand Down Expand Up @@ -68,11 +68,11 @@ const executeEmbeddedSignUpFlowV2 = async ({
const flowResponse: EmbeddedSignUpFlowResponseV2 = await response.json();

// IMPORTANT: Only applicable for Asgardeo V2 platform.
// Check if the flow is complete and has an assertion and sessionDataKey is provided, then call OAuth2 authorize.
// Check if the flow is complete and has an assertion and authId is provided, then call OAuth2 authorize.
if (
flowResponse.flowStatus === EmbeddedSignUpFlowStatusV2.Complete &&
(flowResponse as any).assertion &&
sessionDataKey
authId
) {
try {
const oauth2Response: Response = await fetch(`${baseUrl}/oauth2/authorize`, {
Expand All @@ -84,7 +84,7 @@ const executeEmbeddedSignUpFlowV2 = async ({
},
body: JSON.stringify({
assertion: (flowResponse as any).assertion,
sessionDataKey,
authId,
}),
credentials: 'include',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,5 @@ export interface EmbeddedSignInFlowRequestV2 extends Partial<EmbeddedSignInFlowI
* @experimental
*/
export interface EmbeddedFlowExecuteRequestConfigV2<T = any> extends EmbeddedFlowExecuteRequestConfig<T> {
sessionDataKey?: string;
authId?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export interface EmbeddedSignUpFlowRequestV2 extends Partial<EmbeddedSignUpFlowI
* @experimental
*/
export interface EmbeddedFlowExecuteRequestConfigV2<T = any> extends EmbeddedFlowExecuteRequestConfig<T> {
sessionDataKey?: string;
authId?: string;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/react/src/AsgardeoReactClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,17 +357,17 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
!isEmpty(arg1) &&
('flowId' in arg1 || 'applicationId' in arg1)
) {
const sessionDataKeyFromUrl: string = new URL(window.location.href).searchParams.get('sessionDataKey');
const sessionDataKeyFromStorage: string = sessionStorage.getItem('asgardeo_session_data_key');
const sessionDataKey: string = sessionDataKeyFromUrl || sessionDataKeyFromStorage;
const authIdFromUrl: string = new URL(window.location.href).searchParams.get('authId');
const authIdFromStorage: string = sessionStorage.getItem('asgardeo_auth_id');
const authId: string = authIdFromUrl || authIdFromStorage;
const baseUrlFromStorage: string = sessionStorage.getItem('asgardeo_base_url');
const baseUrl: string = config?.baseUrl || baseUrlFromStorage;

return executeEmbeddedSignInFlowV2({
payload: arg1 as EmbeddedSignInFlowHandleRequestPayload,
url: arg2?.url,
baseUrl,
sessionDataKey,
authId,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
const clearFlowState = (): void => {
setFlowId(null);
setIsFlowInitialized(false);
sessionStorage.removeItem('asgardeo_session_data_key');
sessionStorage.removeItem('asgardeo_auth_id');
// Reset refs to allow new flows to start properly
oauthCodeProcessedRef.current = false;
};
Expand All @@ -215,16 +215,16 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
nonce: urlParams.get('nonce'),
flowId: urlParams.get('flowId'),
applicationId: urlParams.get('applicationId'),
sessionDataKey: urlParams.get('sessionDataKey'),
authId: urlParams.get('authId'),
};
};

/**
* Handle sessionDataKey from URL and store it in sessionStorage.
* Handle authId from URL and store it in sessionStorage.
*/
const handleSessionDataKey = (sessionDataKey: string | null): void => {
if (sessionDataKey) {
sessionStorage.setItem('asgardeo_session_data_key', sessionDataKey);
const handleAuthId = (authId: string | null): void => {
if (authId) {
sessionStorage.setItem('asgardeo_auth_id', authId);
}
};

Expand Down Expand Up @@ -257,14 +257,14 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
};

/**
* Clean up flow-related URL parameters (flowId, sessionDataKey) from the browser URL.
* Clean up flow-related URL parameters (flowId, authId) from the browser URL.
* Used after flowId is set in state to prevent using invalidated flowId from URL.
*/
const cleanupFlowUrlParams = (): void => {
if (!window?.location?.href) return;
const url = new URL(window.location.href);
url.searchParams.delete('flowId');
url.searchParams.delete('sessionDataKey');
url.searchParams.delete('authId');
url.searchParams.delete('applicationId');
window?.history?.replaceState({}, '', url.toString());
};
Expand Down Expand Up @@ -309,7 +309,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
}

const urlParams = getUrlParams();
handleSessionDataKey(urlParams.sessionDataKey);
handleAuthId(urlParams.authId);

window.location.href = redirectURL;
return true;
Expand All @@ -331,7 +331,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
return;
}

handleSessionDataKey(urlParams.sessionDataKey);
handleAuthId(urlParams.authId);

// Skip OAuth code processing - let the dedicated OAuth useEffect handle it
if (urlParams.code || urlParams.state) {
Expand Down Expand Up @@ -367,7 +367,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
// Reset OAuth code processed ref when starting a new flow
oauthCodeProcessedRef.current = false;

handleSessionDataKey(urlParams.sessionDataKey);
handleAuthId(urlParams.authId);

const effectiveApplicationId = applicationId || urlParams.applicationId;

Expand Down Expand Up @@ -488,7 +488,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
setFlowId(null);
setIsFlowInitialized(false);
sessionStorage.removeItem('asgardeo_flow_id');
sessionStorage.removeItem('asgardeo_session_data_key');
sessionStorage.removeItem('asgardeo_auth_id');

// Clean up OAuth URL params before redirect
cleanupOAuthUrlParams(true);
Expand Down
Loading