Skip to content

Commit 21afc74

Browse files
Merge pull request #136 from adrienne-deriv/front-channel-logout
Added front-channel logout functionality
2 parents 9aff97a + b379b73 commit 21afc74

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/oidc/oidc.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,18 @@ export const createUserManager = async (options: CreateUserManagerOptions) => {
279279
* Logs out the user from the auth server and calls the callback function when the logout is complete.
280280
* @param WSLogoutAndRedirect - The callback function to call after the logout is complete
281281
*/
282-
export const OAuth2Logout = (options: OAuth2LogoutOptions) => {
282+
export const OAuth2Logout = async (options: OAuth2LogoutOptions) => {
283283
const oidcEndpoints = localStorage.getItem('config.oidc_endpoints') || '{}';
284284

285-
const logoutUrl = getOAuthLogoutUrl() || JSON.parse(oidcEndpoints).end_session_endpoint;
285+
let logoutUrl = getOAuthLogoutUrl() || JSON.parse(oidcEndpoints).end_session_endpoint;
286+
const userManager = await createUserManager({
287+
redirectCallbackUri: options.redirectCallbackUri,
288+
postLogoutRedirectUri: options.postLogoutRedirectUri,
289+
});
290+
const userState = await userManager.getUser();
291+
if (userState?.id_token) {
292+
logoutUrl += `?id_token_hint=${userState.id_token}&post_logout_redirect_uri${options.postLogoutRedirectUri}`;
293+
}
286294

287295
const cleanup = () => {
288296
const iframe = document.getElementById('logout-iframe') as HTMLIFrameElement;

0 commit comments

Comments
 (0)