When an AI agent running on Amazon Bedrock AgentCore needs to query Snowflake Cortex AI, the first question is not what the agent can ask — it is who the agent is when it asks. Snowflake Cortex OAuth is the answer AWS tested end to end: three OAuth configurations that let an agent authenticate to the Snowflake-managed MCP server, each with a different answer to the identity question.
Why agents need their own identity to reach Snowflake Cortex AI
Agents on Amazon Bedrock AgentCore call the Snowflake-managed MCP server, which exposes Snowflake Cortex Agents — Cortex Search and Cortex Analyst — as tools the agent can discover and invoke through the Model Context Protocol (MCP). Enterprises need to extend their authentication and authorization controls into the agentic layer; without a clear way to do that, the alternatives are broad service account permissions or custom-built auth integrations that add operational overhead.
A broad service account works, but every query it runs looks the same in the audit trail, with no way to tell which person the agent was working for. The three OAuth patterns answer that question, and the answer decides whether your audit trail names a real user or a shared service account — and whether Snowflake’s row-level security and masking policies apply to the person or to the machine.
How Snowflake Cortex OAuth works through AgentCore Identity

Two AgentCore capabilities do the work. Amazon Bedrock AgentCore Gateway connects 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, and aggregates its configured targets into a single unified catalog, presented to the agent as one tools/list response.
Amazon Bedrock AgentCore Identity is the credential broker. The Gateway obtains a workload token by calling GetWorkloadAccessTokenForJWT, then calls GetResourceOauth2Token against the configured provider. Identity owns the token vault, the token refresh, and the user-to-token binding, and fetches, caches, and refreshes tokens automatically. The outbound path is the same in all three patterns: the Gateway resolves a token through Identity, which obtains and renews it from an authorization server, then presents it to the Snowflake-managed MCP server. What changes is which authorization server issues the token and under which grant — two grant types, authorization_code for Patterns 1 and 2 and client_credentials for Pattern 3. Across all three, the agent code and the Snowflake MCP tool set stay unchanged; only the OAuth wiring differs.
Pattern 1: Snowflake OAuth, per-user with no external identity provider
Pattern 1 is the simplest path to per-user audit trails. Snowflake acts as its own OAuth authorization server: each user authenticates directly to Snowflake through the authorization code grant (3LO), and no external identity provider is needed. The credential provider is the generic CustomOauth2 provider, and the Snowflake security integration is TYPE = OAUTH with OAUTH_CLIENT = CUSTOM. Every query runs as the real user, with their assigned role. Snowflake exposes its built-in OAuth endpoints /oauth/authorize and /oauth/token-request.
At runtime, when a tool call needs a Snowflake token and none is cached, the Gateway returns JSON-RPC error code -32042 carrying a session-URI-bound authorization URL. The client opens it in the user’s browser, which is routed to Snowflake’s built-in authorization server. The user signs in and consents to a specific role — role names in the requested scope must be uppercase, for example session:role:ANALYST_ROLE. AgentCore Identity completes the code exchange only after the application calls CompleteResourceTokenAuth with the user identity and session URI, valid for 10 minutes. On the retried call, the Gateway presents the cached token, Snowflake creates a user session scoped to the consented role, and QUERY_HISTORY records the real username.
The consented scope controls the primary role only. The MCP server advertises session:role:all and falls back to DEFAULT_ROLE, so set OAUTH_SCOPES_SUPPORTED to narrow the advertised role scope and restrict ALLOWED_ROLES_LIST to enforce which roles a user can consent to. Keep OAUTH_USE_SECONDARY_ROLES = NONE — the default — so the session cannot carry more privilege than the consented role. Snowflake also blocks its most privileged roles from OAuth by default: ACCOUNTADMIN, ORGADMIN, GLOBALORGADMIN, and SECURITYADMIN, controlled by BLOCKED_ROLES_LIST (Snowflake OAuth) and EXTERNAL_OAUTH_BLOCKED_ROLES_LIST (External OAuth), applying to the primary role only.
Access tokens last 600 seconds by default, with a maximum of 3600; when one expires, AgentCore Identity automatically uses the refresh token to obtain a new one. Refresh-token lifetime is controlled by OAUTH_REFRESH_TOKEN_VALIDITY — the reference implementation sets it to 86400 seconds (1 day), and Snowflake allows up to 90 days — and OAUTH_ISSUE_REFRESH_TOKENS defaults to TRUE. This pattern suits proof-of-concept work, teams whose users already have Snowflake credentials, and compliance requirements that mandate individual accountability.
Pattern 2: three-legged OAuth with corporate single sign-on
Pattern 2 combines per-user authentication with corporate single sign-on. Users sign in through the external identity provider — Okta or Microsoft Entra ID in the tested configurations — which enforces multi-factor authentication (MFA), conditional access, and session policies. Snowflake trusts the IdP-issued JWTs through its External OAuth security integration, verifying the issuer, audience, and signature through a JSON Web Key Set (JWKS), then mapping a configurable claim to a Snowflake user’s LOGIN_NAME or EMAIL_ADDRESS. The mapping claim is sub for Okta and upn for Microsoft Entra ID.
The key difference from Pattern 1 is that the authorization server is your corporate IdP, not Snowflake; Snowflake remains the resource server. Users authenticate with the same credentials and policies they use for every other corporate application, and no separate Snowflake passwords are required. On the AgentCore side, Identity provides built-in credential provider vendors — OktaOauth2 and MicrosoftOauth2.
The runtime flow mirrors Pattern 1, with the IdP in place of Snowflake’s own server. When no token is cached, the Gateway returns the -32042 elicitation; AgentCore Identity routes the user to the IdP, where they authenticate through corporate SSO and consent to the requested scopes. For Okta, the role scope takes the form session:role:ANALYST_ROLE; Microsoft Entra ID delegated flows use session:scope: instead. Only after the application calls CompleteResourceTokenAuth does AgentCore Identity exchange the code for an access token and cache it in the per-user token vault. On the retried call, the Gateway presents the cached IdP-issued JWT. As AWS puts it: “Snowflake does not call the IdP at runtime. It validates tokens locally using the IdP’s published JWKS signing keys.”
The Snowflake side of this pattern is an External OAuth security integration, TYPE = EXTERNAL_OAUTH: Snowflake verifies the issuer, audience, and signature of IdP-issued JWTs through a JSON Web Key Set (JWKS) and maps the configured claim — sub for Okta, upn for Microsoft Entra ID — to a Snowflake user’s LOGIN_NAME or EMAIL_ADDRESS.
Unlike Pattern 1, token lifetimes here are governed by the IdP, and AgentCore Identity handles the refresh transparently. Revocation has one wrinkle: disabling a user in the IdP prevents new Snowflake authorizations, but cached tokens stay valid until they expire. To force a user to re-authorize, pass forceAuthentication=true on the next request, which clears the stored refresh token and starts a new authorization flow.
Pattern 3: two-legged OAuth with a shared service user
Pattern 3 uses the OAuth 2.0 client_credentials grant: a machine-to-machine flow with no user interaction. AgentCore Identity obtains a JWT from the IdP using the configured client ID and client secret, and the Gateway presents it to Snowflake, which executes the requests under a shared service user, regardless of which end user initiated the query.
This is the most operationally direct pattern: no consent screens, no per-user token vaults, no browser redirects. The credential provider uses the client_credentials grant type — either a built-in vendor (OktaOauth2, MicrosoftOauth2) or the generic CustomOauth2 provider; a built-in vendor is not required. Configuration needs the IdP’s token endpoint, client ID, and client secret. AgentCore Identity fetches a token from the IdP on the first tool call, caches it, and — because client_credentials issues no refresh token — requests a fresh one before it expires. Because the two-legged target needs no user consent, the Gateway connects to the Snowflake-managed MCP server at target-creation time and discovers tools through implicit sync.
The provider details matter at setup time. For Okta, the requested scope includes the Snowflake role, for example session:role:MCP_GATEWAY_ROLE. For Microsoft Entra ID, the client requests the api://<application-id>/.default scope and the role arrives in the roles claim from an app role whose value is session:role:MCP_GATEWAY_ROLE. The token’s aud claim is the Snowflake account URL or an additional value in EXTERNAL_OAUTH_AUDIENCE_LIST. For Microsoft Entra ID, the client ID is carried in appid/azp while sub holds the service principal’s object ID (a GUID), so with Entra ID, LOGIN_NAME must map to that GUID.
The trade-off is audit granularity. As the AWS post states: “There is no per-user identity propagation. Snowflake’s QUERY_HISTORY records a single service user for queries.” Because every request runs as the shared service user, Snowflake’s row-level security and column masking policies apply that user’s permissions to requests — policies keyed on CURRENT_USER() and CURRENT_ROLE() all resolve to that single service user and its one role. There is also no user-level token revocation: to cut off access, revoke the client credentials at the IdP or disable the Snowflake security integration, and rotate client secrets regularly, restricting the service user to least-privilege access. This pattern is preferred for automated, unattended, and batch workloads — scheduled jobs, background pipelines, or system-level agents with no human in the loop — where per-user identity is not required and a shared service user is acceptable for audit purposes.
On-behalf-of grants and the API-key alternative for unattended workloads
There is a fourth option for workloads with no user present, and it fixes Pattern 3’s main weakness. AgentCore Identity supports an on-behalf-of (OBO) grant (TOKEN_EXCHANGE) that delivers per-user identity for unattended workloads without a consent prompt. OBO exchanges an inbound user token for a Snowflake-scoped token that preserves the real user’s identity, so QUERY_HISTORY attributes each query to the actual user, while keeping the unattended, machine-to-machine flow of Pattern 3 — no browser redirect, no consent screen. On the Snowflake side it uses the same TYPE = EXTERNAL_OAUTH integration as Patterns 2 and 3, optionally issuer-locked with OAUTH_AUTHORIZATION_SERVER. On the AgentCore side it is configured on the OAuth credential provider through onBehalfOfTokenExchangeConfig, with grant mode TOKEN_EXCHANGE for Okta (RFC 8693) or JWT_AUTHORIZATION_GRANT for Microsoft Entra ID (RFC 7523 section 2.1). At runtime, call GetResourceOauth2Token with oauth2Flow set to ON_BEHALF_OF_TOKEN_EXCHANGE, passing the workload access token from GetWorkloadAccessTokenForJWT as the subject token.
OBO is generally available on AgentCore Identity, though it was outside the scope of the three configurations AWS tested. AgentCore Identity also offers an API-key credential provider, which supports Snowflake Programmatic Access Tokens, but the post focuses on OAuth for per-user attribution and automatic token refresh. If your workload is unattended but your auditors still need to see real usernames, OBO is the pattern to evaluate before defaulting to the shared service user.
Choosing the right pattern for your enterprise

