Skip to content
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

EventListener multiplies itself on login or logout when using platform 'capacitor' #17

Open
Physox512 opened this issue Jun 21, 2022 · 1 comment

Comments

@Physox512
Copy link

Physox512 commented Jun 21, 2022

We have discovered a bug in the plugin, where the EventListener multiplies itself on login or logout when using platform 'capacitor'.
This results in many 400 bad request errors when trying to receive a token from Keycloak:

grafik
Also on iOS we had to click on login button seveeral times, before the login really worked...

The solution simply was, to remove the EventListerners after running the Event code in keycloak.js file starting in line 1615:

if (type == 'capacitor') {
    loginIframe.enable = false;

    return {
        login: function(options) {
            var promise = createPromise();
            var loginUrl = kc.createLoginUrl(options);

            const addUrlListener = window.Capacitor.Plugins.App.addListener('appUrlOpen', (data) => {
                window.cordova.plugins.browsertab.close();
                var oauth = parseCallback(data.url);
                processCallback(oauth, promise);
                addUrlListener.remove(); // <--- REMOVE THE EVENT LISTENER HERE
            });

            window.cordova.plugins.browsertab.openUrl(loginUrl);
            return promise.promise;
        },

        logout: function(options) {
            var promise = createPromise();
            var logoutUrl = kc.createLogoutUrl(options);

            const addUrlListener = window.Capacitor.Plugins.App.addListener('appUrlOpen', (data) => {
                window.cordova.plugins.browsertab.close();
                kc.clearToken();
                promise.setSuccess();
                addUrlListener.remove(); // <--- REMOVE THE EVENT LISTENER HERE
            });

            window.cordova.plugins.browsertab.openUrl(logoutUrl);
            return promise.promise;
        },
 ...
@jy95
Copy link

jy95 commented Nov 12, 2022

@Physox512 For your info, keycloak-capacitor should not have this issue : feel free to give a try :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants