Azure B2C Sign Out In Ionic Capacitor Project

Viewed 401

I m using this Capacitor (https://github.com/moberwasserlechner/capacitor-oauth2) plugin in my Hybrid project. With Azure B2C, we have to trigger sign-out URL manually. How can I do that properly in a ionic-capacitor project.

This is one of my implementation (b2c page will open in webview so user won't notice)

import { Plugins } from '@capacitor/core';
const { Browser } = Plugins;

const b2cUrl = 'https://xxx.b2clogin.com/xxx.onmicrosoft.com/B2C_1A_Signup_Signin/oauth2/v2.0/logout'
const redirectUrl = 'myapp://auth'
const url = `${b2cUrl}?post_logout_redirect_uri=${redirectUrl}`;
await Browser.open({ url: url });
await Browser.open({ url: redirectUrl});

Please note I use 2 open methods because in android, browser.close doesnt work.

Another method (b2c page will open in new browser)

window.location.replace(url); 

Solution

For Android and PWA

window.location.replace(url);

For iOS

import { BrowserPlugin, Plugins } from '@capacitor/core';
const { Browser }: { Browser: BrowserPlugin } = Plugins;
Browser.close()
0 Answers
Related