In modern development workflows, developers increasingly rely on agentic coding assistants such as Kiro Integrated Development Environment (IDE) to interact with remote tools and services. However, organizations require robust authentication mechanisms to provide secure, identity-verified access between these agentic coding assistants and enterprise Model Context Protocol (MCP) servers.
Amazon Bedrock AgentCore is a fully managed service that helps you deploy, manage, and scale AI agents in production. One of its key components, the AgentCore Gateway, provides a centralized entry point for routing and securing agent-to-tool communications. When an AI assistant makes a request to an MCP server through the Gateway, that request must be verified before it’s processed. This is known as inbound authentication. Only authorized users and agents can access the tools and services exposed by the MCP server. Organizations typically manage user identities through an identity provider (IdP), such as Okta, Microsoft Entra ID, or Amazon Cognito, which authenticates users and issues security tokens that verify who they are.
This post demonstrates how to implement Open Authorization (OAuth) Code flow as an inbound authorization mechanism for MCP servers hosted on Amazon Bedrock AgentCore Gateway. By the end of this guide, you will have a production-ready setup where each AI assistant request is authenticated with a valid user identity token issued from your organization’s identity provider.
In an inbound authorization code flow OAuth setup, the AgentCore Gateway acts as an MCP resource server that requires a valid identity token before allowing AI clients to access any tools.
The following diagram shows the end-to-end architecture for the authorization code flow with AgentCore Gateway, including the identity provider, AI client, and MCP server interactions.

