Skip to content

Commit

Permalink
KEYCLOAK-15721 KeycloakPromise sometimes doesn't work
Browse files Browse the repository at this point in the history
  • Loading branch information
vmuzikar authored and pedroigor committed Sep 28, 2020
1 parent 04415d3 commit fbe18e6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 35 deletions.
55 changes: 22 additions & 33 deletions adapters/oidc/js/src/main/resources/keycloak.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,38 +74,6 @@
}
}

function toKeycloakPromise(promise) {
promise.__proto__ = KeycloakPromise.prototype;
return promise;
}

function KeycloakPromise(executor) {
return toKeycloakPromise(new Promise(executor));
}

KeycloakPromise.prototype = Object.create(Promise.prototype);
KeycloakPromise.prototype.constructor = KeycloakPromise;

KeycloakPromise.prototype.success = function(callback) {
logPromiseDeprecation();

var promise = this.then(function handleSuccess(value) {
callback(value);
});

return toKeycloakPromise(promise);
};

KeycloakPromise.prototype.error = function(callback) {
logPromiseDeprecation();

var promise = this.catch(function handleError(error) {
callback(error);
});

return toKeycloakPromise(promise);
};

function Keycloak (config) {
if (!(this instanceof Keycloak)) {
return new Keycloak(config);
Expand Down Expand Up @@ -1208,10 +1176,31 @@
p.reject(result);
}
};
p.promise = new KeycloakPromise(function(resolve, reject) {
p.promise = new Promise(function(resolve, reject) {
p.resolve = resolve;
p.reject = reject;
});

p.promise.success = function(callback) {
logPromiseDeprecation();

this.then(function handleSuccess(value) {
callback(value);
});

return this;
}

p.promise.error = function(callback) {
logPromiseDeprecation();

this.catch(function handleError(error) {
callback(error);
});

return this;
}

return p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,9 @@ public void fragmentInLoginFunction() {
@Test
public void testRefreshTokenWithDeprecatedPromiseHandles() {
String refreshWithDeprecatedHandles = "var callback = arguments[arguments.length - 1];" +
" window.keycloak.updateToken(9999).then(function (refreshed) {" +
" window.keycloak.updateToken(9999).success(function (refreshed) {" +
" callback('Success handle');" +
" }).catch(function () {" +
" }).error(function () {" +
" callback('Error handle');" +
" });";

Expand Down

0 comments on commit fbe18e6

Please sign in to comment.