diff --git a/adapters/oidc/js/src/main/resources/keycloak.js b/adapters/oidc/js/src/main/resources/keycloak.js index 23532116bf..fcd6b3c366 100755 --- a/adapters/oidc/js/src/main/resources/keycloak.js +++ b/adapters/oidc/js/src/main/resources/keycloak.js @@ -1223,12 +1223,18 @@ var loginUrl = kc.createLoginUrl(options); var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions); var completed = false; + + var closed = false; + var closeBrowser = function() { + closed = true; + ref.close(); + }; ref.addEventListener('loadstart', function(event) { if (event.url.indexOf('http://localhost') == 0) { var callback = parseCallback(event.url); processCallback(callback, promise); - ref.close(); + closeBrowser(); completed = true; } }); @@ -1238,15 +1244,23 @@ if (event.url.indexOf('http://localhost') == 0) { var callback = parseCallback(event.url); processCallback(callback, promise); - ref.close(); + closeBrowser(); completed = true; } else { promise.setError(); - ref.close(); + closeBrowser(); } } }); + ref.addEventListener('exit', function(event) { + if (!closed) { + promise.setError({ + reason: "closed_by_user" + }); + } + }); + return promise.promise; },