Merge pull request #3402 from brewers/feature/js-entitlement-request
KEYCLOAK-3777: Add client api for requesting entitlements with permission requests
This commit is contained in:
commit
44977207e3
1 changed files with 15 additions and 4 deletions
|
@ -118,12 +118,11 @@
|
||||||
/**
|
/**
|
||||||
* Obtains all entitlements from a Keycloak Server based on a give resourceServerId.
|
* Obtains all entitlements from a Keycloak Server based on a give resourceServerId.
|
||||||
*/
|
*/
|
||||||
this.entitlement = function (resourceSeververId) {
|
this.entitlement = function (resourceSeververId, entitlementRequest ) {
|
||||||
this.then = function (onGrant, onDeny, onError) {
|
this.then = function (onGrant, onDeny, onError) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
|
|
||||||
request.open('GET', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true);
|
|
||||||
request.setRequestHeader('Authorization', 'Bearer ' + keycloak.token)
|
|
||||||
|
|
||||||
request.onreadystatechange = function () {
|
request.onreadystatechange = function () {
|
||||||
if (request.readyState == 4) {
|
if (request.readyState == 4) {
|
||||||
|
@ -149,7 +148,19 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
request.send(null);
|
var erJson = null
|
||||||
|
|
||||||
|
if(entitlementRequest) {
|
||||||
|
request.open('POST', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true);
|
||||||
|
request.setRequestHeader("Content-type", "application/json");
|
||||||
|
erJson = JSON.stringify(entitlementRequest)
|
||||||
|
} else {
|
||||||
|
request.open('GET', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
request.setRequestHeader('Authorization', 'Bearer ' + keycloak.token)
|
||||||
|
request.send(erJson);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
Loading…
Reference in a new issue