FFFF UserInfo request fails by using an access token obtained in Hybrid flow with offline_access scope · Issue #39037 · keycloak/keycloak · GitHub
[go: up one dir, main page]

Skip to content

UserInfo request fails by using an access token obtained in Hybrid flow with offline_access scope #39037

Closed

Description

@tnorimat

Before reporting an issue

  • I have read and understood the above terms for submitting issues, and I understand that my issue may be closed without action if I do not follow them.

Area

oidc

Describe the bug

In hybrid flow with offline_access scope (response_type = code token OR code token id_token, scope = openid offline_access), UserInfo request with an access token obtained from an autorization response fails as 401 Unauthorized (error = "invalid_token", error_description="user_session_not_found").

In the earlier version of 26.2.0, it does not happen.

Due to this issue, Keycloak 26.2.0 cannot pass OpenID Foundation's OIDC conformance tests while all the earlier version of Keycload could pass.

Version

26.2.0

Regression

  • The issue is a regression

Expected behavior

We can get an appropriate UserInfo response as 200 OK.

Actual behavior

We get an error UserInfo response as 401 Unauthorized (error = "invalid_token", error_description="user_session_not_found").

How to Reproduce?

  1. Send an authorization request with response_type = code token OR code token id_token, which means doing OIDC hybrid flow and scope = openid offline_access .
  2. On the login screen, a user input their username and password, which lead to successful login.
  3. On the consent screen, the user input their cosent.
  4. Receive an authorization response with an access token.
  5. Send a UserInfo request with the access token.
  6. Receive an error UserInfo response.

Example:
[1] an authorization request
{
"client_id": "0908b642-8d6c-4075-80e2-d2d7628c9bb1",
"redirect_uri": "https://conformance-suite.keycloak-fapi.org/test/a/keycloak/callback",
"scope": "openid offline_access",
"state": "YQhigLVlWq",
"nonce": "Baki3USTOx",
"response_type": "code token",
"prompt": "consent"
}
->
https://as.keycloak-fapi.org/auth/realms/test/protocol/openid-connect/auth?client_id=0908b642-8d6c-4075-80e2-d2d7628c9bb1&redirect_uri=https://conformance-suite.keycloak-fapi.org/test/a/keycloak/callback&scope=openid%20offline_access&state=YQhigLVlWq&nonce=Baki3USTOx&response_type=code%20token&prompt=consent

[4] an authorization response
https://conformance-suite.keycloak-fapi.org/test/a/keycloak/callback#state=YQhigLVlWq&session_state=8d1f2e10-0df9-403f-a6f0-23e32e1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EZn6ms7YCMQAgbFgCMe8j_xeCZKEIkFbeJxRsi4q62SrT9i0e6Tv3X_aD_JXQibr07gbMyg&token_type=Bearer&expires_in=300

[6] an error UserInfo response
401 Unauthorized
Header:
"www-authenticate": "Bearer realm="test", error="invalid_token", error_description="user_session_not_found"",

Anything else?

I found the issue when I ran the OpenID Foundation's OIDC conformance test against Keycloak 26.2.0.

(1) The authorization request's scope includes "offline_access", which may contribute to this issue.
(2) When receiving the UserInfo request, Keycloak outputs the following logs bout AccessTokenContext

 accessTokenContext.getSessionType() = OFFLINE
 accessTokenContext.getGrantType() = na
 accessTokenContext.getRawTokenId() = d5daa054-015a-4869-9dc1-cccc6b04671b
 accessTokenContext.getTokenType() = REGULAR
2025-04-17 00:03:45,662 WARN [org.keycloak.events] (executor-thread-5) type="USER_INFO_REQUEST_ERROR", realmId="5b9ce58b-4b1d-42bd-a714-eca698e2157f", realmName="test", clientId="b967393f-a745-4efd-9cb9-91d733f41a58", userId="null", sessionId="59e8808b-bb1e-4171-9c57-ccae9cd6bc2a", ipAddress="17
8000
2.18.0.13", error="user_session_not_found", auth_method="validate_access_token"

(3) Due to this issue, Keycloak 26.2.0 cannot pass OpenID Foundation's OIDC conformance tests while all the earlier version of Keycload could pass.

Activity

  1. tnorimat commented on Apr 17, 2025

    @tnorimat
    ContributorAuthor

    @mposolda I am not sure, but does this issue relate to #37694 ?

  2. changed the title [-]UserInfo request fails by using an access token obtained in Hybrid flow[/-] [+]UserInfo request fails by using an access token obtained in Hybrid flow with offline_access scope[/+] on Apr 17, 2025
  3. self-assigned this
    on Apr 24, 2025
  4. mposolda commented on Apr 24, 2025

    @mposolda
    Contributor

    @tnorimat Thanks for reporting this! Yes #37694 is related.

    I've sent PR to fix this. Review is welcome! See PR description for the details.

  5. tnorimat commented on Apr 25, 2025

    @tnorimat
    ContributorAuthor

    @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.

  6. added a commit that references this issue on Apr 25, 2025
    54e1c8a
  7. added a commit that references this issue on Apr 25, 2025
    1b84158
  8. added a commit that references this issue on Apr 30, 2025
    c830a27
  9. stempler commented on Jan 27, 2026

    @stempler

    @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.

    @tnorimat What were the results of your tests?

    I'm still seeing this issue (tested with 26.2.0, 26.3.0 and 26.5.2). The problem does not occur if I remove offline_access from the scope or use version 26.1.3.

    Difference might be that in my case the original token is created in an "implicit" flow.

  10. ahus1 commented on Jan 29, 2026

    @ahus1
    Member

    @stempler - this issue has been closed for some time. If you still see this occurring, please open a new bug with your results against 26.5.2

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

Metadata

Metadata

Assignees

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    0