-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat: Logout Funtion & URL #97
Comments
Coded a workaround for azure b2c logout, while this feature is not completed: //(...)
import { Plugins } from '@capacitor/core';
const { Browser } = Plugins;
//(...)
const urlLogout = 'https://XXXXXX.b2clogin.com/tfp/XXXXXX.onmicrosoft.com/b2c_1_sign_in/oauth2/v2.0/logout?client_id=XXXXX-XXXXX-XXXXX-XXXXX&response_type=token&redirect_uri=com.company.app://oauth/redirect&scope=openid%20offline_access%20https://XXXXX.onmicrosoft.com/api/demo.read';
// just opens and closes the browser with the previous URL
const browser = await Browser.open({ url: urlLogout});
Browser.close();
// Then run the logout from plugin
Plugins.OAuth2Client.logout(environment.oauth2Options)
.then(() => sessionStorage.clear())
.catch(reason => { console.error('OAuth logout failed', reason); }); |
hi, any official solution for this? |
the workaround does not work because login and logout does not use the same browser instance... |
It does work for me, its not a definitive fix though |
how do you do the login? via the plugin (with it's native browser usage?) Are youz forced to type in your username and password after logging out and logging in again? |
The workaround works for azure b2c, not sure about other types of logins. I have made a repo that is working for logins, I have not impletemented there this workaround, but you can have a picture of how I do it: Give it a try and tell us how it goes. |
@tobium you tried in IOS Right? Seems to work on the IOS emulator but not on the device :( . Android works fine on my phone. ~Would be great if this plugin could have the logout, as its kind of a deal-breaker for using it |
PRs are welcome ;) |
After some digging I found this, not sure if it will help to develop this feature. If I knew how to implement it I would. |
@loonix Thanks for the example. Such hints are very helpful as I need less research when starting to work on this task |
@tobium I was able to logout with IOS but had to increase the timeout specifically for IOS.
|
Not able to get it working with any of these solutions, did anyone work out a different way to actually log the user out? |
https://github.com/loonix/capacitor-oauth2-azure-example Check my repo, and the readme file and see if it helps. |
+1 for this feature |
I tried same but logout is not working for me. Any solution for logout in android? |
@PragyaSingla not yet but I try to include this into the upcoming This is a breaking change so I will not back port it to |
I'm not able to implement this in |
With this setup I'm able to logout For iOS For Android Where |
i can confirm that the workaround from @loonix works. For IOS it always works, but for Android it only works if the system browser is Chrome. import { InAppBrowser } from '@awesome-cordova-plugins/in-app-browser/ngx';
import { Browser } from '@capacitor/browser';
import { OAuth2Client } from '@byteowls/capacitor-oauth2';
import { isPlatform } from '@ionic/angular';
constructor(private iab: InAppBrowser) {}
public signOut() {
const url = 'YOUR_LOGOUT_URL';
return of(isPlatform('android')).pipe(
switchMap((isAndroid) => (isAndroid ? this.handleAndroidSignOut(url) : this.handleIosSignOut(url))),
switchMap(() => from(OAuth2Client.logout(OAUTH_OPTIONS)))
);
}
private handleIosSignOut(url: string) {
return from(Browser.open({ url })).pipe(
switchMap(() => from(Browser.addListener('browserPageLoaded', () => {}))), // await page load to make sure logout was called
switchMap(() => Browser.close())
);
}
private handleAndroidSignOut(url: string) {
const ref = this.iab.create(url, '_system', 'hidden=yes');
return ref.on('loadstop').pipe(tap(() => ref.close())); // // await page load to make sure logout was called
} As a sideeffekt you'll see the Browser popup and close quickly. It would be nice, if this could happen in background for better UX. This should be fixed in the plugin itself. |
@DwieDima
The I'm trying to get this to work on reactJS PWA ionic + capacitor. |
@DenysAshikhin try this promise-based snipped: public async signOut(): Promise<void> {
const url = 'your-auth-url';
if(isPlatform('android')) {
await this.handleAndroidSignOut(url);
} else {
await this.handleIosSignOut(url);
}
await OAuth2Client.logout(OAUTH_OPTIONS);
}
private async handleIosSignOut(url: string): Promise<void> {
await Browser.open({ url });
await Browser.addListener('browserPageLoaded', () => {});
await Browser.close();
}
private async handleAndroidSignOut(url: string): Promise<void> {
const ref = this.iab.create(url, '_system');
ref.show();
await new Promise(resolve => setTimeout(() => resolve, 300));
ref.close();
} |
@DwieDima Did you only install |
I just call 'authorize' again with my logout url. This works for me. getAzureB2cOAuth2Options(logout: boolean = false): OAuth2AuthenticateOptions {
return {
...
authorizationBaseUrl: `https://....onmicrosoft.com/.../oauth2/v2.0/` + (!logout ? 'authorize' : 'logout'),
...
};
}
...
logout() {
GenericOAuth2.authenticate(this.getAzureB2cOAuth2Options(true))
.then(async response => {
console.log('OAuth response', response);
})
.catch(reason => {
console.error('OAuth rejected', reason);
});
} |
Describe the Feature
The current logout functionally only cleans any cached tokens but does not log
out of the provider. For that to work we would have to provide a logout URL, which is not supported.
Platform(s) Support Requested
Describe Preferred Solution
Be able to logout completely from the app, it should clear the app cache and log the user out.
Describe Alternatives
None
Related Code
n/a
Additional Context
Reference: #96
The text was updated successfully, but these errors were encountered: