From d7d91cfbc0a3793039c65f8fd8d56ae3cf82924f Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Thu, 20 Oct 2016 15:50:57 +0200 Subject: [PATCH 1/2] Add client api for requesting entitlements with permission requests --- .../js/src/main/resources/keycloak-authz.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/adapters/oidc/js/src/main/resources/keycloak-authz.js b/adapters/oidc/js/src/main/resources/keycloak-authz.js index 4e4255637e..2ce9ba4465 100644 --- a/adapters/oidc/js/src/main/resources/keycloak-authz.js +++ b/adapters/oidc/js/src/main/resources/keycloak-authz.js @@ -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; From 94d4afa11cb0477f8c644db30175f76e514b16f5 Mon Sep 17 00:00:00 2001 From: Cherian Mathew Date: Thu, 20 Oct 2016 17:24:41 +0200 Subject: [PATCH 2/2] Refactor entitlement request argument name --- adapters/oidc/js/src/main/resources/keycloak-authz.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adapters/oidc/js/src/main/resources/keycloak-authz.js b/adapters/oidc/js/src/main/resources/keycloak-authz.js index 2ce9ba4465..843b11d9fb 100644 --- a/adapters/oidc/js/src/main/resources/keycloak-authz.js +++ b/adapters/oidc/js/src/main/resources/keycloak-authz.js @@ -118,7 +118,7 @@ /** * Obtains all entitlements from a Keycloak Server based on a give resourceServerId. */ - this.entitlement = function (resourceSeververId, permissionRequests) { + this.entitlement = function (resourceSeververId, entitlementRequest ) { this.then = function (onGrant, onDeny, onError) { var request = new XMLHttpRequest(); @@ -150,10 +150,10 @@ var erJson = null - if(permissionRequests) { + if(entitlementRequest) { request.open('POST', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true); request.setRequestHeader("Content-type", "application/json"); - erJson = JSON.stringify(permissionRequests) + erJson = JSON.stringify(entitlementRequest) } else { request.open('GET', keycloak.authServerUrl + '/realms/' + keycloak.realm + '/authz/entitlement/' + resourceSeververId, true); }