If I have a user that has authenticated with keycloak with public client C1 under realm R is there an endpoint I can hit in keycloak that will generate a new access token for a different public client C2 under the same realm R?
[Update #1] I tried using the refresh token to obtain a new access token for C2 client but I get the following error:
Invalid refresh token. Token client and authorized client don't match
[Update #2] So, the above gave me the idea of trying to use the exchange token grant type and I have it working now.
curl --request POST \
'https://myhost.com.au/auth/realms/<my realm>/protocol/openid-connect/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=urn:ietf:params:oauth:grant-type:token-exchange' \
--data-urlencode 'subject_token=<c1 access token>' \
--data-urlencode 'subject_token_type=urn:ietf:params:oauth:token-type:access_token' \
--data-urlencode 'requested_token_type=urn:ietf:params:oauth:token-type:refresh_token' \
--data-urlencode 'client_id=<c2 client id>'
Your question makes sense. Unfortunately the role scope mapping documentation is elusive about how to generate a new access token when switching to a different client.
There is an Oauth2 RFC about token exchange. As of Keycloak 11.0.2 token exchange is documented as a technology preview and has to be enabled with
-Dkeycloak.profile.feature.token_exchange=enabled
You can exchange tokens this way (actually taken from the question):
Here is some context from the "role scope mapping" documentation intended for other readers.