From b811bc518c81250b80008bf07d5fa601631d69c7 Mon Sep 17 00:00:00 2001 From: Yasasr1 Date: Mon, 25 Sep 2023 14:14:25 +0530 Subject: [PATCH] add config to send client_id or id_token_hint --- lib/src/core/authentication-core.ts | 31 +++++++++++++++++------------ lib/src/models/client-config.ts | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/lib/src/core/authentication-core.ts b/lib/src/core/authentication-core.ts index c3e8390e..aee4f84d 100644 --- a/lib/src/core/authentication-core.ts +++ b/lib/src/core/authentication-core.ts @@ -535,17 +535,7 @@ export class AuthenticationCore { ); } - const idToken = (await this._dataLayer.getSessionData(userID))?.id_token; - - if (!idToken || idToken.trim().length === 0) { - throw new AsgardeoAuthException( - "JS-AUTH_CORE-GSOU-NF02", - "ID token not found.", - "No ID token could be found. Either the session information is lost or you have not signed in." - ); - } - - const callbackURL = configData?.signOutRedirectURL ?? configData?.signInRedirectURL; + const callbackURL: string = configData?.signOutRedirectURL ?? configData?.signInRedirectURL; if (!callbackURL || callbackURL.trim().length === 0) { throw new AsgardeoAuthException( @@ -556,9 +546,24 @@ export class AuthenticationCore { ); } - const logoutCallback = + let parameter: string = `client_id=${ configData.clientID }`; + + if (configData.sendIdTokenInLogoutRequest) { + const idToken: string = (await this._dataLayer.getSessionData(userID))?.id_token; + + if (!idToken || idToken.trim().length === 0) { + throw new AsgardeoAuthException( + "JS-AUTH_CORE-GSOU-NF02", + "ID token not found.", + "No ID token could be found. Either the session information is lost or you have not signed in." + ); + } + parameter = `id_token_hint=${ idToken }`; + } + + const logoutCallback: string = `${ logoutEndpoint }?` + - `id_token_hint=${ idToken }` + + parameter + `&post_logout_redirect_uri=${ callbackURL }&state=` + SIGN_OUT_SUCCESS_PARAM; diff --git a/lib/src/models/client-config.ts b/lib/src/models/client-config.ts index 5ce2cbdf..58b638a6 100644 --- a/lib/src/models/client-config.ts +++ b/lib/src/models/client-config.ts @@ -40,6 +40,7 @@ export interface DefaultAuthClientConfig { * */ sendCookiesInRequests?: boolean; + sendIdTokenInLogoutRequest?: boolean; } export interface WellKnownAuthClientConfig extends DefaultAuthClientConfig {