User identity Propagation in Agentic Workflows: Amazon Quick + AgentCore Gateway + OBO Token Exchange
Learn how to implement single sign-in with identity preservation across multiple MCP servers using Amazon Bedrock AgentCore Gateway, AgentCore Identity, and RFC 8693 On-Behalf-Of token exchange.
The Identity Problem in Multi-Tool Agentic Systems
When an AI agent serves users through multiple backend MCP servers, identity management becomes a critical challenge. Users should sign in once and have their identity flow transparently to every downstream service — with scoped-down permissions at each hop.
Consider an enterprise document processing system:
- Server A handles identity and access control
- Server B performs document OCR and analysis
- Server C manages regulatory search
Without a unified identity approach, each server requires its own authentication — resulting in multiple sign-in prompts, broad privilege tokens, and no audit trail showing which user triggered which tool call.
This article demonstrates a production-ready pattern that solves all three problems using Amazon Quick Suite as the MCP client, AgentCore Gateway as the central routing and security boundary, and AgentCore Identity performing RFC 8693 On-Behalf-Of token exchange.
What You Will Build
A system where:
- A user signs in once through an OAuth identity provider
- AgentCore Gateway validates the inbound JWT
- AgentCore Identity performs an RFC 8693 token exchange — producing a scoped-down token that preserves the user's identity (
subclaim)
- Each MCP server receives a token bound to a specific audience with minimum required scopes
- Multiple MCP servers sit behind a single Gateway endpoint — one connector, one sign-in
AWS AgentCore Platform — MCP Authentication Flow

How the Token Flows

