Open hpylypets-ua opened 1 year ago
The OAuth2 spec does not specify how the audience would be used and validated for client_credentials flows, which is why we do not support it currently. I think auth0 supports an audience claim, but I don't think they validate it?
I will check later if the audience is validated, but it's included in JWT tokens - here are decoded tokens from Azure AD and Keycloak.
Sorry for the delay in response.
I think auth0 supports an audience claim, but I don't think they validate it?
I checked for Keycloak: there are multiple ways to use audience there. One is a hardcoded value without a validation that can be customized, and another one, dynamic setting/verifying the audience claim based on the provided scope. So answering to your question, they have an option for validating an audience.
https://www.keycloak.org/docs/latest/server_admin/#_audience_hardcoded For example, Client -> Client Details -> Client Scope -> choose dedicated scope -> add mapper -> by configuration -> audience/audience resolve. Then added audience claims can be included in the token.
https://www.keycloak.org/docs/latest/server_admin/#setup-4
"verify-token-audience" : true,
When setting up audience checking:
Ensure that services are configured to check audience on the access token sent to them by adding the flag verify-token-audience in the adapter configuration. See Adapter configuration for details.
Ensure that access tokens issued by Keycloak contain all necessary audiences. Audiences can be added using the client roles as described in the next section or hardcoded. See Hardcoded audience.
I don't have a ready to test auth0 setup to verify how it works there, but they also have examples with audience
and client_credentials
requests - https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#example-post-to-token-url
The OAuth2 spec does not specify how the audience would be used and validated for client_credentials flows, which is why we do not support it currently.
But as I showed in my first message, specifying an invalid audience leads to an error. The only problem is that aud
claim is empty in the JWT token obtained for the client_credentials
grant type in case of Ory Hydra.
I think it makes sense for Ory Hydra to include an audience claim in the JWT token if specified at client creation to mimic the hardcoded behaviour from the Keycloak. What do you think, @aeneasr?
i am also curious how we should validate the token without the aud
is returned from introspection? using scope
instead? if using scope
, does hydra support registering resource with custom scope?
In our case, we are trying to use hydra as the authorization server for secure our APIs. currently we are using the context path as the scope, so that nginx will intercept the request and use issuer url
+scope
to do the authorization before sending request to the upstream. I am hoping to use aud
for this validation, and use scope
for granting permission for things like read
or write
I believe this to now be possible using actions / webhooks: https://www.ory.sh/docs/hydra/guides/claims-at-refresh
Preflight checklist
Describe the bug
No audience is returned for client_credentials grant flow even when the audience parameter is explicitly set. This issue results in an invalid JWT token when validating it because of an empty aud claim.
How to set up an audience for the client? Docs doesn't help - https://www.ory.sh/docs/hydra/guides/audiences, same for tutorial - https://www.ory.sh/docs/hydra/5min-tutorial
Reproducing the bug
This is easily reproducible:
docker run --name hydra -e DSN=memory -e SECRETS_SYSTEM=abcdefghjklimnop -e STRATEGIES_ACCESS_TOKEN=jwt -p 4444:4444 -p 4445:4445 oryd/hydra:v2.0.3 serve all --dev
docker exec hydra hydra create client --endpoint http://127.0.0.1:4445/ --format json --grant-type client_credentials --audience account
.--data-urlencode 'audience=account'
results in the same response as without the audience.Relevant log output
Relevant configuration
No response
Version
2.0.3(latest)
On which operating system are you observing this issue?
Linux
In which environment are you deploying?
Docker
Additional Context
I'm unable to use Ory Hydra as a token provider for Kafka Oauthbearer OIDC because of empty audience array, which is unexpected for JwtConsumer.
Keycloak works fine since it returns audience.