﻿# AI backend token exchange: preserve the subject and current actor

Choose delegation or impersonation deliberately when an assistant calls another service. Verify the current actor, target resource and scope at the backend.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/enterprise-ai-token-exchange-subject-current-actor/
Language: en

## Preserve who is acting for whom

A case-management assistant receives a user's request and needs a document service to retrieve an attachment. The frontend and document service use different access contracts. Copying the incoming credential obscures whether the backend sees the user directly, the frontend acting for that user, or an unrelated service account. Decide which relationship the application intends before selecting a token exchange flow. The model's description of its role is not an authenticated actor identity.

## Distinguish impersonation from delegation

[RFC 8693](https://www.rfc-editor.org/rfc/rfc8693.html) describes token exchange and distinguishes impersonation, where an actor is treated as the subject within an authorized rights context, from delegation, where the actor retains a separate identity while representing the subject. Its subject_token and actor_token parameters provide inputs to the authorization server; whether a composite token is issued depends on policy. For this application, the design review should explicitly choose the intended relationship and explain how the document backend will recognize it. A successful exchange response alone cannot demonstrate that relationship.

## Request the actual downstream target

[RFC 8707](https://www.rfc-editor.org/rfc/rfc8707.html) provides resource indicators so a client can signal the protected resource for which it wants access. Recipient and operation scope solve different parts of the contract. In the case-management deployment, an allowlisted document-service target should come from application configuration, while requested scope should match the permitted attachment operation. A resource identifier supplied inside retrieved text must not choose where a credential is sent. Broad multi-resource credentials make later access evidence harder to interpret.

## Keep the exchange behind a trusted broker

The component performing exchange needs a clear relationship between authenticated user, authorized client, intended target and business operation. Retain those identifiers in a protected operation record. Do not expose raw subject or actor tokens to the model merely to help it select a tool. If the authorization server refuses the request, preserve that refusal as an exchange outcome. Falling back to a broadly privileged service token changes the authority of the operation and requires a separate, explicit application policy.

## Interpret actor history within its defined scope

For JWT composite tokens, RFC 8693 identifies the outer actor as current and nested actors as history. Prior actors are informational for access-control decisions; they do not supply extra permission by appearing in a chain. Therefore, keep backend authorization tied to the validated current relationship and top-level claims under the accepted profile. Historical participants can help explain a request's route. They should not turn an earlier administrative intermediary into an inherited permission grant for the assistant.

## Test the relationship at the receiving service

Prepare an authorized test user, a permitted frontend identity and a harmless attachment fixture. Verify the expected subject and current actor at the backend's validated identity boundary. Add an unauthorized actor, the wrong target and a narrower scope that excludes the requested operation. Observe whether denial occurs before document contents are returned. Separately record exchange failure and backend authorization failure. This proposed procedure validates identity interpretation and enforcement; it does not assert that a particular identity provider supports every profile or that these checks have been executed.

## Separate sign-in, exchange and business permission

[OAuth PKCE sign-in](/journal/learn-openrouter-oauth-pkce/) explains how an application obtains user-authorized access. The exchange step adapts credentials for a downstream relationship, while the backend still applies resource permission. [Client-history trust](/journal/guide-pydantic-ai-client-history-trust/) addresses another boundary: a conversation entry cannot establish approval or caller authority. A useful enterprise handoff record connects these stages through stable identifiers and observed outcomes, without flattening them into a single claim that the user was authenticated.
