Secure OAuth patterns for Snowflake Cortex AI through Amazon Bedrock AgentCore

AWS published a walkthrough of three OAuth configurations it tested end-to-end for outbound authentication between Amazon Bedrock AgentCore Gateway and the Snowflake-managed MCP server, which exposes Snowflake Cortex Agents as one of its tool types alongside Cortex Search and Cortex Analyst. The patterns are Snowflake OAuth with no external identity provider, three-legged OAuth through a corporate IdP such as Okta or Microsoft Entra ID, and two-legged OAuth using a shared service user. AWS says it tested them with Okta and Microsoft Entra ID.
The architectural shape is the same across all three. AgentCore Gateway connects agents to external tool providers through MCP server targets and, rather than wrapping each target, aggregates their capabilities into one catalog returned as a single tools/list response. Because the Gateway uses JWT inbound authentication, it first obtains a workload token via GetWorkloadAccessTokenForJWT, then calls GetResourceOauth2Token against a configured credential provider. AgentCore Identity holds the token vault, handles user-to-token binding, and fetches, caches and refreshes tokens automatically. The Gateway then presents the token to Snowflake. What differs is which authorization server issues it and under which grant: Snowflake's built-in OAuth server or a third-party IdP, via authorization_code or client_credentials.
Pattern 1 uses a three-legged flow with Snowflake as both authorization server and resource server, exposing /oauth/authorize and /oauth/token-request. Users sign in with Snowflake credentials and consent to a specific role; QUERY_HISTORY then records their real username. Per-role consent is not automatic: the MCP server advertises session:role:all and falls back to DEFAULT_ROLE, so administrators set OAUTH_SCOPES_SUPPORTED to narrow the advertised role scope and ALLOWED_ROLES_LIST to enforce consentable roles, while PRE_AUTHORIZED_ROLES_LIST names roles that skip consent. Role names in scopes must be uppercase. Setup order matters because the callback URL only exists after the CustomOauth2 credential provider is created with placeholder credentials; that URL is registered as the redirect URI on a Snowflake integration with TYPE = OAUTH and OAUTH_CLIENT = CUSTOM, and the provider is then updated with the real client ID and secret plus explicit oauthDiscovery metadata.
At runtime, a missing cached token produces a JSON-RPC error -32042 carrying a session-URI-bound authorization URL. The code exchange completes only after the application calls CompleteResourceTokenAuth with the user identity and session URI, valid for 10 minutes, which binds the code to the originating request and blocks authorization-URL hijacking. The return URL is registered via UpdateWorkloadIdentity and in production is hosted by the web application or, for JWT-authenticated gateways, by the AgentCore Identity Consent Portal; the agentcore dev CLI hosts it only for local development.
Token lifetimes are concrete: access tokens default to 600 seconds with a 3600-second maximum, refreshed silently; refresh-token lifetime is set by OAUTH_REFRESH_TOKEN_VALIDITY, which the reference implementation sets to 86400 seconds, against a Snowflake ceiling of 90 days, with issuance governed by OAUTH_ISSUE_REFRESH_TOKENS. Consented scope controls only the primary role, so AWS recommends OAUTH_USE_SECONDARY_ROLES = NONE rather than IMPLICIT to prevent escalation. Snowflake blocks ACCOUNTADMIN, ORGADMIN, GLOBALORGADMIN and SECURITYADMIN by default through BLOCKED_ROLES_LIST, but that covers only the primary role.
Pattern 2 replaces the authorization server with the corporate IdP, giving SSO with MFA, conditional access and session policies while Snowflake stays the resource server. Snowflake validates IdP-issued JWTs through an External OAuth integration, checking issuer, audience and signature via JWKS, then maps a claim configured with EXTERNAL_OAUTH_TOKEN_USER_MAPPING_CLAIM (sub for Okta, upn for Entra ID) to a Snowflake LOGIN_NAME or EMAIL_ADDRESS and runs as that user. Integration parameter values are case-sensitive. AgentCore Identity supplies built-in provider vendors such as OktaOauth2 and MicrosoftOauth2 configured through includedOauth2ProviderConfig, and because the MCP server uses pre-registered OAuth clients, the same create, record callback, register, update sequence applies. Okta role scopes look like session:role:ANALYST_ROLE; Entra ID delegated flows use session:scope:.
Pattern 3 uses client_credentials with a shared service user, requiring no user interaction or consent, suited to machine-to-machine workloads. It can use a built-in vendor or CustomOauth2 with any OAuth 2.0 authorization server. The trade-off is attribution: queries resolve to one shared Snowflake user, so per-user audit trails are lost.
The most operationally important detail concerns OAUTH_AUTHORIZATION_SERVER, the issuer-lock set with ALTER ACCOUNT, DATABASE or SCHEMA. It lets direct MCP clients auto-discover the IdP via Protected Resource Metadata and locks the MCP endpoint to that integration. Lock a scope to an external IdP and Snowflake OAuth tokens are rejected for MCP servers there, with no fallback; accounts needing both must set the parameter per schema or database. AWS also notes an on-behalf-of TOKEN_EXCHANGE grant for unattended per-user identity without consent prompts, and an API-key provider supporting Programmatic Access Tokens. Patterns 2 and 3 follow standard OAuth flows and can extend to other OAuth-protected MCP servers, though claims, scopes and audience must be validated; only Pattern 1 is Snowflake-specific. AWS frames Pattern 1 as the simplest route to per-user audit trails, appropriate for proofs of concept, individual accountability requirements, or where user lifecycle stays inside Snowflake.
Why it matters: teams wiring agents to enterprise data now have documented, tested recipes for outbound OAuth rather than broad service accounts or custom integrations. That matters most for platform and security engineers, who must choose between per-user attribution and simpler machine authentication, and who face real footguns in issuer-locking and per-role consent. My own inference is that the pattern-selection rules here will become a reference point for other MCP servers behind corporate IdPs.
Based on reporting from the original publisher. Visit the source for full context and later updates.
Publisher excerpt
When an AI agent on Amazon Bedrock AgentCore calls Snowflake Cortex AI over MCP, how does it authenticate? This post walks through three OAuth patterns we tested on AgentCore Identity: Snowflake OAuth, three-legged OAuth with a corporate IdP, and two-legged OAuth, so you can match your organization's identity, audit, and compliance needs.