Skip to content

Commit

Permalink
Merge pull request #136 from adrienne-deriv/front-channel-logout
Browse files Browse the repository at this point in the history
Added front-channel logout functionality
  • Loading branch information
adrienne-deriv authored Jan 14, 2025
2 parents 9aff97a + b379b73 commit 21afc74
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/oidc/oidc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 21afc74

Please sign in to comment.