From b379b7350f575aa8a84a12f374f86dcccfd1e563 Mon Sep 17 00:00:00 2001 From: Adrienne Rio Date: Mon, 13 Jan 2025 17:00:39 +0800 Subject: [PATCH] chore: added front-channel logout --- src/oidc/oidc.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/oidc/oidc.ts b/src/oidc/oidc.ts index 7504ec8..4a09299 100644 --- a/src/oidc/oidc.ts +++ b/src/oidc/oidc.ts @@ -279,10 +279,18 @@ export const createUserManager = async (options: CreateUserManagerOptions) => { * Logs out the user from the auth server and calls the callback function when the logout is complete. * @param WSLogoutAndRedirect - The callback function to call after the logout is complete */ -export const OAuth2Logout = (options: OAuth2LogoutOptions) => { +export const OAuth2Logout = async (options: OAuth2LogoutOptions) => { const oidcEndpoints = localStorage.getItem('config.oidc_endpoints') || '{}'; - const logoutUrl = getOAuthLogoutUrl() || JSON.parse(oidcEndpoints).end_session_endpoint; + let logoutUrl = getOAuthLogoutUrl() || JSON.parse(oidcEndpoints).end_session_endpoint; + const userManager = await createUserManager({ + redirectCallbackUri: options.redirectCallbackUri, + postLogoutRedirectUri: options.postLogoutRedirectUri, + }); + const userState = await userManager.getUser(); + if (userState?.id_token) { + logoutUrl += `?id_token_hint=${userState.id_token}&post_logout_redirect_uri${options.postLogoutRedirectUri}`; + } const cleanup = () => { const iframe = document.getElementById('logout-iframe') as HTMLIFrameElement;