Keycloak cannot get RPT with Permissions using service account token

喜夏-厌秋 提交于 2021-01-04 07:31:01

问题


I am using Keycloak: 4.8.3.Final

I have the following clients in Keycloak

  • UserService

  • InventoryService

InventoryService has some resources defined in Keycloak and Authorization enabled.

UserService (as a service-account) has the necessary client-roles assigned in the service-account-roles tab

Whenever someone tries to access the APIs of InventoryService, I do the following:

  • Get the access token from the Authorization Header
  • get RPT (as mentioned here)
  • introspect the RPT if the desired permissions are present or not.

I am getting the following error response when the UserService tries to access the apis of InventoryService

{
  "error": "invalid_resource",
  "error_description": "Resource with id [item] does not exist."
}

Here is the code snippet in java.

I am getting the following error response when the UserService tries to access the apis of InventoryService

AuthorizationResource authResource = authzClient.authorization(at);
AuthorizationRequest request = new AuthorizationRequest();
request.addPermission(resourceId, scopes);
AuthorizationResponse authResponse = authResource.authorize(request);
String rpt = authResponse.getToken();

When I remove the line request.addPermission(resourceId, scopes); I am able to get an RPT with all the list of Permissions. but if I include it the above error is thrown.

Btw, one more observation is: the above code snippet works fine when the token belongs to a User (not a service account).

Can any let me know what is happening? Is this a bug in Keycloak?


回答1:


This problem persists in KeyCloak 11.0.2. Service accounts are explicitly excluded in the authorization token service.

However, you can work around this by explicitly setting the azp claim to something other than your client_id via a protocol mapper on your client.

.



来源:https://stackoverflow.com/questions/57591475/keycloak-cannot-get-rpt-with-permissions-using-service-account-token

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!