Skip to content

Commit

Permalink
KEYCLOAK-15113: Move away from deprecated Promise.success()/error()
Browse files Browse the repository at this point in the history
  • Loading branch information
testn authored and ssilvert committed Sep 1, 2020
1 parent 0001a93 commit 0362d3a
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions adapters/oidc/js/src/main/resources/keycloak.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
* });
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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');
});
}
Expand All @@ -87,7 +87,7 @@ angular.element(document).ready(function ($http) {
});

angular.bootstrap(document, ["app"]);
}).error(function () {
}).catch(function () {
window.location.reload();
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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');
});
}
Expand All @@ -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'
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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');
});
}
Expand All @@ -91,7 +91,7 @@ angular.element(document).ready(function ($http) {
});

angular.bootstrap(document, ["app"]);
}).error(function () {
}).catch(function () {
window.location.reload();
});
});
Expand Down
2 changes: 1 addition & 1 deletion examples/cordova-native/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion examples/cordova/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
8 changes: 4 additions & 4 deletions examples/cors/angular-product-app/src/main/webapp/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,7 +40,7 @@ angular.element(document).ready(function ($http) {
return auth;
});
angular.bootstrap(document, ["product"]);
}).error(function () {
}).catch(function () {
alert("failed to login");
});

Expand Down Expand Up @@ -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');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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";
module.factory('Auth', function() {
return auth;
});
angular.bootstrap(document, ["product"]);
}).error(function () {
}).catch(function () {
window.location.reload();
});

Expand All @@ -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');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ <h2>Customer Listing</h2>
}

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>';
});

Expand Down
8 changes: 4 additions & 4 deletions examples/js-console/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ <h2>Events</h2>
}

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');
});
}
Expand Down Expand Up @@ -173,9 +173,9 @@ <h2>Events</h2>
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');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -57,7 +57,7 @@ angular.element(document).ready(function ($http) {
return auth;
});
angular.bootstrap(document, ["product"]);
}).error(function () {
}).catch(function () {
alert("failed to login");
});

Expand Down Expand Up @@ -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');
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -702,9 +702,9 @@ public void fragmentInLoginFunction() {
@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');" +
" });";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -117,7 +117,7 @@ angular.element(document).ready(function () {
});

loadSelect2Localization();
}).error(function () {
}).catch(function () {
window.location.reload();
});
});
Expand All @@ -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();
});
}
Expand Down

0 comments on commit 0362d3a

Please sign in to comment.