+
Skip to content

UserInfo request fails by using an access token obtained in Hybrid fl… #39183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2025

Conversation

mposolda
Copy link
Contributor

@mposolda mposolda commented Apr 24, 2025

…ow with offline_access scope

closes #39037

Problem: When there is hybdrid flow requested (the request sent to OIDC authentication endpoint with something like response_type=code token) together with offline access requested (the scope=offline_access), there are access-tokens (and possibly ID tokens etc) issued from the OIDC authorization response. When these access-tokens are sent to KEycloak endpoints (like UserInfo endpoint or Introspection endpoint) before the code from authz response is exchanged for another set of tokens (in the code-to-token request),the requests fails.

Cause: Before OIDC authentication response is sent back to the client after successful authentication, Keycloak creates only regular "online" user session. Then during code-to-token request (processed by AuthorizationCodeGrantType), the online session is possibly removed and there is instead offline user session created. So when the request is sent to UserInfo endpoint with the token from OIDC authentication response, before the code-to-token request, the offline user session does not yet exists. With the changes from #37662, Keycloak is now more opinionated as it knows that access-tokens is associated with the offline-session and hence tries to lookup only offline-session (not "online" session). Which fails as offline session does not yet exists.

The approach I've used in the PR is to create offline session at the end of the OIDC authorization code flow in case that "hybrid" flow is used. In that case, UserInfo can be successfully invoked even before code-to-token request as offline session already exists.

The alternative approach I was considering was to create offline session still as before in the code-to-token request. But instead possibly introduce another type of AccessTokenContext.SessionType, which will allow to lookup both offline or online session. In that case, access-token will be able to fallback to lookup online session in case that offline session does not yet exists. Let me know if you prefer this approach. It would have advantage that does not need to create offline session earlier than needed (as it is really needed just when refresh offline token is going to be issued), but it would make a code a little bit more complicated than necessary.

…ow with offline_access scope

closes keycloak#39037

Signed-off-by: mposolda <mposolda@gmail.com>
@mposolda mposolda force-pushed the 39037-offline-token-hybrid-flow branch from a1f0bd7 to ef26a17 Compare April 24, 2025 13:13
@mposolda mposolda requested review from rmartinc and tnorimat April 24, 2025 14:21
Copy link
Contributor

@rmartinc rmartinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mposolda! LGTM!

@tnorimat
Copy link
Contributor

@mposolda Thank you for sending the PR. I wil review it. Also, I would like to run the OIDC conformance tests against the Keycloak including the PR to confirm that the Keycloak can pass the tests. I will notify you of its test results, so please wait for that.

@mposolda
Copy link
Contributor Author

@rmartinc Thanks for the review!
@tnorimat Cool, Thanks for the info. I will wait for your review and for you running OIDC conformance testsuite.

@tnorimat
Copy link
Contributor

@mposolda I ran not only OIDC but also FAPI1, FAPI2, FAPI-CIBA, OIDC logout conformance tests against the Keycloak built from the branch of the PR and confirmed that the Keycloak can pass all the conformance tests.

Copy link
Contributor

@ahus1 ahus1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving based on previous reviews.

@ahus1 ahus1 merged commit 54e1c8a into keycloak:main Apr 25, 2025
77 checks passed
@mposolda
Copy link
Contributor Author

@tnorimat Thanks for checking the conformance testsuites!
@ahus1 Thanks as well for merging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UserInfo request fails by using an access token obtained in Hybrid flow with offline_access scope
4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载