Discover the authorization server
Start from the production API’s protected-resource metadata:authorization_servers and scopes_supported values for the current environment. Discover these values at runtime instead of hard-coding the Clerk host.
Authorization flow
Use the OAuth 2.0 authorization-code flow with Proof Key for Code Exchange (PKCE). PKCE binds the one-time authorization code to the client that started the sign-in. Use theS256 challenge method:
- Register a public OAuth client with the discovered authorization server. Dynamic Client Registration is supported for compatible clients.
- Use a loopback redirect URI such as
http://127.0.0.1:<port>/callback. - Generate a PKCE verifier and challenge.
- Open the authorization URL in the user’s browser.
- The user signs in to Control and is redirected to the loopback callback with a one-time code.
- Exchange the code and verifier at the discovered token endpoint.
- Send the access token as
Authorization: Bearer <token>. - Use the refresh token before the access token expires.
OAuth-capable Model Context Protocol (MCP) clients perform the redirect, PKCE, token exchange, and refresh
automatically. The user should not copy an access token into chat or application settings.
Verify the token
401means the token is missing, invalid, or expired.403means the signed-in user lacks workspace access or Parquet exports are not enabled.