Repository navigation
|
Hi all, I am new to Keycloak and loving most of it. However, I am currently stuck with validating the audience. I created a new client "client_xy" and created some client roles. The roles are stored properly in the ID and access tokens at "resource_access.client_xy.roles", however, the audience claim "aud" is behaving strangely: In the ID token the client ID is used ("aud": "client_xy"), while in the access token the account client ID is used ("aud": "account"). Is there some obvious error in the configuration that could cause that behavior? I also need "aud": "client_xy" in the access token, not only in the ID token. I am on version 19.0.2. Any advice would be much appreciated! |
Replies: 4 comments 16 replies
|
@Zacherl That's exactly working as intended. The audience of an ID token is the client who is actually retrieving the token to get information on the user. The audience of the access token is some resource server (api) the client will pass the token to when making a request. The access token could be opaque as per OAuth2 spec so it is in general not even readable by the client. |
|
Older versions of keycloak did not add an aud claim to the access token. You can control the aud claim value by adding an "Audience" mapper to the client's (or scope's) mappers and enabling the "add to access token" switch of the mapper. |
|
Thanks a lot you for your quick replies! @sschu The client that retrieved the token was "client_xy", not "account" - I'm actually not using the "account" client at all. Is it still working as intended if the "aud" claim contains "account"? I expected "client_xy" in there. I am a bit confused - I even checked the "token" request containing the three tokens in its response (ID token, access token and refresh token). The ID token has "client_xy" as audience (as expected), the access token "account". Adding an audience mapper would work, but then I would have to add an audience mapper for every client. |
|
If the access token actually contains the client ID of a completely uninvolved client (here: "account"), this looks like a misconfiguration or a bug. The OAuth use case of the access token is not primarily that the frontend client (which triggered the authentication, which is in the azp claim) can check the user identity (that is what the ID token is for!). Rather, the purpose of the access token is to use it when calling a 3rd party API. This 3rd party then checks whether it itself is entered as an addressee in the aud claim. So you really only need the audience mapper for clients that use the access token in such a 3rd party delgation scenario. |
If the access token actually contains the client ID of a completely uninvolved client (here: "account"), this looks like a misconfiguration or a bug.
The OAuth use case of the access token is not primarily that the frontend client (which triggered the authentication, which is in the azp claim) can check the user identity (that is what the ID token is for!). Rather, the purpose of the access token is to use it when calling a 3rd party API. This 3rd party then checks whether it itself is entered as an addressee in the aud claim.
So you really only need the audience mapper for clients that use the access token in such a 3rd party delgation scenario.