Cannot exchange external OIDC ID token for Hydra access token due to aud
claim handling in Hydra
#3723
Open
3 of 5 tasks
Labels
bug
Something is not working.
Preflight checklist
Ory Network Project
No response
Describe the bug
Trying to acquire an access token from Hydra using the
urn:ietf:params:oauth:grant-type:jwt-bearer
grant type fails when including an JWT from GitLab as the identity provider when making a request to the/oauth2/token
. The intent is to receive an ID token through social sign-in with GitLab and then have Hydra respond with an access token upon successful verification of the JWT. I was basically following the docs for using JWTs as authorization grants. This process is automated with a custom tool calledopaal
.The entire flow is broken down as follows:
opaal
initiates an authorization code flow by redirecting user to GitLab (assuming there's a registered client)User logs in and authorizes application with set scopes
GitLab redirects back to
opaal
endpoint with codeopaal
makes another request back to GitLab with code to receive token (only interested in ID token)opaal
fetches the JWKS from GitLab to include JWK in request to trust issuerThe GitLab instance is added as a trusted issuer with the
/admin/trust/grants/jwt-bearer/issuers
endpointA client is created/registered with Hydra with client ID, secret, and
urn:ietf:params:oauth:grant-type:jwt-bearer
grant typeRequest is made to
/oauth2/token
endpoint with grant type, client ID, and assertionThe expected output is another token from Hydra, but Hydra is complaining about the token having the wrong audience (see error below), which I believe is the intended behavior according to section 3.3 of RFC 7523 and the OpenID documentation. How would you go about using a JWT from another OIDC provider with Hydra if the provider sets the audience to something other than the intended token endpoint for Hydra?
Reproducing the bug
Register OAuth2 app with GitLab (or any OIDC identity provider??)
Run
opaal
with appropriate configuration fileLogin and consent to app access scopes (returns code used by
opaal
)Observe output from
opaal
Alternatively to running
opaal
, run the following instead after getting token:Add trusted issuer:
curl http://127.0.0.1:4445/admin/trust/grants/jwt-bearer/issuers -X POST -H 'Content-Type: application/json' -d '{"allow_any_subject": false, "issuer": "https://gitlab.com", "subject": "1", "expires_at": "2025-01-01 12:00:00", "jwk": "$jwk", "scope": ["openid", "profile", "email"]}'
Register new client:
curl http://127.0.0.1:4444/oauth2/client -X POST -H 'Content-Type: application/json' -d '{"client_name": "opaal", "token_endpoint_auth_method": "client_secret_post", "scope": "openid email profile", "grant_types": ["client_credentials", "urn:ietf:params:oauth:grant-type:jwt-bearer"], "response_type": ["token"]}'
Make a request for a token:
curl http://127.0.0.1:4444/oauth2/token -H 'Content-Type: application/x-www-form-urlencoded' -d 'grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&client_id=43b425a7-c687-4e20-92d0-c5f6ca81631e&client_secret=gloas-d478a49ce2e99a03f37d4324aa68832fbfb9d0712f92493c42a5db13b4540299&scope=openid+profile+email&assertion=${jwt}'
Relevant log output
Relevant configuration
Version
2.2.0
On which operating system are you observing this issue?
macOS
In which environment are you deploying?
Docker Compose
Additional Context
No response
Editted links and formatting
The text was updated successfully, but these errors were encountered: