Repository navigation
AI Agent acting on behalf of a user: tokens can’t be refreshed after the user logs out #53875
|
I have the following setup:
ProblemIf the user logs out mid-run, the agent’s refresh fails because its token belongs to the user’s session, and the run fails. Constraints: the agent must act as the user (not a service account), with no extra login or consent screen. What we’ve considered
Questions
|
Replies: 2 comments
|
With what Keycloak ships today, option 4 is the way to go. Standard token exchange won't give you an offline or long-lived token, and that's by design. In V2 the refresh setting only has two values, For option 4, a few things matter:
The tradeoff is that logout no longer stops the agent, so decide explicitly whether logging out should cancel running jobs. If you want token exchange to cover this natively, I'd open a feature request referencing #37115. |
|
Thanks for the quick reply! |
With what Keycloak ships today, option 4 is the way to go. Standard token exchange won't give you an offline or long-lived token, and that's by design.
In V2 the refresh setting only has two values,
NOandSAME_SESSION. If the subject token comes from an offline (or transient) session, asking forrequested_token_type=refresh_tokenfails with "creating a new session is needed". An access-token exchange is then served from a transient session, which is why option 2 gives you no refresh token.offline_accessis also rejected explicitly. This was a deliberate choice when V2 was designed: in #37115 minting offline tokens through exchange was considered too powerful, with a note to revisit if p…