Figure 1: Authorization code flow architecture diagram.
The solution involves the following components working together to complete the authentication flow:
This flow makes sure that every request that the AI assistant sends to the MCP server is authenticated with a valid identity token belonging to the user.
www-authenticate header pointing to the Gateway’s OAuth Protected Resource Metadata endpoint (.well-known/oauth-protected-resource). This follows the MCP specification’s Protected Resource Metadata (PRM) pattern.https://{yourIdPDomain}/oauth2/default/.well-known/openid-configuration).openid profile email offline_access).Authorization header for all subsequent requests. The Gateway validates the token’s signature, expiration, issuer, and audience or custom claims, then proxies the request to the target MCP server for execution.
Figure 2: Authorization code flow request sequence.
The following table summarizes the required configuration for each component in the authorization code flow setup. Detailed step-by-step instructions follow in the Technical implementation section.
| Component | Required configuration | |
| 1 | Identity provider | Create an OpenID Connect (OIDC) web application with Authorization Code and Refresh Token grants enabled. |
| 2 | AgentCore Gateway | Set inbound authorization to JWT. Configure the discovery URL to your IdP’s issuer (for example, https://{yourIdPDomain}/oauth2/default/.well-known/openid-configuration). |
| 3 | Kiro IDE | Add the Gateway URL in Settings > Connectors (or through the CLI). The client automatically triggers the OAuth flow if the Gateway returns a 401 Unauthorized with the correct auth headers. |
With the architecture and flow established, configure each component. This section provides step-by-step instructions for the three components referenced in the configuration overview table:
You must have the following prerequisites in place to follow along.
In this step, you register an OIDC application with your organization’s identity provider and configure it to support the authorization code flow with PKCE.
Sign in to your IdP admin console and create a new OIDC/OAuth 2.0 application integration:
Enable the following grant types:
Add the callback URL that your AI client will use:
http://localhost:PORT/callback
Replace PORT with the port that your client uses.
In your IdP application settings, do the following.
Token lifetimes:
Save the following values. You will need them for Gateway configuration:
https://{yourIdPDomain}/oauth2/default).https://{yourIdPDomain}/oauth2/default/.well-known/openid-configuration).For this configuration:
With your identity provider configured, the next step is to connect AgentCore Gateway to your IdP so it can validate incoming tokens.
Configure your Gateway to use JWT-based authentication with your IdP’s discovery endpoint:
# Example Gateway configuration (adjust based on your deployment method)
aws agentcore update-gateway \
--gateway-id <your-gateway-id> \
--inbound-auth-type JWT \
--jwt-discovery-url "https://{yourIdPDomain}/oauth2/default/.well-known/openid-configuration" \
--region <your-region>
AgentCore Gateway validates JWT tokens based on standard OAuth 2.0 claims and supports custom claim validation to accommodate different IdP implementations. The Gateway expects tokens to contain:
iss (issuer), aud (audience), exp (expiration), iat (issued at), client_id (client identity), and scopes (allowed scopes).Other IdPs might use different claim names for client identification, scopes, and so on (for example, cid, azp, scp). You can configure custom claim validation in your Gateway to match your IdP’s token structure:
<claim-name> EQUALS <expected-value> (see AgentCore Gateway: Set up a JWT).cid EQUALS 0oaz7147z771FZmdQ697 (for IdPs that use cid, like Okta).Note: The Gateway’s Allowed audience field can be kept empty when using custom claim validation. The custom claim check provides the necessary client identity verification.
Now that the Gateway is configured with your IdP’s discovery URL and claim rules, look at how it validates incoming tokens at runtime.
AgentCore Gateway is designed to be agnostic to how the OAuth token was obtained by the user. The Gateway doesn’t distinguish between tokens acquired through the following:
The Gateway only requires that the OAuth token presented in the request is valid based on the parameters configured during Gateway setup:
iss claim): Matches the expected IdP issuer.iat, exp, and so on.Whether users obtain tokens through a client credentials flow, authorization code flow, or other OAuth grant type, the Gateway treats all tokens equally. As long as the token passes the validation checks configured in your Gateway setup, the request is authorized. With this flexibility, you can choose the authentication flow that fits your use case while maintaining consistent security at the Gateway level.
Test that your Gateway endpoint is accessible and requires authentication:
# Test authentication with an actual MCP request (POST without auth token)
curl -i -X POST https://<your-gateway-url>/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{},"id":1}'
The following response confirms that authentication is properly configured (a 401 response to unauthenticated MCP requests):
# Expected response showing authentication is required:
HTTP/2 401
www-authenticate: Bearer resource_metadata="https://<your-gateway-url>/.well-known/oauth-protected-resource"
{"jsonrpc":"2.0","id":0,"error":{"code":-32001,"message":"Missing Bearer token"}}
For the purpose of this post, use mcp-remote to standardize the MCP client interface and complete the authorization code flow.
Use mcp-remote to bridge Kiro IDE’s MCP client with the Gateway’s OAuth-protected endpoint.
Note: mcp-remote is a working proof-of-concept and should be considered experimental.
npm install -g mcp-remote
With the Gateway and MCP OAuth proxy configured, the final configuration step is connecting your AI client to the Gateway endpoint. Kiro IDE handles the OAuth flow automatically. When it receives a 401 challenge from the Gateway, it initiates the authorization code flow with your IdP.
Add the Gateway to your MCP configuration file at ~/.kiro/settings/mcp.json:
{
"mcpServers": {
"gateway-tools": {
"command": "mcp-remote",
"args": [
"https://<your-gateway-url>/mcp",
"<PORT>",
"--static-oauth-client-info",
"{\"client_id\": \"<your-idp-client-id>\", \"redirect_uris\": [\"http://localhost:<PORT>/oauth/callback\"], \"scope\": \"openid profile email offline_access\"}"
]
}
}
}
Configuration parameters:
command: Use mcp-remote to connect to remote MCP servers (mcp-remote)./mcp path.3334).--static-oauth-client-info: JSON string containing:
client_id: Your IdP application client ID.redirect_uris: Must match the port specified in the second arg.scope: Include openid profile email offline_access for basic auth.After adding the Gateway connection, verify that the authentication flow completes successfully:
After all components are configured and the initial authentication succeeds, verify that the full flow works end-to-end, from the AI client sending a tool request, through token validation at the Gateway, to receiving a response from the MCP server.
Monitor your Gateway logs to confirm token validation:
# Example log entry showing successful validation
[INFO] Token validated successfully for user: user@example.com
[INFO] Executing tool: list_files
For a step-by-step walkthrough using Okta as the IdP, see this GitHub repo.
If you followed along with this post and want to undo the resources you created, complete the following steps. They’re presented in reverse order of creation so that dependent resources are removed before the components they rely on.
Before removing any configuration, revoke any active tokens issued during testing. Consult your IdP’s documentation for the exact revocation endpoint URL and supported parameters.
curl -X POST "<your-idp-revocation-endpoint>" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "token=<your-refresh-token>&client_id=<your-client-id>"
Key considerations that vary by IdP:
revocation_endpoint field).client_id in the body. Confidential clients might require a Basic Authorization header with encoded credentials.You can also clear locally cached tokens by removing the mcp-remote auth cache. On macOS or Linux:
Remove the Gateway entry from your Kiro IDE MCP configuration at ~/.kiro/settings/mcp.json. Delete the gateway-tools server block you added in Step 4.
Uninstall the mcp-remote package you installed in Step 3:
npm uninstall -g mcp-remote
Remove the inbound authentication configuration you set up in Step 2, or delete the Gateway entirely if you created it solely for this walkthrough:
Option A: Remove inbound auth (keep the Gateway)
aws agentcore update-gateway \
--gateway-id <your-gateway-id> \
--inbound-auth-type NONE \
--region <your-region>
Option B: Delete the Gateway
aws agentcore delete-gateway \
--gateway-id <your-gateway-id> \
--region <your-region>
Delete the OIDC application integration you created in Step 1:
This revokes all client credentials and prevents any future token issuance for this application.
In this post, you learned how to implement secure, identity-verified access to MCP servers hosted on Amazon Bedrock AgentCore Gateway using inbound authorization code flow. With this setup, every AI assistant request is authenticated with a valid user token from your organization’s identity provider.