Open rcapp opened 1 year ago
Quick update: I changed how the library behaves when checking the audience, haven't done any real work to test and validate. So I won't call it a "solution". Also, I'm not sure how much this change bellow would impact the rest of the library:
def decode_token(self, token, key, algorithms=["RS256"], **kwargs):
"""Decode user token. """
return jwt.decode(token, key, algorithms=algorithms, **kwargs)
Then, I provide the intended audience (account
) for the access_token
, since I cannot pass a ID Token to use the client audience.
https://github.com/keycloak/keycloak/discussions/14398 -- this is more or less my situation and one of the replies mention the client_id
should be used on ID Token, not on access_token
.
Cheers!
found a workaround here https://github.com/marcospereirampj/python-keycloak/issues/89#issuecomment-1497759963
The error you're encountering seems to be related to how you are decoding and validating a JWT token using the PyJWT library in Python. The error messages are indicating problems with the audience (aud) claim in the JWT. The issue appears to be in the validation of the audience, which doesn't match what you expected.
To resolve this issue, follow these steps:
1.Review Audience (aud) Claim: The error messages suggest that there is a problem with the audience claim in the JWT. Verify that the audience you are providing to the jwt.decode method ("demo-api") matches the audience in the token. In your code, it seems you're expecting the audience to be "demo-api".
2.Check Token Payload: Print the contents of the token["id_token"] to see what audience is included in the token. Make sure the audience in the token matches what you're using in the jwt.decode method. Verify that the aud claim in the decoded token matches the expected audience ("demo-api").
3.Ensure Proper Token Signing Algorithm: Ensure that the token you are trying to decode (token["id_token"]) is signed using the RS256 algorithm since you are specifying algorithms="RS256" when calling jwt.decode. If the token uses a different signing algorithm, you will need to adjust the algorithm parameter accordingly.
Check Token Issuer (iss) Claim: Additionally, you should verify that the issuer (iss) claim of the token ("iss") matches your Keycloak server's URL. You can add this check using the issuer parameter when calling jwt.decode.
Verify Token in Keycloak: Manually verify the token in your Keycloak admin console to confirm the audience claim and other token attributes.
Hello, everyone!
I'm trying to use the
get_policies
function, but I'm getting errors related with the Audience. I cannot find where in Keycloak I set them, so I'm not able to see if they are doubled (one of the errors says there are too many audiences). It maybe a problem with my configuration, but could be a bug too. Nevertheless, here is how I'm doing it:These are the errors:
The two commands bellow they also crashes:
policies = keycloak_openid.get_policies( ..., audience="account", ...) # same error as above
and without the
audience
parameter it crashes with the error bellow:Any help is appreciated! Cheers!