Skip to main content
On a server configured with oauth, tool, resource, and prompt callbacks receive verified authentication data on ctx.auth. The provider determines the static type of ctx.auth.user; there is no generic UserInfo shape.

Auth shape

Every provider exposes this top-level shape:
  • user is the provider’s normalized user type.
  • payload contains the verified token claims or introspection data.
  • accessToken is the verified bearer token. Forward it only when calling an upstream API on behalf of the user.
  • scopes are copied from the auth information returned by the token verifier.
  • permissions are produced by the provider’s mapping.
  • clientId is present when the token has a client identifier.
  • expiresAt is a Unix timestamp in seconds.
  • resource is the protected resource validated by the verifier.

Use provider-specific fields

All built-in users have id. Optional profile and organization fields vary:
Use normalized fields for application logic. Read payload only when you deliberately need a provider claim that is not mapped.

Check scopes and permissions

Scopes describe OAuth grants. Permissions describe provider-mapped application authorization.
Provider mappings differ: Auth0 and WorkOS map their permission claim, Clerk maps organization permissions, Keycloak flattens resource roles as client:role, and Supabase maps AAL to aal:<level>.

Map custom claims

For another authorization server, oauthCustomProvider separates verification from application mapping:
This fixed-token verifier keeps the example small and is only suitable for local testing. In production, validate the token signature, issuer, expiry, and MCP resource, or introspect an opaque token with the authorization server. createTokenVerifier receives the canonical MCP resource. mapAuthInfo runs only after SDK auth information has been verified and must return { user, payload, permissions }. It does not rewrite ctx.auth.scopes; those come from the verifier’s verified auth info.

Next steps

Authentication

Choose and configure an OAuth provider.

Custom Provider

Implement resource-bound token verification and claim mapping.

Middleware

Apply shared authorization checks.