- Newest
- Most votes
- Most comments
Amazon Bedrock AgentCore provides two main authentication mechanisms: IAM SigV4 Authentication (default) and JWT bearer tokens with OAuth. For your scenario where you need to access an existing API that requires a user's bearer token, you have a few options:
- Configure JWT Inbound Authentication: You can set up AgentCore to accept JWT bearer tokens by configuring an authorizer during agent creation. This requires:
- A Discovery URL matching the OpenID Connect discovery pattern
- Allowed audiences matching the 'aud' claim in the token
- Allowed clients matching the 'client_id' claim
- Pass User Context: When making requests to your agent, include both the user's access token and user ID:
- Use the "Authorization: Bearer <user-access-token>" header
- Include the "X-Amzn-Bedrock-AgentCore-Runtime-User-Id: <user-id>" header
- Configure Outbound OAuth Access: For the USER_FEDERATION approach with Cognito, you need to properly configure the agent to use the token for outbound OAuth calls. This involves setting up the agent to forward the token to external services.
For machine-to-machine authentication with AgentCore Gateway using Cognito:
- Create a Cognito user pool and note the User Pool ID
- Create a resource server for the user pool
- Create a client for the user pool with appropriate OAuth flows and scopes
- Configure the Gateway Inbound Auth with the Discovery URL and Allowed Clients
You can also use Amazon Cognito's pre-token generation Lambda trigger to customize access tokens for your AI agent. This allows the agent to obtain its own access token while passing the user's access token as context using the aws_client_metadata request parameter. The customized token can then include user context that your API can validate.
This approach would allow your agent to act on behalf of users while maintaining proper authentication with your existing API.
Sources
Amazon Cognito - Amazon Bedrock AgentCore
Authenticate and authorize with Inbound Auth and Outbound Auth - Amazon Bedrock AgentCore
How to route pass through an access token in AWS Bedrock AgentCore? | AWS re:Post
Setting up inbound Auth - Amazon Bedrock AgentCore
Empower AI agents with user context using Amazon Cognito | AWS Security Blog
answered a year ago
