Direct Naked Impersonation - error: access_denied
See original GitHub issueDescribe the bug
I have followed directions according to the guide (https://www.keycloak.org/docs/latest/securing_apps/#direct-naked-impersonation), but still cannot get it to work. After researching, seems like others can’t get it to work neither (https://keycloak.discourse.group/t/direct-naked-impersonation/6887/3) and unfortunately I wasn’t able to find a possible solution.
Details about my Keycloak installation:
Version: 18 Installed using containers (AWS ECS) and using this guide: https://www.keycloak.org/server/containers SSL enabled token-exchange and admin-fine-grained-authz features enabled
Example request:
curl --location --request POST 'https://example_domain.com/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 'client_id=my-client' \
--data-urlencode 'client_secret=iXwJB01N5u0WcTEMMcGA1KvUWm5VA9HN' \
--data-urlencode 'requested_subject=test_user'
Example response:
403
{
"error": "access_denied",
"error_description": "Client not allowed to exchange"
}
Has anybody experienced the same or know if there’s anything else to configure or may it be a bug?
Version
18
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Anything else?
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Related StackOverflow Question
I figured out a way, but I’m not sure this is the right way to do it. Some help from more experienced experts would be very much appreciated.
When following the Direct Naked Impersonation guide, instead of
user-impersonatedunderUsers -> PermissionsI choseimpersonateto apply theclient-impersonatorspolicy.And then in order to achieve the desired result, there’s rather a 2 step call that looks like this:
Client
access_tokenfrom the response will then be used in the next call as asubject_tokenparameter.Response of the above should give User’s access token that then can be used to authenticate (or rather impersonate).
However it’s still not at all how the official guide describes it.
@pedroigor The updated Documentation still does not reflect that the whole Direct Naked steps are wrong like what @motiejuss mentioned. In the documentation it is just a ONE STEP curl with the clientID and secret, not like the example that @motiejuss provided which is two steps and requires the access token from first doing a client_credential flow.
Below is what the current documentation have without mention of the subject token.