In a microservice architecture, we use JWT tokens from keycloak. Now we would like to get a second access token with less rights (less claims/ less roles). The use case is: the new access token should give its owner access to just one document in the document store. Why? To limit the damage someone could do if he can steal this token.
Ideally, we could get this second token via a special refresh_token call (the user holding the refresh token has the right to get a full access token, so he should also be able to get a partial access token). How could we do this?
Using scopes does not seem to work: the list of given scopes are only evaluated at login (so at the moment of refreshing a token, I cannot adopt the list of scopes).
I also tried to understand https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_overview or RPTs. But unfortunately, I am missing some documentation (and my tries failed).
Are there other ideas? Or maybe even an example showing how to do this?
Later edit to make my question about RPTs more explicit: https://www.keycloak.org/docs/latest/authorization_services/index.html#_service_overview says:
... Keycloak Authorization Services provide extensions to OAuth2 to allow access tokens to be issued based on the processing of all policies associated with the resource(s) or scope(s) being requested. This means that resource servers can enforce access to their protected resources based on the permissions granted by the server and held by an access token. In Keycloak Authorization Services the access token with permissions is called a Requesting Party Token or RPT for short.
Could such an access token with permissions be used for our goal?
In my experiments I could get token with a grant_type=urn:ietf:params:oauth:grant-type:uma-ticket . But there were some issues:
I had to change some settings in keycloak to enable permissions (before it would say "Client does not support permissions"). After I made these changes, my normal login call would no longer work (I could test while my token was still valid). I had to scratch my keycloak config to continue working.
I do not really understand the permission model to use for this feature
An end-to-end example would be useful (the ones in the Keycloak documentation are a bit abstract).