KEYCLOAK-15113: Move away from deprecated Promise.success()/error()

This commit is contained in:
testn 2020-08-12 16:06:03 +07:00 committed by Stan Silvert
parent 0001a930b4
commit 0362d3a430
14 changed files with 43 additions and 43 deletions

View file

@ -546,13 +546,13 @@ declare namespace Keycloak {
* still valid, or if the token is no longer valid.
* @example
* ```js
* keycloak.updateToken(5).success(function(refreshed) {
* keycloak.updateToken(5).then(function(refreshed) {
* if (refreshed) {
* alert('Token was successfully refreshed');
* } else {
* alert('Token is still valid');
* }
* }).error(function() {
* }).catch(function() {
* alert('Failed to refresh the token, or the session has expired');
* });
*/

View file

@ -20,7 +20,7 @@ var module = angular.module('app', []);
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
module.factory('Auth', function() {
var Auth = {};
@ -59,8 +59,8 @@ angular.element(document).ready(function ($http) {
deferred.resolve(config);
if (keycloakAuth.token) {
keycloakAuth.updateToken(5).success(function() {
}).error(function() {
keycloakAuth.updateToken(5).then(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}

View file

@ -20,7 +20,7 @@ var module = angular.module('app', []);
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
module.factory('Auth', function() {
var Auth = {};
@ -59,8 +59,8 @@ angular.element(document).ready(function ($http) {
deferred.resolve(config);
if (keycloakAuth.token) {
keycloakAuth.updateToken(5).success(function() {
}).error(function() {
keycloakAuth.updateToken(5).then(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}
@ -87,7 +87,7 @@ angular.element(document).ready(function ($http) {
});
angular.bootstrap(document, ["app"]);
}).error(function () {
}).catch(function () {
window.location.reload();
});
});

View file

@ -20,7 +20,7 @@ var module = angular.module('app', []);
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
module.factory('Auth', function() {
var Auth = {};
@ -53,8 +53,8 @@ angular.element(document).ready(function ($http) {
deferred.resolve(config);
if (keycloakAuth.token) {
keycloakAuth.updateToken(5).success(function() {
}).error(function() {
keycloakAuth.updateToken(5).then(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}
@ -81,7 +81,7 @@ angular.element(document).ready(function ($http) {
});
angular.bootstrap(document, ["app"]);
}).error(function () {
}).catch(function () {
window.location = keycloakAuth.createLoginUrl({
idpHint: 'saml-identity-provider'
})

View file

@ -20,7 +20,7 @@ var module = angular.module('app', []);
angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
module.factory('Auth', function() {
var Auth = {};
@ -63,8 +63,8 @@ angular.element(document).ready(function ($http) {
deferred.resolve(config);
if (keycloakAuth.token) {
keycloakAuth.updateToken(5).success(function() {
}).error(function() {
keycloakAuth.updateToken(5).then(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}
@ -91,7 +91,7 @@ angular.element(document).ready(function ($http) {
});
angular.bootstrap(document, ["app"]);
}).error(function () {
}).catch(function () {
window.location.reload();
});
});

View file

@ -60,7 +60,7 @@
responseMode: 'query',
onLoad: 'check-sso',
redirectUri: 'android-app://org.keycloak.examples.cordova/https/keycloak-cordova-example.github.io/login'
}).success(updateState).error(error);
}).then(updateState).catch(error);
}, false);
</script>
<style>

View file

@ -55,7 +55,7 @@
}
document.addEventListener("deviceready", function() {
keycloak.init({ onLoad: "check-sso" }).success(updateState).error(error);
keycloak.init({ onLoad: "check-sso" }).then(updateState).catch(error);
}, false);
</script>
<style>

View file

@ -31,7 +31,7 @@ angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
auth.loggedIn = false;
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
console.log('here login');
auth.loggedIn = true;
auth.authz = keycloakAuth;
@ -40,7 +40,7 @@ angular.element(document).ready(function ($http) {
return auth;
});
angular.bootstrap(document, ["product"]);
}).error(function () {
}).catch(function () {
alert("failed to login");
});
@ -112,12 +112,12 @@ module.factory('authInterceptor', function($q, Auth) {
request: function (config) {
var deferred = $q.defer();
if (Auth.authz.token) {
Auth.authz.updateToken(5).success(function() {
Auth.authz.updateToken(5).then(function() {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + Auth.authz.token;
deferred.resolve(config);
}).error(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}

View file

@ -30,7 +30,7 @@ angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
auth.loggedIn = false;
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
auth.loggedIn = true;
auth.authz = keycloakAuth;
auth.logoutUrl = keycloakAuth.authServerUrl + "/realms/demo/protocol/openid-connect/logout?redirect_uri=/angular-product/index.html";
@ -38,7 +38,7 @@ angular.element(document).ready(function ($http) {
return auth;
});
angular.bootstrap(document, ["product"]);
}).error(function () {
}).catch(function () {
window.location.reload();
});
@ -62,12 +62,12 @@ module.factory('authInterceptor', function($q, Auth) {
request: function (config) {
var deferred = $q.defer();
if (Auth.authz.token) {
Auth.authz.updateToken(5).success(function() {
Auth.authz.updateToken(5).then(function() {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + Auth.authz.token;
deferred.resolve(config);
}).error(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}

View file

@ -98,8 +98,8 @@ User <b id="subject"></b> made this request.
}
keycloak.init({ onLoad: 'login-required' })
.success(reloadData)
.error(function(errorData) {
.then(reloadData)
.catch(function(errorData) {
document.getElementById('customers').innerHTML = '<b>Failed to load data. Error: ' + JSON.stringify(errorData) + '</b>';
});

View file

@ -90,13 +90,13 @@
}
function refreshToken(minValidity) {
keycloak.updateToken(minValidity).success(function(refreshed) {
keycloak.updateToken(minValidity).then(function(refreshed) {
if (refreshed) {
output(keycloak.tokenParsed);
} else {
output('Token not refreshed, valid for ' + Math.round(keycloak.tokenParsed.exp + keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds');
}
}).error(function() {
}).catch(function() {
output('Failed to refresh token');
});
}
@ -173,9 +173,9 @@
flow: 'standard'
};
keycloak.init(initOptions).success(function(authenticated) {
keycloak.init(initOptions).then(function(authenticated) {
output('Init Success (' + (authenticated ? 'Authenticated' : 'Not Authenticated') + ')');
}).error(function() {
}).catch(function() {
output('Init Error');
});

View file

@ -48,7 +48,7 @@ angular.element(document).ready(function ($http) {
var keycloakAuth = new Keycloak('keycloak.json');
auth.loggedIn = false;
keycloakAuth.init({ onLoad: 'login-required' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required' }).then(function () {
console.log('here login');
auth.loggedIn = true;
auth.authz = keycloakAuth;
@ -57,7 +57,7 @@ angular.element(document).ready(function ($http) {
return auth;
});
angular.bootstrap(document, ["product"]);
}).error(function () {
}).catch(function () {
alert("failed to login");
});
@ -117,12 +117,12 @@ module.factory('authInterceptor', function($q, Auth) {
request: function (config) {
var deferred = $q.defer();
if (Auth.authz.token) {
Auth.authz.updateToken(5).success(function() {
Auth.authz.updateToken(5).then(function() {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + Auth.authz.token;
deferred.resolve(config);
}).error(function() {
}).catch(function() {
deferred.reject('Failed to refresh token');
});
}

View file

@ -702,9 +702,9 @@ public class JavascriptAdapterTest extends AbstractJavascriptTest {
@Test
public void testRefreshTokenWithDeprecatedPromiseHandles() {
String refreshWithDeprecatedHandles = "var callback = arguments[arguments.length - 1];" +
" window.keycloak.updateToken(9999).success(function (refreshed) {" +
" window.keycloak.updateToken(9999).then(function (refreshed) {" +
" callback('Success handle');" +
" }).error(function () {" +
" }).catch(function () {" +
" callback('Error handle');" +
" });";

View file

@ -96,7 +96,7 @@ angular.element(document).ready(function () {
return auth;
});
keycloakAuth.init({ onLoad: 'login-required', pkceMethod: 'S256' }).success(function () {
keycloakAuth.init({ onLoad: 'login-required', pkceMethod: 'S256' }).then(function () {
auth.authz = keycloakAuth;
whoAmI(function(data) {
@ -117,7 +117,7 @@ angular.element(document).ready(function () {
});
loadSelect2Localization();
}).error(function () {
}).catch(function () {
window.location.reload();
});
});
@ -128,12 +128,12 @@ module.factory('authInterceptor', function($q, Auth) {
if (!config.url.match(/.html$/)) {
var deferred = $q.defer();
if (Auth.authz.token) {
Auth.authz.updateToken(5).success(function () {
Auth.authz.updateToken(5).then(function () {
config.headers = config.headers || {};
config.headers.Authorization = 'Bearer ' + Auth.authz.token;
deferred.resolve(config);
}).error(function () {
}).catch(function () {
location.reload();
});
}