Add client api for requesting entitlements with permission requests
This commit is contained in:
parent
ec0f222f7e
commit
d7d91cfbc0
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.
|
||||
*/
|
||||
this.entitlement = function (resourceSeververId) {
|
||||
this.entitlement = function (resourceSeververId, permissionRequests) {
|
||||
this.then = function (onGrant, onDeny, onError) {
|
||||
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 () {
|
||||
if (request.readyState == 4) {
|
||||
|
@ -149,7 +148,19 @@
|
|||
}
|
||||
};
|
||||
|
||||
request.send(null);
|
||||
var erJson = null
|
||||
|
||||
if(permissionRequests) {
|
||||
request.open('POST', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true);
|
||||
request.setRequestHeader("Content-type", "application/json");
|
||||
erJson = JSON.stringify(permissionRequests)
|
||||
} else {
|
||||
request.open('GET', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true);
|
||||
}
|
||||
|
||||
request.setRequestHeader('Authorization', 'Bearer ' + keycloak.token)
|
||||
request.send(erJson);
|
||||
|
||||
};
|
||||
|
||||
return this;
|
||||
|
|
Loading…
Reference in a new issue