ionic-appauth
ionic-appauth copied to clipboard
Unclear how to use browser (close) event
In a previous issue #19 you mentioned that the Browser
class has a method called browserCloseListener
.
The problem is that i only see the addCloseBrowserEvent
method and I'm not sure how to properly use that method to get SignInFailed or similar errors.
Maybe you can help me and clearify how i could use that method appropriate.
Still not able to add a closeBrowser event or to intercept a login failed action.
I'm having the same problem. I don't know how to handle a login cancel button in the browser...
Actually I just tested that hooking up to:
browser.browserCloseListener(() => {
App.exitApp();
});
does the trick. Actually my full auth.factory is (in case it helps you:
import { Platform } from '@ionic/angular';
import { StorageBackend, Requestor } from '@openid/appauth';
import { AuthService, Browser, ConsoleLogObserver } from 'ionic-appauth';
import { Plugins } from '@capacitor/core';
import { environment } from 'src/environments/environment';
import { NgZone } from '@angular/core';
const { App } = Plugins;
export let authFactory = (platform: Platform, ngZone: NgZone,
requestor: Requestor, browser: Browser, storage: StorageBackend) => {
const authService = new AuthService(browser, storage, requestor);
authService.authConfig = environment.auth_config;
if (!platform.is('android')) {
authService.authConfig.server_host = environment.browserAuthorityUrl;
authService.authConfig.redirect_url = window.location.origin + '/auth-callback';
authService.authConfig.end_session_redirect_url = window.location.origin + '/end-session';
}
if (platform.is('capacitor')) {
App.addListener('appUrlOpen', (data: any) => {
if (data.url !== undefined) {
ngZone.run(() => {
if (data.url.indexOf(environment.auth_config.redirect_url) === 0) {
authService.authorizationCallback(data.url);
} else if (data.url.indexOf(environment.auth_config.end_session_redirect_url) === 0) {
authService.endSessionCallback();
}
});
}
});
browser.browserCloseListener(() => {
App.exitApp();
});
}
console.log('Using IdentityServer URL', authService.authConfig.server_host);
authService.addActionObserver(new ConsoleLogObserver());
return authService;
};