Resource Server jwt Sample code
From ESS-WIKI
Revision as of 07:27, 16 January 2017 by Dylan.chang (talk | contribs) (Created page with "*Maven Dependency <pre><code data-lang="xml"><dependencies> <dependency> <groupId>org.keycloak</groupId> <artifactId>keycloak-authz-client</artifactId>...")
- Maven Dependency
<code data-lang="xml"><dependencies> <dependency> <groupId>org.keycloak</groupId> <artifactId>keycloak-authz-client</artifactId> <version>${KEYCLOAK_VERSION}</version> </dependency> </dependencies></code>
- Obtaining User Entitlements
<code data-lang="java">// create a new instance based on the configuration defined in keycloak-authz.json AuthzClient authzClient = AuthzClient.create(); // obtain an Entitlement API Token to get access to the Entitlement API. // this token is an access token issued to a client on behalf of an user // with a scope = kc_entitlement String eat = getEntitlementAPIToken(authzClient); // send the entitlement request to the server to // obtain an RPT with all permissions granted to the user EntitlementResponse response = authzClient.entitlement(eat) .getAll("hello-world-authz-service"); String rpt = response.getRpt(); System.out.println("You got a RPT: " + rpt); // now you can use the RPT to access protected resources on the resource server</code>