From 023b558f4353fa0924153bee4ba77a6b29e814ef Mon Sep 17 00:00:00 2001 From: Stian Thorgersen Date: Tue, 23 Feb 2016 13:31:31 +0100 Subject: [PATCH] KEYCLOAK-2527 Cordova not working --- .../oidc/js/src/main/resources/keycloak.js | 31 +++++++++---------- examples/cordova/www/index.html | 10 ++++-- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/adapters/oidc/js/src/main/resources/keycloak.js b/adapters/oidc/js/src/main/resources/keycloak.js index 4bfec592d1..30453e3871 100755 --- a/adapters/oidc/js/src/main/resources/keycloak.js +++ b/adapters/oidc/js/src/main/resources/keycloak.js @@ -878,31 +878,28 @@ var loginUrl = kc.createLoginUrl(options); var ref = window.open(loginUrl, '_blank', o); - var callback; - var error; + var completed = false; ref.addEventListener('loadstart', function(event) { if (event.url.indexOf('http://localhost') == 0) { - callback = parseCallback(event.url); + var callback = parseCallback(event.url); + processCallback(callback, promise); ref.close(); + completed = true; } }); ref.addEventListener('loaderror', function(event) { - if (event.url.indexOf('http://localhost') == 0) { - callback = parseCallback(event.url); - ref.close(); - } else { - error = true; - ref.close(); - } - }); - - ref.addEventListener('exit', function(event) { - if (error || !callback) { - promise.setError(); - } else { - processCallback(callback, promise); + if (!completed) { + if (event.url.indexOf('http://localhost') == 0) { + var callback = parseCallback(event.url); + processCallback(callback, promise); + ref.close(); + completed = true; + } else { + promise.setError(); + ref.close(); + } } }); diff --git a/examples/cordova/www/index.html b/examples/cordova/www/index.html index cd33b24dd3..296986d112 100644 --- a/examples/cordova/www/index.html +++ b/examples/cordova/www/index.html @@ -48,8 +48,14 @@ } } + function error() { + document.getElementById('authenticated').style.display = 'none'; + document.getElementById('not-authenticated').style.display = 'block'; + document.getElementById('error').innerText = 'Failed to initialize Keycloak adapter'; + } + document.addEventListener("deviceready", function() { - keycloak.init({ onLoad: 'check-sso' }).success(updateState); + keycloak.init({ onLoad: "check-sso" }).success(updateState).error(error); }, false);