capacitor-community / generic-oauth2

Generic Capacitor OAuth 2 client plugin. Stop the war in Ukraine!
MIT License
231 stars 113 forks source link

fixed android logout #233

Closed svzi closed 1 year ago

svzi commented 1 year ago

As mentioned in https://github.com/moberwasserlechner/capacitor-oauth2/issues/97 there are currently some issues with the logout functionality. We discovered them only on Android, so this fix is only implementing a solution for Android. Our project uses SalesForce OAuth2 provider.

We found that our users had problems with logout whenever they did not use their system's default browser. For example, if they had configured the Brave browser or Firefox as their default browser. In these cases we were not able to delete the session cookies. This is because this plugin always uses the system browser (usually Chrome), no matter what the user has set as default. But when we open a new browser window using Capacitor, the default browser configured by the user is used. And just not the system browser.

That's why we implemented the logout functionality for Android and our users can now logout correctly on Android. No matter which browser they use and no matter which browser is default on their system.

I implemented the customization in such a way that no changes are necessary for existing applications. The code is fully backward compatible.

If you want to use the new logout functionality, you now have to pass the current accessToken as a second, optional, parameter to the logout(...) function (required by the Android plugin). If you do not pass the parameter, the plugin will behave as before.

I have adapted the documentation as good as possible. If it is incomplete or you want it to be different, please let me know.

moberwasserlechner commented 1 year ago

Thanks for this PR

svzi commented 1 year ago

You're welcome and I need to thank you for providing such an awesome plugin. 🏆

Ssnipo commented 1 year ago

I might be wrong but id_token parameter currently has no effect. I have printed the result of call.getData() and it's not there.

For tests purpose I forced id_token with this snippet:

// @ts-ignore
oAuth2AuthenticateOptions.id_token = _accessToken;

That will result into NullPointerException because the logoutUrl is not set in this method: OAuth2Options buildAuthenticateOptions(JSObject callData)

Also setLogoutUrl(String logoutUrl) is not defined in OAuth2Options.java

Making these changes will end in this error that I could not solve: java.lang.NullPointerException: Attempt to invoke virtual method 'android.net.Uri$Builder android.net.Uri.buildUpon()' on a null object reference