From c4be0a637ea026a9e0484744ffb6489e1bf67db4 Mon Sep 17 00:00:00 2001 From: savindi7 Date: Wed, 13 Mar 2024 09:50:58 +0530 Subject: [PATCH] Support additional params in trySignInSilently URL --- lib/src/client.ts | 6 ++++-- lib/src/clients/main-thread-client.ts | 14 ++++++++++---- lib/src/clients/web-worker-client.ts | 15 +++++++++++---- lib/src/helpers/authentication-helper.ts | 7 ++++--- lib/src/models/client.ts | 4 ++-- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/lib/src/client.ts b/lib/src/client.ts index 9d76e95f..d68e3dc9 100755 --- a/lib/src/client.ts +++ b/lib/src/client.ts @@ -402,7 +402,9 @@ export class AsgardeoSPAClient { * auth.trySignInSilently() *``` */ - public async trySignInSilently(): Promise { + public async trySignInSilently( + additionalParams?: Record + ): Promise { await this._isInitialized(); // checks if the `signIn` method has been called. @@ -410,7 +412,7 @@ export class AsgardeoSPAClient { return; } - return this._client?.trySignInSilently().then((response: BasicUserInfo | boolean) => { + return this._client?.trySignInSilently(additionalParams).then((response: BasicUserInfo | boolean) => { if (this._onSignInCallback && response) { const basicUserInfo = response as BasicUserInfo; if ( diff --git a/lib/src/clients/main-thread-client.ts b/lib/src/clients/main-thread-client.ts index cc9ba63f..ca161bf2 100755 --- a/lib/src/clients/main-thread-client.ts +++ b/lib/src/clients/main-thread-client.ts @@ -306,11 +306,14 @@ export const MainThreadClient = async ( ); }; - const constructSilentSignInUrl = async (): Promise => { + const constructSilentSignInUrl = async ( + additionalParams: Record = {} + ): Promise => { const config = await _dataLayer.getConfigData(); const urlString: string = await _authenticationClient.getAuthorizationURL({ prompt: "none", - state: SILENT_SIGN_IN_STATE + state: SILENT_SIGN_IN_STATE, + ...additionalParams }); // Replace form_post with query @@ -337,12 +340,15 @@ export const MainThreadClient = async ( * @return {Promise => { + const trySignInSilently = async ( + additionalParams: Record = {} + ): Promise => { return await _authenticationHelper.trySignInSilently( constructSilentSignInUrl, requestAccessToken, - _sessionManagementHelper + _sessionManagementHelper, + additionalParams ); }; diff --git a/lib/src/clients/web-worker-client.ts b/lib/src/clients/web-worker-client.ts index e3a104fc..76b669a3 100755 --- a/lib/src/clients/web-worker-client.ts +++ b/lib/src/clients/web-worker-client.ts @@ -391,12 +391,15 @@ export const WebWorkerClient = async ( ); }; - const constructSilentSignInUrl = async (): Promise => { + const constructSilentSignInUrl = async ( + additionalParams: Record = {} + ): Promise => { const config: AuthClientConfig = await getConfigData(); const message: Message = { data: { prompt: "none", - state: SILENT_SIGN_IN_STATE + state: SILENT_SIGN_IN_STATE, + ...additionalParams }, type: GET_AUTH_URL }; @@ -426,11 +429,15 @@ export const WebWorkerClient = async ( * @return {Promise => { + const trySignInSilently = async ( + additionalParams: Record = {} + ): Promise => { + return await _authenticationHelper.trySignInSilently( constructSilentSignInUrl, requestAccessToken, - _sessionManagementHelper + _sessionManagementHelper, + additionalParams ); }; diff --git a/lib/src/helpers/authentication-helper.ts b/lib/src/helpers/authentication-helper.ts index 4e64b08b..467ad796 100644 --- a/lib/src/helpers/authentication-helper.ts +++ b/lib/src/helpers/authentication-helper.ts @@ -521,9 +521,10 @@ export class AuthenticationHelper< } public async trySignInSilently( - constructSilentSignInUrl: () => Promise, + constructSilentSignInUrl: (additionalParams?: Record) => Promise, requestAccessToken: (authzCode: string, sessionState: string, state: string) => Promise, - sessionManagementHelper: SessionManagementHelperInterface + sessionManagementHelper: SessionManagementHelperInterface, + additionalParams?: Record ): Promise { // This block is executed by the iFrame when the server redirects with the authorization code. @@ -549,7 +550,7 @@ export class AuthenticationHelper< ) as HTMLIFrameElement; try { - const url = await constructSilentSignInUrl(); + const url = await constructSilentSignInUrl(additionalParams); promptNoneIFrame.src = url; } catch (error) { diff --git a/lib/src/models/client.ts b/lib/src/models/client.ts index d54256a1..ba04bd11 100755 --- a/lib/src/models/client.ts +++ b/lib/src/models/client.ts @@ -65,7 +65,7 @@ export interface MainThreadClientInterface { getDataLayer(): Promise>; isAuthenticated(): Promise; updateConfig(config: Partial>): Promise; - trySignInSilently(): Promise; + trySignInSilently(additionalParams?: Record): Promise; } export interface WebWorkerClientInterface { @@ -96,5 +96,5 @@ export interface WebWorkerClientInterface { setHttpRequestFinishCallback(callback: () => void): void; refreshAccessToken(): Promise; updateConfig(config: Partial>): Promise; - trySignInSilently(): Promise; + trySignInSilently(additionalParams?: Record): Promise; }