Token Transformation
The key security property of this architecture: the user's identity is preserved while the token's scope and audience are narrowed at each boundary.
Claim | Inbound Token (from user) | OBO Token (to MCP server) |
|---|---|---|
iss | Provider auth server | Tenant auth server |
aud | my-gateway | https://api.my-service.example |
sub | alice@company.com | alice@company.com ✅ PRESERVED |
scp | gateway/invoke | data/read data/write (scoped down) |
cid | User app (login client) | Delegate app (agent identity) |
The downstream MCP server receives a token that:
- Identifies who is calling (alice, not "the gateway")
- Is bound to one specific service (audience)
- Carries minimum permissions (scoped scopes)
- Records who performed the exchange (delegate = agent identity, for audit)
Prerequisites
- AWS account with Amazon Quick Suite Enterprise and AgentCore enabled
- An OAuth 2.0 identity provider that supports RFC 8693 token exchange (Okta, Microsoft Entra ID, or similar)
- At least one MCP server deployed (on AgentCore Runtime or ECS Fargate)
- Basic understanding of OAuth 2.0, JWT, and MCP protocol
Step 1: Configure Your Identity Provider
You need two authorization servers (or one with two roles):
Provider Authorization Server — where users sign in:
- Audience:
my-gateway(identifies the Gateway as the intended recipient)
- Scopes:
openid email gateway/invoke
Tenant Authorization Server — performs the OBO exchange:
- Audience:
https://api.my-service.example(identifies the downstream MCP server)
- Scopes:
data/read data/write(the permissions the MCP server needs)
- Trusted Servers: Must trust the Provider auth server (so it accepts Provider-issued JWTs as subject tokens)
Delegate Application (service/API app):
- Grant types: Client Credentials + Token Exchange
- Used by AgentCore Identity to authenticate the exchange request
- DPoP: Disabled (AgentCore cannot provide DPoP proof)
User Application (OIDC web app):
- Grant types: Authorization Code
- Redirect URI: Amazon Quick's OAuth callback URL
- This is what Quick uses to sign users in
Step 2: Create the AgentCore Gateway
Create a Gateway with JWT-based inbound authentication pointing at your Provider auth server:
import boto3
client = boto3.client('bedrock-agentcore-control', region_name='us-east-1')
gateway = client.create_gateway( name='my-obo-gateway', roleArn='arn:aws:iam::<ACCOUNT_ID>:role/my-gateway-role', protocolType='MCP', protocolConfiguration={'mcp': {'supportedVersions': ['2025-03-26']}}, authorizerType='CUSTOM_JWT', authorizerConfiguration={ 'customJWTAuthorizer': { 'discoveryUrl': 'https://<your-idp>/oauth2/<provider-server-id>/.well-known/openid-configuration', 'allowedAudience': ['my-gateway'] } })
gateway_id = gateway['gatewayId']print(f"Gateway: {gateway_id} — {gateway['status']}")The Gateway validates every inbound request's JWT against the Provider's public keys (JWKS). Invalid, expired, or wrong-audience tokens are rejected with 401 before reaching any MCP server.
Step 3: Create the OAuth2 Credential Provider (OBO)
This tells AgentCore Identity how to perform the RFC 8693 exchange:
provider = client.create_oauth2_credential_provider( name='my-obo-provider', credentialProviderVendor='CustomOauth2', oauth2ProviderConfigInput={ 'customOauth2ProviderConfig': { 'oauthDiscovery': { 'discoveryUrl': 'https://<your-idp>/oauth2/<tenant-server-id>/.well-known/openid-configuration' }, 'clientId': '<delegate-app-client-id>', 'clientSecret': '<delegate-app-client-secret>', 'clientAuthenticationMethod': 'CLIENT_SECRET_POST', 'onBehalfOfTokenExchangeConfig': { 'grantType': 'TOKEN_EXCHANGE', 'tokenExchangeGrantTypeConfig': { 'actorTokenContent': 'NONE' } } } })
provider_arn = provider['credentialProviderArn']print(f"Credential Provider: {provider_arn}")Key settings:
-
grantType: TOKEN_EXCHANGE— tells Identity to use RFC 8693
-
actorTokenContent: NONE— the delegate authenticates with client credentials alone (no separate actor token)
- The client secret is stored encrypted in AWS Secrets Manager automatically
Step 4: Create the Gateway Target (MCP Server)
This is where the magic happens — combining the MCP server target with the OBO credential provider:
target = client.create_gateway_target( gatewayIdentifier=gateway_id, name='my-mcp-server', targetConfiguration={ 'mcp': { 'mcpServer': { 'endpoint': '<your-mcp-server-url>' } } }, credentialProviderConfigurations=[{ 'credentialProviderType': 'OAUTH', 'credentialProvider': { 'oauthCredentialProvider': { 'providerArn': provider_arn, 'scopes': ['data/read', 'data/write'], 'grantType': 'TOKEN_EXCHANGE', 'customParameters': { 'audience': 'https://api.my-service.example', 'subject_token_type': 'urn:ietf:params:oauth:token-type:access_token' } } } }])
print(f"Target: {target['targetId']} — {target['status']}")The critical fields on the target:
-
grantType: 'TOKEN_EXCHANGE'— tells the Gateway to perform OBO (not client_credentials) on tool invocation
-
customParameters.audience— binds the OBO token to this specific downstream API
-
customParameters.subject_token_type— tells the IDP the subject token is an access_token
When a user calls a tool, the Gateway:
- Takes the user's inbound JWT (validated in Step 2)
- Passes it to AgentCore Identity as the
subject_token
- Identity calls the Tenant auth server with RFC 8693
- Receives a scoped OBO token (sub=user preserved, aud+scp rewritten)
- Sends the OBO token as
Authorization: Bearerto the MCP server
Step 5: Configure the MCP Server to Accept OBO Tokens
Your MCP server needs to validate the OBO token. Since the token is issued by the Tenant auth server (not the Provider), configure accordingly.
If MCP server is on AgentCore Runtime:
client.update_agent_runtime( agentRuntimeId='<runtime-id>', authorizerConfiguration={ 'customJWTAuthorizer': { 'discoveryUrl': 'https://<your-idp>/oauth2/<tenant-server-id>/.well-known/openid-configuration', 'allowedAudience': ['https://api.my-service.example'] } })If MCP server is on ECS Fargate behind ALB:
- Configure an ALB JWT authorizer (or validate in application code)
- Validate against the Tenant auth server's JWKS
- Check
aud=https://api.my-service.example
In both cases, the MCP server reads the user identity from the decoded JWT claims:
# Inside your MCP tool functionclaims = decode_jwt(authorization_header)user = claims['sub'] # alice@company.comscopes = claims['scp'] # ['data/read', 'data/write']audience = claims['aud'] # https://api.my-service.example
Step 6: Connect Amazon Quick Suite
Create a single MCP connector in Quick pointing at the Gateway:
Field | Value |
|---|---|
MCP Server URL | https://<gateway-id>.gateway.bedrock-agentcore.<region>.amazonaws.com/mcp |
Auth type | User authentication (3LO) |
Authorization URL | https://<your-idp>/oauth2/<provider-server-id>/v1/authorize |
Token URL | https://<your-idp>/oauth2/<provider-server-id>/v1/token |
Client ID | Your user app's client ID |
Scope | openid email gateway/invoke |
After connecting, Quick discovers all tools from all targets behind the Gateway. Users sign in once — the token exchange happens transparently on every tool call.
Adding Multiple MCP Servers
The power of this architecture: add more targets to the same Gateway, each with its own credential provider (or sharing one). Users never see multiple sign-ins:
# Second MCP server — same Gateway, same sign-inclient.create_gateway_target( gatewayIdentifier=gateway_id, name='my-second-server', targetConfiguration={ 'mcp': {'mcpServer': {'endpoint': '<second-server-url>'}} }, credentialProviderConfigurations=[{ 'credentialProviderType': 'OAUTH', 'credentialProvider': { 'oauthCredentialProvider': { 'providerArn': provider_arn, # Same or different provider 'scopes': ['search/read'], 'grantType': 'TOKEN_EXCHANGE', 'customParameters': { 'audience': 'https://api.search-service.example', 'subject_token_type': 'urn:ietf:params:oauth:token-type:access_token' } } } }])Each target can have different scopes and audiences — the user's identity propagates to all, with minimum permissions per target.
What AgentCore Identity Provides
Capability | What it does for you |
|---|---|
Credential Provider | Stores delegate app credentials in Secrets Manager; knows the IDP's discovery URL and exchange configuration |
Token Vault | Caches OBO tokens per user — repeat tool calls don't re-exchange |
Auto-Refresh | Refreshes tokens before expiry — users are never prompted again mid-session |
Workload Identity | The Gateway's own identity (for audit: "which agent performed the exchange") |
You write zero token management code. The Gateway and Identity handle the full lifecycle.
Security Properties
Property | How it's enforced |
|---|---|
User identity preserved | sub claim passes through the exchange unchanged |
Least privilege | Each MCP server gets a token with only its required scopes |
Audience binding | Token's aud is bound to one specific service — can't be reused elsewhere |
No impersonation | Original JWT never reaches the MCP server — only the scoped exchange result does |
Audit trail | cid claim records the delegate (agent), sub records the user |
No credential exposure | Delegate secrets stored in Secrets Manager, never in code or logs |
What We Tried That Didn't Work (And Why)
❌ Attempt 1: Gateway Interceptor to Inject Token via Custom Headers
The idea: Use a REQUEST interceptor Lambda to extract the user's JWT and inject it as a custom header (
x-user-sub , x-user-groups ) for the downstream MCP server.Why it failed: AgentCore Gateway strips all custom headers before forwarding to MCP server targets. The interceptor can modify headers in its response, but the Gateway doesn't pass them through to
mcpServer targets. Only standard headers survive.Lesson: Don't rely on custom header propagation to MCP server targets. Headers injected by interceptors are NOT forwarded to the downstream.
❌ Attempt 2: Interceptor Modifying the MCP Request Body
The idea: If headers don't work, inject identity into the MCP JSON-RPC body (
body.params.arguments ) from the interceptor.Why it partially worked: This actually DOES work for MCP protocol gateways — the interceptor can modify the request body and it reaches the MCP server. We used this as an interim solution. But it's a workaround, not the intended pattern.
Lesson: Injecting into tool arguments works but is fragile — every tool needs to accept an extra
authorization argument, and it's not how the platform was designed to propagate identity.
❌ Attempt 3: OAuth Credential Provider with GATEWAY_IAM_ROLE Target
The idea: Use the OBO credential provider on the target, but keep
GATEWAY_IAM_ROLE for the actual connection to the Runtime.Why it failed:
GATEWAY_IAM_ROLE means the Gateway authenticates to the Runtime using IAM SigV4, not an OAuth token. The OBO token was never sent. The MCP server received the request via IAM with no user identity.Lesson:
GATEWAY_IAM_ROLE and OAUTH credential providers are mutually exclusive on a target. If you want the OBO token to reach the MCP server, the target must use OAUTH as its credential provider type — which means the Runtime must have JWT auth configured to accept the OBO token.
❌ Attempt 4: HTTP Target (no protocol type) with OBO
The idea: Create a Gateway without
protocolType: MCP (HTTP target type) and use the OBO credential provider to send the token as Bearer.Why it partially worked: The target was created successfully and reached READY status. However, during tool invocation, the Gateway performed a
client_credentials call (delegate identity only) instead of passing the user's token as subject_token . The returned sub was the delegate app, not alice.Why: On HTTP targets, the Gateway's native OBO exchange requires the inbound token to be from a trusted issuer. At the time we tested this, our inbound auth was still Cognito (not Okta Provider). Once we switched inbound to Okta Provider (trusted by the Tenant), this path might work — but we moved to the simpler MCP target approach instead.
Lesson: The
grantType: TOKEN_EXCHANGE on a target's credential provider only performs actual OBO (with user identity) if the inbound JWT issuer is trusted by the exchange authorization server. Otherwise it silently falls back to client_credentials .
❌ Attempt 5: AgentCore Identity APIs from Interceptor Lambda (GetWorkloadAccessTokenForJWT)
The idea: Have the interceptor Lambda assume the Gateway's IAM role and call
GetWorkloadAccessTokenForJWT + GetResourceOauth2Token to perform the exchange via AgentCore Identity's official APIs.Why it failed: Error:
"WorkloadIdentity is linked to a service and cannot retrieve an access token by the caller." Even after assuming the Gateway's IAM role via
sts:AssumeRole , AgentCore Identity still rejected the call. The workload identity is bound to the Gateway's internal service principal — not just its IAM role. External callers (including Lambdas assuming the same role) cannot use it.Lesson:
GetWorkloadAccessTokenForJWT can only be called from WITHIN the service that owns the workload identity (the Gateway itself or a Runtime's own code). Lambda interceptors cannot use this API path. The native target-level credential provider is the correct approach.
❌ Attempt 6: FastMCP with JWTVerifier (Token Validation Inside the MCP Server)
The idea: Use the standalone
fastmcp package with its built-in JWTVerifier auth provider to validate the OBO token inside the MCP server container.Why it failed: AgentCore Runtime sends internal health check pings (
PingRequest ) to the MCP server's /mcp endpoint without a Bearer token. The JWTVerifier rejected these with 401, causing the container to be marked unhealthy and restart in a loop.Lesson: Don't add application-level JWT validation inside an MCP server running on AgentCore Runtime. The Runtime's platform-level JWT authorizer handles validation before requests reach your container. Your server code just needs to decode the token (without re-validating the signature) — it's already been validated upstream.
✅ What Finally Worked: MCP Target + TOKEN_EXCHANGE Credential Provider + Runtime JWT Auth
The winning combination:
- Gateway:
protocolType: MCP, inbound CUSTOM_JWT pointing at Okta Provider
- Target:
credentialProviderType: OAUTHwithgrantType: TOKEN_EXCHANGE+customParameters(audience + subject_token_type)
- Runtime:
customJWTAuthorizerpointing at Okta Tenant (the issuer of the OBO token)
The Gateway handles everything natively — no interceptor, no custom code. AgentCore Identity performs the exchange, caches in the Token Vault, and auto-refreshes.
Key Learnings & Gotchas
- The target's
grantTypemust beTOKEN_EXCHANGE— Without this, the Gateway defaults toclient_credentialsand loses user identity. This is the single most important configuration.
-
customParametersare required — You must setaudienceandsubject_token_typeon the target. Without them, the IDP can't produce a correctly scoped token.
- Trusted Servers (IDP-specific) — The Tenant auth server must trust the Provider auth server. In Okta, this is configured under Security → API → Tenant → Trusted Servers. Without it, the exchange fails with "invalid subject_token."
- DPoP must be disabled — AgentCore Identity is a token relay and cannot provide Demonstrating Proof-of-Possession headers. Disable DPoP on your delegate and user apps.
- MCP server must validate against the Tenant (not Provider) — The OBO token is issued by the Tenant auth server. If your MCP server validates against the Provider's JWKS, it will reject the token (wrong issuer).
- Discovery uses client_credentials (by design) — During
tools/list(tool discovery), there's no user. The Gateway uses client_credentials to discover tools. This is expected — OBO only kicks in ontools/call(when a user is present).
- Works for any MCP server hosting — The same pattern applies whether the MCP server runs on AgentCore Runtime, ECS Fargate, Lambda, or any HTTPS endpoint. The server just needs to accept and validate a Bearer token.
For Production Deployments
For enterprise/regulated environments, also consider:
- Customer-managed KMS key on the Token Vault for key ownership compliance
- Private networking via Quick VPC Connection (avoid public internet for token exchange)
- Token lifetimes — issue short-lived OBO tokens (5-15 min) to minimize replay window
- Scope reduction per role — use IDP claim expressions to return different scopes based on user group membership
- CloudTrail monitoring — track
InvokeAgentRuntimecalls with user context for full audit
Conclusion
The combination of Amazon Quick Suite, AgentCore Gateway, and AgentCore Identity with RFC 8693 token exchange provides a complete solution for identity propagation in multi-tool agentic systems. Users authenticate once; their identity flows securely to every downstream service with scoped-down permissions and full audit trail — regardless of where those services are hosted.
The key insight: configure the Gateway target's credential provider with
grantType: TOKEN_EXCHANGE and the appropriate customParameters . AgentCore Identity handles the rest — exchange, caching, refresh — with zero custom code.
Resources
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article