Skip to content

Commit 2b1f8de

Browse files
Refactor instance ID handling in authorization flow and update related utility functions
1 parent 10ca5ed commit 2b1f8de

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

packages/javascript/src/__legacy__/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,11 +255,11 @@ export class AsgardeoAuthClient<T> {
255255
clientId: configData.clientId,
256256
codeChallenge,
257257
codeChallengeMethod: PKCEConstants.DEFAULT_CODE_CHALLENGE_METHOD,
258+
instanceId: this.getInstanceId().toString(),
258259
prompt: configData.prompt,
259260
redirectUri: configData.afterSignInUrl,
260261
responseMode: configData.responseMode,
261262
scopes: processOpenIDScopes(configData.scopes),
262-
instanceId: this.getInstanceId().toString(),
263263
},
264264
{key: pkceKey},
265265
authRequestConfig,

packages/javascript/src/utils/getAuthorizeRequestUrlParams.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ const getAuthorizeRequestUrlParams = (
5555
clientId: string;
5656
codeChallenge?: string;
5757
codeChallengeMethod?: string;
58+
instanceId?: string;
5859
prompt?: string;
5960
redirectUri: string;
6061
responseMode?: string;
6162
scopes?: string;
62-
instanceId?: string;
6363
} & ExtendedAuthorizeRequestUrlParams,
6464
pkceOptions: {key: string},
6565
customParams: Record<string, string | number | boolean>,
@@ -106,17 +106,14 @@ const getAuthorizeRequestUrlParams = (
106106
});
107107
}
108108

109-
if (options.instanceId) {
110-
const AUTH_INSTANCE_PREFIX = "instance_";
111-
customParams[OIDCRequestConstants.Params.STATE] = AUTH_INSTANCE_PREFIX + options.instanceId;
112-
}
109+
const AUTH_INSTANCE_PREFIX: string = 'instance_';
110+
const customStateValue: string = options.instanceId
111+
? AUTH_INSTANCE_PREFIX + options.instanceId
112+
: customParams ? customParams[OIDCRequestConstants.Params.STATE]?.toString() : '';
113113

114114
authorizeRequestParams.set(
115115
OIDCRequestConstants.Params.STATE,
116-
generateStateParamForRequestCorrelation(
117-
pkceKey,
118-
customParams ? customParams[OIDCRequestConstants.Params.STATE]?.toString() : '',
119-
),
116+
generateStateParamForRequestCorrelation(pkceKey, customStateValue),
120117
);
121118

122119
return authorizeRequestParams;

packages/react/src/contexts/Asgardeo/AsgardeoProvider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ const AsgardeoProvider: FC<PropsWithChildren<AsgardeoProviderProps>> = ({
266266
}
267267

268268
const currentUrl: URL = new URL(window.location.href);
269-
const hasAuthParamsResult: boolean = hasAuthParams(currentUrl, afterSignInUrl) && hasCalledForThisInstance(currentUrl, instanceId ?? 0);
269+
const hasAuthParamsResult: boolean =
270+
hasAuthParams(currentUrl, afterSignInUrl) && hasCalledForThisInstance(currentUrl, instanceId ?? 0);
270271

271272
const isV2Platform: boolean = config.platform === Platform.AsgardeoV2;
272273

packages/react/src/hooks/useBrowserUrl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ const useBrowserUrl = (): UseBrowserUrl => {
6262
// authParams?.authorizationCode || // FIXME: These are sent externally. Need to see what we can do about this.
6363
url.searchParams.get('error') !== null;
6464

65-
const hasCalledForThisInstance = (url: URL, instanceId: number): boolean =>
66-
(hasCalledForThisInstanceInUrl(instanceId, url.search));
65+
const hasCalledForThisInstance = (url: URL, instanceId: number): boolean =>
66+
hasCalledForThisInstanceInUrl(instanceId, url.search);
6767

6868
return {hasAuthParams, hasCalledForThisInstance};
6969
};

0 commit comments

Comments
 (0)