Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rmartinc
Copy link
Contributor

Closes #37117

The PR avoids creating a real client session for TE when it is possible. If the client session is missing a new transient session is created and used (same notes than realm online session). The difference is that the sid claim in this case is set to the token (the session exists but the token is transient, there is no real client session for this client). This is only done if the TE requested type is not the refresh token which needs a persistent session.

@mposolda
Copy link
Contributor

mposolda commented Feb 28, 2025

@rmartinc Thanks! Nice approach.

Few concerns:

  • When I tested the PR and added setTimeOffset(1) to the StandardTokenExchangeV2Test line 251 (right before calling introspection endpoint), then the test failed. The introspection-endpoint fails due the userSession is created before token. Is it maybe that when creating "transient user session", it would also receive the startup time from the original session? Or startup time would be checked against the original persistent session?

  • Is it possible to also add the test check, which will logout the original session (or remove the session by admin REST API) and then checks that it is not possible to introspect the exhcnaged token anymore? IMO it will work with the current PR, but testing could be good.

  • Will this work when the exchanged token is used to call account/admin REST API? Or when newly exchanged token is used as subject_token for the further token exchange? Some automated test might be also good. I have some doubts as AFAIK those unfortunately use different methods to lookup/verify user sessions ( AuthenticationManager.verifyIdentityToken ). If you prefer, this can be addressed as a follow-up to this PR. BTW. I was thinking about some consolidation of this and make sure that various Keycloak endpoints use same code when lookup/validate user session, offline session etc, but refactoring is rather out of scope of this PR...

@rmartinc
Copy link
Contributor Author

rmartinc commented Mar 2, 2025

@mposolda Good catch! I didn't realize the started was set to current time when creating the transient session. I have worked in the three points:

  1. Done and modified the test to run the test with offset.
  2. Modified the test to delete the session and check it fails as expected.
  3. Added two more tests for admin/account API. I have not done with a token obtained by a first TE request (I have just seen it now) but I can add if you think it is important. I have just modified the AuthenticationManager to make it work with teh new transient tokens. Maybe we need to re-think this and use the same code in both parts. But I would do that in a follow-up.

Copy link
Contributor

@mposolda mposolda left a comment

Choose a reason for hiding this comment

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

@rmartinc Thanks for the updates!

@mposolda mposolda merged commit 5f3e44d into keycloak:main Mar 3, 2025
78 checks passed
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.

Can we avoid creating client-session for the case when access-token requested?

2 participants