Skip to content

Commit dbdcdef

Browse files
authored
Merge pull request #278 from thiva-k/rename-auth-id
Update Asgardeo V2 to use `authId`
2 parents e9f9254 + dc849e8 commit dbdcdef

File tree

7 files changed

+32
-26
lines changed

7 files changed

+32
-26
lines changed

.changeset/slow-colts-beam.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@asgardeo/react': patch
3+
'@asgardeo/javascript': patch
4+
---
5+
6+
Rename sessionDataKey to authId for V2

packages/javascript/src/api/v2/executeEmbeddedSignInFlowV2.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const executeEmbeddedSignInFlowV2 = async ({
2727
url,
2828
baseUrl,
2929
payload,
30-
sessionDataKey,
30+
authId,
3131
...requestConfig
3232
}: EmbeddedFlowExecuteRequestConfigV2): Promise<EmbeddedSignInFlowResponseV2> => {
3333
if (!payload) {
@@ -68,11 +68,11 @@ const executeEmbeddedSignInFlowV2 = async ({
6868
const flowResponse: EmbeddedSignInFlowResponseV2 = await response.json();
6969

7070
// IMPORTANT: Only applicable for Asgardeo V2 platform.
71-
// Check if the flow is complete and has an assertion and sessionDataKey is provided, then call OAuth2 authorize.
71+
// Check if the flow is complete and has an assertion and authId is provided, then call OAuth2 authorize.
7272
if (
7373
flowResponse.flowStatus === EmbeddedSignInFlowStatusV2.Complete &&
7474
(flowResponse as any).assertion &&
75-
sessionDataKey
75+
authId
7676
) {
7777
try {
7878
const oauth2Response: Response = await fetch(`${baseUrl}/oauth2/authorize`, {
@@ -84,7 +84,7 @@ const executeEmbeddedSignInFlowV2 = async ({
8484
},
8585
body: JSON.stringify({
8686
assertion: (flowResponse as any).assertion,
87-
sessionDataKey,
87+
authId,
8888
}),
8989
credentials: 'include',
9090
});

packages/javascript/src/api/v2/executeEmbeddedSignUpFlowV2.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const executeEmbeddedSignUpFlowV2 = async ({
2727
url,
2828
baseUrl,
2929
payload,
30-
sessionDataKey,
30+
authId,
3131
...requestConfig
3232
}: EmbeddedFlowExecuteRequestConfigV2): Promise<EmbeddedSignUpFlowResponseV2> => {
3333
if (!payload) {
@@ -68,11 +68,11 @@ const executeEmbeddedSignUpFlowV2 = async ({
6868
const flowResponse: EmbeddedSignUpFlowResponseV2 = await response.json();
6969

7070
// IMPORTANT: Only applicable for Asgardeo V2 platform.
71-
// Check if the flow is complete and has an assertion and sessionDataKey is provided, then call OAuth2 authorize.
71+
// Check if the flow is complete and has an assertion and authId is provided, then call OAuth2 authorize.
7272
if (
7373
flowResponse.flowStatus === EmbeddedSignUpFlowStatusV2.Complete &&
7474
(flowResponse as any).assertion &&
75-
sessionDataKey
75+
authId
7676
) {
7777
try {
7878
const oauth2Response: Response = await fetch(`${baseUrl}/oauth2/authorize`, {
@@ -84,7 +84,7 @@ const executeEmbeddedSignUpFlowV2 = async ({
8484
},
8585
body: JSON.stringify({
8686
assertion: (flowResponse as any).assertion,
87-
sessionDataKey,
87+
authId,
8888
}),
8989
credentials: 'include',
9090
});

packages/javascript/src/models/v2/embedded-signin-flow-v2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ export interface EmbeddedSignInFlowRequestV2 extends Partial<EmbeddedSignInFlowI
9494
* @experimental
9595
*/
9696
export interface EmbeddedFlowExecuteRequestConfigV2<T = any> extends EmbeddedFlowExecuteRequestConfig<T> {
97-
sessionDataKey?: string;
97+
authId?: string;
9898
}

packages/javascript/src/models/v2/embedded-signup-flow-v2.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export interface EmbeddedSignUpFlowRequestV2 extends Partial<EmbeddedSignUpFlowI
168168
* @experimental
169169
*/
170170
export interface EmbeddedFlowExecuteRequestConfigV2<T = any> extends EmbeddedFlowExecuteRequestConfig<T> {
171-
sessionDataKey?: string;
171+
authId?: string;
172172
}
173173

174174
/**

packages/react/src/AsgardeoReactClient.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,17 @@ class AsgardeoReactClient<T extends AsgardeoReactConfig = AsgardeoReactConfig> e
357357
!isEmpty(arg1) &&
358358
('flowId' in arg1 || 'applicationId' in arg1)
359359
) {
360-
const sessionDataKeyFromUrl: string = new URL(window.location.href).searchParams.get('sessionDataKey');
361-
const sessionDataKeyFromStorage: string = sessionStorage.getItem('asgardeo_session_data_key');
362-
const sessionDataKey: string = sessionDataKeyFromUrl || sessionDataKeyFromStorage;
360+
const authIdFromUrl: string = new URL(window.location.href).searchParams.get('authId');
361+
const authIdFromStorage: string = sessionStorage.getItem('asgardeo_auth_id');
362+
const authId: string = authIdFromUrl || authIdFromStorage;
363363
const baseUrlFromStorage: string = sessionStorage.getItem('asgardeo_base_url');
364364
const baseUrl: string = config?.baseUrl || baseUrlFromStorage;
365365

366366
return executeEmbeddedSignInFlowV2({
367367
payload: arg1 as EmbeddedSignInFlowHandleRequestPayload,
368368
url: arg2?.url,
369369
baseUrl,
370-
sessionDataKey,
370+
authId,
371371
});
372372
}
373373

packages/react/src/components/presentation/SignIn/component-driven/SignIn.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
197197
const clearFlowState = (): void => {
198198
setFlowId(null);
199199
setIsFlowInitialized(false);
200-
sessionStorage.removeItem('asgardeo_session_data_key');
200+
sessionStorage.removeItem('asgardeo_auth_id');
201201
// Reset refs to allow new flows to start properly
202202
oauthCodeProcessedRef.current = false;
203203
};
@@ -215,16 +215,16 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
215215
nonce: urlParams.get('nonce'),
216216
flowId: urlParams.get('flowId'),
217217
applicationId: urlParams.get('applicationId'),
218-
sessionDataKey: urlParams.get('sessionDataKey'),
218+
authId: urlParams.get('authId'),
219219
};
220220
};
221221

222222
/**
223-
* Handle sessionDataKey from URL and store it in sessionStorage.
223+
* Handle authId from URL and store it in sessionStorage.
224224
*/
225-
const handleSessionDataKey = (sessionDataKey: string | null): void => {
226-
if (sessionDataKey) {
227-
sessionStorage.setItem('asgardeo_session_data_key', sessionDataKey);
225+
const handleAuthId = (authId: string | null): void => {
226+
if (authId) {
227+
sessionStorage.setItem('asgardeo_auth_id', authId);
228228
}
229229
};
230230

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

259259
/**
260-
* Clean up flow-related URL parameters (flowId, sessionDataKey) from the browser URL.
260+
* Clean up flow-related URL parameters (flowId, authId) from the browser URL.
261261
* Used after flowId is set in state to prevent using invalidated flowId from URL.
262262
*/
263263
const cleanupFlowUrlParams = (): void => {
264264
if (!window?.location?.href) return;
265265
const url = new URL(window.location.href);
266266
url.searchParams.delete('flowId');
267-
url.searchParams.delete('sessionDataKey');
267+
url.searchParams.delete('authId');
268268
url.searchParams.delete('applicationId');
269269
window?.history?.replaceState({}, '', url.toString());
270270
};
@@ -309,7 +309,7 @@ const SignIn: FC<SignInProps> = ({className, size = 'medium', onSuccess, onError
309309
}
310310

311311
const urlParams = getUrlParams();
312-
handleSessionDataKey(urlParams.sessionDataKey);
312+
handleAuthId(urlParams.authId);
313313

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

334-
handleSessionDataKey(urlParams.sessionDataKey);
334+
handleAuthId(urlParams.authId);
335335

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

370-
handleSessionDataKey(urlParams.sessionDataKey);
370+
handleAuthId(urlParams.authId);
371371

372372
const effectiveApplicationId = applicationId || urlParams.applicationId;
373373

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

493493
// Clean up OAuth URL params before redirect
494494
cleanupOAuthUrlParams(true);

0 commit comments

Comments
 (0)