The three patterns differ in only a few dimensions, and those dimensions decide the choice. Here is how the three patterns compare:
| Aspect | Pattern 1: Snowflake OAuth (3LO) | Pattern 2: 3LO with external IdP | Pattern 3: 2LO with external IdP |
|---|---|---|---|
| OAuth grant type | authorization_code | authorization_code | client_credentials |
| AgentCore Identity provider | Custom provider (CustomOauth2) | Built-in provider (OktaOauth2, MicrosoftOauth2) | Built-in provider or CustomOauth2 |
| Authorization server | Snowflake built-in OAuth | Third-party IdP (Okta, Entra ID) | Third-party IdP (Okta, Entra ID) |
| Identity visible to Snowflake | The real user | The real user | Shared service user |
| RBAC model | Per-user Snowflake role | Per-user Snowflake role | Single role for requests |
| Audit granularity (QUERY_HISTORY) | Real username | Real username | Service user |
| External IdP required | No | Yes | Yes |
| Snowflake security integration | TYPE = OAUTH, OAUTH_CLIENT = CUSTOM | TYPE = EXTERNAL_OAUTH + OAUTH_AUTHORIZATION_SERVER | TYPE = EXTERNAL_OAUTH + OAUTH_AUTHORIZATION_SERVER |
| User login experience | Snowflake login + consent | Corporate SSO | None (no user interaction) |
| MFA / conditional access | Per Snowflake account settings | Enforced by IdP | Not applicable |
| Token lifetime governance | Snowflake security integration | IdP authorization server policy | IdP authorization server policy |
| Works unattended | Only until the refresh token expires (reference app: 1 day, up to 90 days) | Only until the refresh token expires (per IdP session policy) | Yes: no user interaction needed |
| Best for | POCs needing per-user audit without an IdP | Enterprise apps with existing corporate SSO | Internal agents, batch jobs, service-to-service |
Choose by scenario. If you have no external IdP and need per-user audit, Snowflake OAuth is the simplest path. If corporate SSO is already in place and security requires all authentication to flow through it, three-legged OAuth with the external IdP gives you MFA, conditional access, and centralized policy without giving up per-user identity. If the workload is machine-to-machine — scheduled jobs, background pipelines, system-level agents — two-legged OAuth is the most direct model, and OBO is worth evaluating first if per-user attribution still matters. Patterns 2 and 3 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.
What to verify before going live
Choosing a pattern is not the same as enforcing it. Before the agent goes live, verify the settings that determine whether the intended identity and audit trail actually hold. Validate the token claims, scopes, and audience settings for your provider. Confirm the issuer-lock and the matching security integration on the Snowflake side — the issuer-lock is set with a hierarchical parameter that can be scoped to an account, database, or schema:
ALTER SCHEMA analytics_db.mcp_schema
SET OAUTH_AUTHORIZATION_SERVER = external_oauth_okta;
ALTER DATABASE analytics_db
SET OAUTH_SCOPES_SUPPORTED = 'session:role:ANALYST,session:role:DATA_SCIENTIST';When OAUTH_AUTHORIZATION_SERVER is set, Snowflake advertises the external issuer in the Protected Resource Metadata endpoint and rejects OAuth tokens that were not issued by that authorization server — and if you set it to issuer-lock an MCP scope to an external IdP, Snowflake OAuth tokens are rejected for MCP servers in that scope and do not fall back. If you need both patterns in one account, set the parameter per schema or database so each scope resolves to the right authorization server. Confirm the session role and scope grammar and the blocked-roles list behave as intended for the agent’s role, and keep OAUTH_USE_SECONDARY_ROLES = NONE so a session cannot carry more privilege than the consented role. Confirm that QUERY_HISTORY attribution shows the identity you expect — the real user for Patterns 1 and 2, the shared service user for Pattern 3.
Two more checks come from the fine print. For the three-legged patterns, the gateway pins the MCP protocol revision 2025-11-25 in its supported MCP revisions, which the URL-mode elicitation (-32042) handshake requires; the two-legged gateway does not pin it, because 2LO has no elicitation step. Patterns 1 and 2 run unattended only until the refresh token expires — re-consent then requires a live browser, the same user, and completion inside the 10-minute authorization window, which is why 3LO is unsuitable for fully unattended scheduled jobs, while Pattern 3 runs unattended indefinitely. Finally, the patterns were tested end to end with Okta and Microsoft Entra ID; other identity providers need the same validation of claims, scopes, and audience before you rely on them.












