Im using Keycloak 25.
Im using python keycloak to use keycloak API.
I’ve managed to enable Impersonation from web interface but I need to impersonate user by api using token echange.
The official page has differente screenshot and I cant find section where enable token_exchange.
https://www.keycloak.org/docs/latest/securing_apps/index.html#_token-exchange
This is the method sign in KeycloakOpenID
def exchange_token(
self,
token: str,
audience: Optional[str] = None,
subject: Optional[str] = None,
subject_token_type: Optional[str] = None,
subject_issuer: Optional[str] = None,
requested_issuer: Optional[str] = None,
requested_token_type: str = "urn:ietf:params:oauth:token-type:refresh_token",
scope: str = "openid",
) -> dict:
"""Exchange user token.
Use a token to obtain an entirely different token. See
https://www.keycloak.org/docs/latest/securing_apps/index.html#_token-exchange
This is the error I get:
keycloak.exceptions.KeycloakPostError: 400: b'{"error":"unsupported_grant_type","error_description":"Unsupported grant_type"}'