From 97fccd6d504ecbf12eb3ea085945350aa4a9b3b8 Mon Sep 17 00:00:00 2001 From: jferrer Date: Tue, 23 Jul 2019 11:28:40 +0100 Subject: [PATCH] KEYCLOAK-10910 login function now uses promise type specified in init --- .../oidc/js/src/main/resources/keycloak.js | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/adapters/oidc/js/src/main/resources/keycloak.js b/adapters/oidc/js/src/main/resources/keycloak.js index 675c7f94a4..4a6fcb7985 100755 --- a/adapters/oidc/js/src/main/resources/keycloak.js +++ b/adapters/oidc/js/src/main/resources/keycloak.js @@ -41,7 +41,7 @@ } var useNonce = true; - + kc.init = function (initOptions) { kc.authenticated = false; @@ -154,11 +154,19 @@ if (!prompt) { options.prompt = 'none'; } - kc.login(options).success(function () { - initPromise.setSuccess(); - }).error(function () { - initPromise.setError(); - }); + if (kc.useNativePromise) { + kc.login(options).then(function () { + initPromise.setSuccess(); + }).catch(function () { + initPromise.setError(); + }); + } else { + kc.login(options).success(function () { + initPromise.setSuccess(); + }).error(function () { + initPromise.setError(); + }); + } } var checkSsoSilently = function() { @@ -388,7 +396,7 @@ if (options && options.locale) { url += '&ui_locales=' + encodeURIComponent(options.locale); } - + if (options && options.kcLocale) { url += '&kc_locale=' + encodeURIComponent(options.kcLocale); } @@ -1320,7 +1328,7 @@ cordovaOptions.location = 'no'; if (userOptions && userOptions.prompt == 'none') { cordovaOptions.hidden = 'yes'; - } + } return formatCordovaOptions(cordovaOptions); }; @@ -1332,7 +1340,7 @@ var loginUrl = kc.createLoginUrl(options); var ref = cordovaOpenWindowWrapper(loginUrl, '_blank', cordovaOptions); var completed = false; - + var closed = false; var closeBrowser = function() { closed = true; @@ -1375,7 +1383,7 @@ logout: function(options) { var promise = createPromise(false); - + var logoutUrl = kc.createLogoutUrl(options); var ref = cordovaOpenWindowWrapper(logoutUrl, '_blank', 'location=no,hidden=yes');