Secure OAuth patterns for Snowflake Cortex AI through Amazon Bedrock AgentCore Amazon Bedrock AgentCore Identity now supports three tested OAuth configurations for AI agents calling the Snowflake-managed MCP server through the Model Context Protocol: Snowflake OAuth with per-user authentication and no external identity provider, three-legged OAuth through a third-party identity provider using corporate single sign-on, and two-legged OAuth with a shared service user via the client_credentials grant. Amazon Bedrock AgentCore Identity also supports an on-behalf-of (OBO) grant (TOKEN_EXCHANGE) that delivers per-user identity for unattended workloads without a consent prompt, and it acts as the credential broker, owning the token vault, refresh, and user-to-token binding while the AgentCore Gateway aggregates MCP targets into a single tools/list catalog. Artificial Intelligence https://aws.amazon.com/blogs/machine-learning/ Secure OAuth patterns for Snowflake Cortex AI through Amazon Bedrock AgentCore Enterprises today need a clear way to extend their authentication and authorization controls into the agentic layer, often requiring either broad service account permissions or custom-built auth integrations that add operational overhead. When an AI agent running on Amazon Bedrock AgentCore https://aws.amazon.com/bedrock/agentcore/ a platform to build, connect, and optimize agents at scale, with any framework or model needs to call the Snowflake-managed MCP server https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-agents-mcp which exposes Snowflake Cortex Agents https://docs.snowflake.com/en/user-guide/snowflake-cortex/cortex-agents as one of its tool types through the Model Context Protocol https://modelcontextprotocol.io/ MCP , the first question enterprises must answer is: how does the agent authenticate? In this post, we walk through three Open Authorization OAuth configurations we tested on Amazon Bedrock AgentCore Identity https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/identity.html , a capability of Amazon Bedrock AgentCore: Snowflake OAuth per-user, no external Identity Provider, or IdP , three-legged OAuth with a third-party Identity Provider corporate single sign-on, or SSO , and two-legged OAuth with a third-party Identity Provider shared service user . Amazon Bedrock AgentCore Identity also supports an on-behalf-of OBO grant TOKEN EXCHANGE that delivers per-user identity for unattended workloads without a consent prompt. We focus on the three configurations we tested end-to-end, flagging where OBO fits as we go. By the end, you will be able to identify which pattern suits your enterprise scenario. Solution overview Amazon Bedrock AgentCore Gateway https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway.html , a capability of Amazon Bedrock AgentCore, connects AI agents to external tool providers through MCP server targets. It targets the Snowflake-managed MCP server, which surfaces Cortex Search and Cortex Analyst as MCP tools that an MCP-aware client can discover and invoke. Rather than acting as a wrapper, the Gateway aggregates the capabilities of its configured targets into a single unified catalog, which it presents to the agent as one tools/list response. The core focus of this post is the outbound authentication https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-outbound-auth.html for Amazon Bedrock AgentCore Gateway: how it obtains and presents OAuth tokens to the Snowflake-managed MCP server. Amazon Bedrock AgentCore Identity acts as the credential broker: the Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT because the Gateway uses JSON Web Token JWT inbound authentication , then calls GetResourceOauth2Token against the configured provider. AgentCore Identity owns the token vault, the token refresh, and the user-to-token binding, and it fetches, caches, and refreshes tokens automatically. Amazon Bedrock AgentCore Identity supports three OAuth configurations spanning two grant types authorization code and client credentials : 1. Snowflake OAuth https://docs.snowflake.com/en/user-guide/oauth-snowflake-overview : Snowflake acts as its own OAuth authorization server. Each user authenticates directly to Snowflake through the Authorization Code grant 3LO . No external identity provider is needed. 2. Three-legged OAuth using a third-party Identity Provider: Users authenticate through corporate SSO with the Authorization Code grant. Snowflake trusts IdP-issued JSON Web Tokens JWTs through its External OAuth https://docs.snowflake.com/en/user-guide/oauth-ext-overview security integration. 3. Two-legged OAuth pattern using a third-party IdP: A shared service user authenticates through the client credentials grant of the IdP. No user interaction or consent is required, which is ideal for machine-to-machine workloads. Amazon Bedrock AgentCore Identity also offers an API-key credential provider which supports Snowflake Programmatic Access Tokens . We focus on OAuth here for per-user attribution and automatic token refresh. Each configuration uses a credential provider in Amazon Bedrock AgentCore Identity CustomOauth2, OktaOauth2, or MicrosoftOauth2 and a corresponding security integration on the Snowflake side. Note: We tested these patterns with the Snowflake-managed MCP server using Okta and Microsoft Entra ID. Patterns 2 and 3 external IdP follow standard OAuth flows, so they can extend to other OAuth-protected MCP servers, but validate the token claims, scopes, and audience settings for your SaaS provider. Only Pattern 1 is Snowflake-specific, because it relies on Snowflake’s built-in OAuth authorization server. The Snowflake-specific elements are the OAUTH AUTHORIZATION SERVER issuer-lock parameter, the session:role: / session:scope: grammar, BLOCKED ROLES LIST, LOGIN NAME / EMAIL ADDRESS mapping, and QUERY HISTORY attribution. If your SaaS exposes its own internal OAuth server, you configure outbound OAuth the same way as Snowflake OAuth. | Pattern | OAuth grant | AgentCore Identity credential provider vendor | Snowflake security integration | Snowflake query identity mapping | | Snowflake OAuth – 3LO | authorization code | Custom provider CustomOauth2 | TYPE = OAUTH, OAUTH CLIENT = CUSTOM | The real user, with their assigned role | | 3LO with external IdP | authorization code | Built-in provider such as OktaOauth2, MicrosoftOauth2 | TYPE = EXTERNAL OAUTH + OAUTH AUTHORIZATION SERVER set with ALTER ACCOUNT / DATABASE / SCHEMA ; EXTERNAL OAUTH TYPE = OKTA / AZURE / PING FEDERATE / CUSTOM | The real user, with their assigned role | | 2LO with external IdP | client credentials | Built-in provider such as OktaOauth2, MicrosoftOauth2 or CustomOauth2 | TYPE = EXTERNAL OAUTH + OAUTH AUTHORIZATION SERVER set with ALTER ACCOUNT / DATABASE / SCHEMA ; EXTERNAL OAUTH TYPE = OKTA / AZURE / PING FEDERATE / CUSTOM | A shared Snowflake service user | Notes: - 2LO does not require a built-in vendor. CustomOauth2 with the CLIENT CREDENTIALS grant can work with your choice of OAuth 2.0 authorization server. - When Amazon Bedrock AgentCore Gateway brokers the token the pattern in this post , Snowflake validates it through the TYPE = EXTERNAL OAUTH security integration. Setting OAUTH AUTHORIZATION SERVER with ALTER ACCOUNT, DATABASE, or SCHEMA is what lets direct MCP clients auto-discover your IdP through the Protected Resource Metadata endpoint, and it issuer-locks the MCP endpoint to that integration. - If you set OAUTH AUTHORIZATION SERVER to issuer-lock an MCP scope to an external IdP Pattern 2 , Snowflake OAuth tokens Pattern 1 are rejected for MCP servers in that scope and do not fall back. If you need both patterns in one account, set this parameter per schema or database so each scope resolves to the right authorization server. Solution architecture The following diagram shows the solution we built and the components it uses: a user-facing AI application, a Strands agent https://strandsagents.com/ on Amazon Bedrock AgentCore Runtime https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agents-tools-runtime.html , a capability of Amazon Bedrock AgentCore, Amazon Bedrock https://aws.amazon.com/bedrock/ for reasoning, with Amazon Bedrock Guardrails https://aws.amazon.com/bedrock/guardrails/ redacting personally identifiable information PII from prompts and responses, Amazon Bedrock Knowledge Bases https://aws.amazon.com/bedrock/knowledge-bases/ , the fully managed Retrieval Augmented Generation RAG capability, over policy documents in Amazon Simple Storage Service Amazon S3 https://aws.amazon.com/s3/ , Amazon Bedrock AgentCore Gateway with the Snowflake-managed MCP server as its target, and Amazon Bedrock AgentCore Identity holding the token vault. The outbound OAuth path has the same shape in all three patterns: the Gateway resolves a token through AgentCore Identity, which obtains and renews it from an authorization server, and the Gateway then presents that token to the Snowflake-managed MCP server. What changes between the patterns is which authorization server issues the token and under which grant: Snowflake’s own built-in OAuth server, or a third-party IdP. Those differences are set out in the Pattern comparison table, and each pattern’s runtime flow has its own sequence diagram later in this post. Pattern analysis The following sections examine each pattern in detail: the authentication flow, configuration steps, and trade-offs to help you select the right approach for your use case. Pattern 1: Snowflake OAuth three-legged The Snowflake OAuth pattern uses a three-legged OAuth 3LO flow to deliver per-user authentication without requiring an external identity provider. Each user authenticates to Snowflake with their own credentials, consents to a specific Snowflake role, and Amazon Bedrock AgentCore Identity caches that user’s access and refresh tokens. Every subsequent Snowflake call executes as that user, and QUERY HISTORY records their real username. Note that per-role consent is not the default. The Snowflake-managed MCP server advertises session:role:all and falls back to DEFAULT ROLE, so you set OAUTH SCOPES SUPPORTED an account-, database-, or schema-level parameter set with ALTER to narrow the role scope the server advertises, and restrict ALLOWED ROLES LIST on the integration to enforce which roles a user can consent to PRE AUTHORIZED ROLES LIST does the opposite: it lists roles that skip the consent step . What makes this pattern appealing is its simplicity: no external identity provider is required. Snowflake acts as both the authorization server and the resource server, exposing its own built-in OAuth endpoints /oauth/authorize and /oauth/token-request . Setup follows a specific order, because the callback URL does not exist until the credential provider is created. The administrator first creates the CustomOauth2 credential provider in Amazon Bedrock AgentCore Identity with placeholder client credentials and records the callbackUrl that AgentCore Identity returns. That callbackUrl is then registered as the redirect URI on a Snowflake security integration created with TYPE = OAUTH and OAUTH CLIENT = CUSTOM. Finally, the administrator updates the credential provider with the real client ID and secret issued by Snowflake and configures the provider’s oauthDiscovery with explicit authorization server metadata: the issuer the Snowflake account URL , the authorization endpoint /oauth/authorize , and the token endpoint /oauth/token-request . The following screenshot shows the configuration steps for credential provider vendors in Amazon Bedrock AgentCore Identity with Snowflake OAuth 3LO settings. Next, the Amazon Bedrock AgentCore Gateway configuration points to the Snowflake-managed MCP server endpoint and references the custom Snowflake OAuth for outbound authentication. The following sequence diagram shows the runtime authorization flow for the Snowflake OAuth pattern. The Snowflake OAuth authorization flow https://docs.snowflake.com/en/user-guide/oauth-snowflake-overview snowflake-oauth-authorization-flow works as follows: 1. When a tool call requires a Snowflake token, Amazon Bedrock AgentCore Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT and calls GetResourceOauth2Token to check the token vault of Amazon Bedrock AgentCore Identity for the user. If no token is cached, the Gateway returns a JSON-RPC error code -32042 https://aws.amazon.com/blogs/machine-learning/connecting-mcp-servers-to-amazon-bedrock-agentcore-gateway-using-authorization-code-flow/ carrying a URL elicitation. That authorization URL belongs to AgentCore Identity and is session-URI-bound . The client opens that URL in the user’s browser, which is routed to Snowflake’s bu