Merge pull request #2262 from stianst/master

KEYCLOAK-2527
This commit is contained in:
Stian Thorgersen 2016-02-23 14:15:25 +01:00
commit eacd689f91
2 changed files with 22 additions and 19 deletions

View file

@ -878,31 +878,28 @@
var loginUrl = kc.createLoginUrl(options); var loginUrl = kc.createLoginUrl(options);
var ref = window.open(loginUrl, '_blank', o); var ref = window.open(loginUrl, '_blank', o);
var callback; var completed = false;
var error;
ref.addEventListener('loadstart', function(event) { ref.addEventListener('loadstart', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (event.url.indexOf('http://localhost') == 0) {
callback = parseCallback(event.url); var callback = parseCallback(event.url);
processCallback(callback, promise);
ref.close(); ref.close();
completed = true;
} }
}); });
ref.addEventListener('loaderror', function(event) { ref.addEventListener('loaderror', function(event) {
if (event.url.indexOf('http://localhost') == 0) { if (!completed) {
callback = parseCallback(event.url); if (event.url.indexOf('http://localhost') == 0) {
ref.close(); var callback = parseCallback(event.url);
} else { processCallback(callback, promise);
error = true; ref.close();
ref.close(); completed = true;
} } else {
}); promise.setError();
ref.close();
ref.addEventListener('exit', function(event) { }
if (error || !callback) {
promise.setError();
} else {
processCallback(callback, promise);
} }
}); });

View file

@ -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() { document.addEventListener("deviceready", function() {
keycloak.init({ onLoad: 'check-sso' }).success(updateState); keycloak.init({ onLoad: "check-sso" }).success(updateState).error(error);
}, false); }, false);
</script> </script>
<style> <style>
@ -104,7 +110,7 @@
<button onclick="keycloak.login()">Log in</button> <button onclick="keycloak.login()">Log in</button>
</div> </div>
<div> <div>
<p>Not authenticated</p> <p id="error">Not authenticated</p>
</div> </div>
</div> </div>
</body> </body>