The persistent headache of agent identity has a new, albeit previewed, solution. Keycloak 26.8 has introduced token exchange delegation, a mechanism allowing AI agents to act on behalf of users without stealing their full identity or requiring overly broad service accounts. Tested on Keycloak 26.8.2 and oauth2c 1.21.1, this feature addresses the core security flaw in current agent architectures: the ambiguity of who is actually making the request.

The Identity Crisis of Current Agents

Standard practice has long been a binary choice between two bad options. Handing an agent the user’s own access token results in 'token passthrough,' where every backend service sees the user as the actor, destroying the audit trail. Conversely, giving an agent a service account with broad read permissions creates a 'helpful insider' vulnerability, where a single prompt injection can exfiltrate data across the entire user base. Neither option satisfies the principle of least privilege or proper attribution.

How Delegation Works Under the Hood

Keycloak’s implementation builds on RFC 8693, distinguishing between impersonation and delegation. In delegation, the token’s sub claim remains the user (e.g., Alice), but an act claim is added to identify the agent (e.g., agent-bot). This allows resource servers to log the agent’s involvement and enforce specific policies. The feature requires enabling two preview flags: token-exchange-delegation and parameterized-scopes. Crucially, the agent must be a confidential client with a service account, and the user-facing application must have consent required.

Implementation Nuances and Silent Failures

The setup is not trivial. As detailed in the demo by Anoop Gopi, a common pitfall is the 'silent drop.' If the Fine-Grained Admin Permissions (FGAP) are not correctly configured to allow the agent to delegate for the user, Keycloak will strip the delegation scope from the token without throwing an error. The agent then proceeds with a token that lacks the may_act claim, leading to unexpected behavior downstream. Proper configuration involves creating a client policy for the agent and a scope permission for delegation on the Users resource.

Limitations of the Preview Feature

This is a preview feature, and its constraints are significant. The delegated token is short-lived, inheriting the expiration of the user’s original token (defaulting to five minutes), and it cannot be refreshed. It does not grant Admin API access, even if the agent has a service account. Furthermore, the system currently supports only single-hop delegation; an agent cannot pass its delegated token to another agent. The consent screen is also broad, lacking specific data scope or duration controls, which remains a UX and security gap.

Key Takeaways

  • Keycloak 26.8 introduces preview token exchange delegation to solve agent identity attribution.
  • The feature uses RFC 8693 standards, adding an act claim to tokens while preserving the user's sub.
  • Misconfiguration of Fine-Grained Admin Permissions leads to silent scope drops, a major debugging trap.
  • Delegated tokens are short-lived, non-refreshable, and currently limited to single-hop agent chains.
  • The feature is in preview, meaning APIs and behaviors may change before full support.

The Bottom Line

Token exchange delegation is a necessary step toward secure agent ecosystems, but its preview status and silent failure modes demand rigorous testing. Until multi-hop support and granular consent controls arrive, treat this as a powerful debugging tool rather than a production-ready security boundary.