Dev.to Security ๐Ÿ” Cybersecurity ๐Ÿ‘ 0 ๐Ÿ“– 12 min read

MCP server OAuth for ChatGPT and Claude with the login you already have

I'm building Transica, where I put OAuth in front of a company's existing login so its customers can sign in to MCP servers from ChatGPT and Claude. These are my notes on what that takes: which identity providers let Cha

I'm building Transica, where I put OAuth in front of a company's existing login so its customers can sign in to MCP servers from ChatGPT and Claude. These are my notes on what that takes: which identity providers let ChatGPT and Claude register on their own, which redirect addresses to allow, and six steps from the first 401 to refresh tokens that keep people signed in. They follow the 2026-07-28 MCP specification.

To let ChatGPT and Claude users sign in with the login they already have, your MCP server answers a request without a valid token with HTTP 401 pointing to its protected resource metadata, and an OAuth 2.1 authorization server with PKCE S256 signs them in. That server is your identity provider itself when it lets ChatGPT and Claude register on their own and puts the resource value in the token's audience. Otherwise it's an authorization server in front of your provider that sends people to your usual login page. Public tools need no sign-in at all.

How do I let ChatGPT users sign in with my existing login?

It depends on what your provider supports. Provider docs read on 4 November 2026:

Provider Client ID metadata documents Dynamic client registration resource becomes the audience ChatGPT and Claude register on their own
Auth0 Yes, a tenant setting Yes, a tenant setting Yes, with a compatibility profile Yes
Okta Configured by an admin per app An API exists; open registration not documented Yes Not documented
Clerk Yes Yes Not documented Yes
Supabase Not documented Yes, in public beta Not documented Through dynamic registration

How do I let ChatGPT users sign in with my existing Auth0 login?

Auth0 supports both ways the AI apps register. Under Dashboard > Settings > Advanced, turn on Client ID Metadata Document Registration with Dynamic CIMD Registration, or Dynamic Client Registration (DCR). Open DCR lets anyone create applications in your tenant without a token, at up to 5 requests a second, and those clients can use only domain-level connections (Auth0).

In the same place, turn on the Resource Parameter Compatibility Profile, so the resource value ChatGPT and Claude send becomes the token's audience. When a request carries both resource and audience, Auth0 uses audience (Auth0). Turn on Include Issuer in Authorization Responses too, which ChatGPT needs for its stable redirect address.

How do I let ChatGPT users sign in with my existing Okta login?

Okta supports the resource parameter and audience switching (Okta). Its client ID metadata documents are set up by an admin for each app (Okta), and its docs don't describe an unknown client registering itself. Plan on an authorization server in front of Okta, with Okta as its upstream provider (below).

How do I let ChatGPT users sign in with my existing Clerk login?

Clerk supports both. Under OAuth applications > Settings > Client onboarding, turn on Publish CIMD support, and Publish DCR support only for clients that need it. Clerk's @clerk/mcp-tools package serves the protected resource metadata at /.well-known/oauth-protected-resource/mcp and verifies Clerk's tokens (Clerk). Clerk's guide doesn't mention the resource parameter, so check each token's audience yourself.

How do I let ChatGPT users sign in with my existing Supabase login?

Supabase Auth's OAuth 2.1 server, in public beta, signs users in with the authorization code flow and PKCE and lets MCP clients register dynamically. Turn it on under Authentication > OAuth Server (Supabase). Its docs don't mention client ID metadata documents or the resource parameter, so ChatGPT and Claude both use dynamic registration. WarrantyWarden's ChatGPT plugin signs people in with its existing Supabase login through an authorization server in front of it (case study).

Does ChatGPT support dynamic client registration or client ID metadata documents?

Both. ChatGPT prefers a client ID metadata document when your authorization server advertises client_id_metadata_document_supported: true; the plugin builder can pick dynamic registration instead, and a predefined client also works. With dynamic registration, ChatGPT registers once per MCP server connection and reuses that client; if its credentials expire, people get invalid_client (OpenAI). The 2026-07-28 MCP spec says clients and servers should support metadata documents and marks dynamic registration as deprecated.

Which redirect URI does ChatGPT use?

https://chatgpt.com/connector_platform_oauth_redirect when your authorization server sends the issuer in its responses (RFC 9207). Otherwise https://chatgpt.com/connector/oauth/{callback_id}. Copy the exact address from your MCP server's management page into your provider's allowed list. ChatGPT's client ID metadata document is at https://chatgpt.com/oauth/client.json, or a per-callback address without RFC 9207.

Does the same sign-in work in Claude?

Yes. Claude connects to the same server and uses https://claude.ai/api/mcp/auth_callback on the web, desktop and mobile. Claude Code signs in on a local port: allow http://localhost/callback and http://127.0.0.1/callback with any port. Claude uses a metadata document only when your provider advertises both client_id_metadata_document_supported: true and "none" as a token endpoint auth method; otherwise it registers dynamically, a new client on every fresh connection (Anthropic).

The steps below follow the MCP specification (2026-07-28).

How does MCP server authentication work?

There are three parties. Your MCP server holds the data and checks the token on every request. Your authorization server signs people in and hands out tokens. That's usually the identity provider you already use, such as Auth0, Clerk, WorkOS, Okta, Microsoft Entra ID or Keycloak, not something new. And ChatGPT or Claude is the client: it works out where to send people, gets a token on their behalf and sends it with each request. When your identity provider can't serve the AI apps directly, the MCP server runs its own authorization server in front of it (below).

What is the MCP OAuth flow?

A request without a token gets a 401. The app finds your authorization server from your metadata, registers, signs the person in with PKCE and sends the token with each request. Steps 1 to 6 set this up.

Step 1: say "sign in first" the right way

When a request needs sign-in and arrives without a valid token, answer with HTTP 401 and a WWW-Authenticate header that tells the app where your metadata lives. For example: WWW-Authenticate: Bearer resource_metadata="https://mcp.example.com/.well-known/oauth-protected-resource", scope="orders:read".

Two details catch people out. Claude only starts sign-in on a real 401. If you return a normal 200 with a "please sign in" message, that text just shows up in the chat and nothing happens. And the scope part is optional but worth sending, because it tells the app exactly which permissions to ask for, so the consent screen isn't broader than it needs to be.

Step 2: publish where your sign-in lives

Your server needs a small JSON document, called protected resource metadata (RFC 9728), that names the server and its identity provider. The main fields are resource (for example https://mcp.example.com/mcp), authorization_servers (for example ["https://auth.example.com"]), and optionally scopes_supported.

Get these right and most of the rest follows. The resource value has to match your server's URL exactly as people type it into the app, path included. Put your main identity provider first in authorization_servers, because Claude only ever uses the first one. Serve the document at /.well-known/oauth-protected-resource/mcp as well as at /.well-known/oauth-protected-resource, since clients try the first one when your URL has a path. And keep scopes_supported to what basic use needs; you can ask for more later (see per-tool access).

Step 3: make your identity provider discoverable

Your identity provider has to publish its own metadata, either standard OAuth server metadata (RFC 8414) or OpenID Connect discovery. Most providers already do. It's still worth checking a few things. It should list its issuer and its authorization and token endpoints. It should say it supports PKCE with S256, because every flow uses it. Ideally it should include the issuer in each sign-in response (RFC 9207): the spec asks clients to check it and expects to make it required later.

One easy one to miss: the AI app has to be able to reach your identity provider. Claude's requests come from Anthropic's published range (160.79.104.0/21 as of this writing), and a firewall in front of your identity provider can break sign-in even when your MCP server itself is reachable.

Step 4: let the app register itself

Before ChatGPT or Claude can send anyone to sign in, it needs a client ID at your identity provider. There are three ways to get one.

The one the spec now prefers is a client ID metadata document. The app's client ID is simply an HTTPS URL, and your identity provider fetches it to read the app's name and redirect addresses. There's no registration step and no table of clients to maintain. OpenAI prefers it too, and Claude uses it as long as your metadata advertises client_id_metadata_document_supported: true and accepts "none" as a token endpoint auth method.

The second is a client you create yourself and hand to the app. Claude calls this Anthropic-held credentials and takes it in its developer portal. It doesn't work when every customer has their own server URL.

The third is dynamic client registration, where the app registers itself through an endpoint you expose. Both apps still support it, but the 2026-07-28 spec marks it as deprecated, and Claude registers a new client on every fresh connection, so a busy server can end up with thousands of them.

If your provider supports metadata documents, use those. If it doesn't, dynamic registration works for now.

Whichever you choose, register the right redirect addresses. Claude on the web, desktop and mobile uses https://claude.ai/api/mcp/auth_callback. Claude Code signs in through your computer on a random local port, so accept http://localhost/callback and http://127.0.0.1/callback with any port. And show the redirect host clearly on your consent screen, so people can see who's asking.

Step 5: make sure each token was meant for you

During sign-in, the app tells your identity provider which server the token is for (the resource parameter, RFC 8707). Put that into the token's audience. Then check every token on every request: the signature, the issuer, the expiry and the audience. A token meant for some other API has to be refused, even if it's otherwise valid.

The spec is strict about one more thing: your server must never pass the token it received on to other services. If your MCP server calls your own API behind the scenes, it uses its own credentials or exchanges the token for a new one. Forwarding it is a known way to get confused-deputy bugs.

Tokens go in the Authorization: Bearer header only, never in the URL. And when a token is invalid or expired, answer 401 so the app knows to refresh it.

Step 6: make refresh boring

Nobody wants to sign in again every hour. Offer refresh tokens: Claude adds offline_access to its request when your provider lists it, and refreshes up to five minutes before a token expires or as soon as it gets a 401. If the app registered through a metadata document or dynamic registration, rotate the refresh token on each use and send the new one in the same response. When a refresh token is no longer valid, answer with the standard invalid_grant error rather than a custom one, so the app can recover cleanly.

Two practical details. Your token endpoint has to accept ordinary form posts (application/x-www-form-urlencoded), while registration uses JSON, so check both parsers. And be quick: Claude waits ten seconds for discovery, registration and token requests and thirty for refresh, then gives up.

Where ChatGPT and Claude differ

The two apps share the same foundation, but a few things work differently.

Claude ChatGPT
What starts sign-in An HTTP 401 with WWW-Authenticate securitySchemes on each tool, plus an error result carrying _meta["mcp/www_authenticate"]
How the app registers Metadata document (when both values are advertised), a client you give Anthropic, or dynamic registration Metadata document preferred, dynamic registration or a predefined client
Other options A fixed API key in a header (beta, organization-wide) or credentials entered at connection time (on request) No API keys for public apps
Some tools without sign-in Yes ("lazy authentication") Yes ("mixed" auth)

The per-tool side of this is in per-tool access. Directory sign-in rules: ChatGPT and Claude.

How to use your existing identity provider (sign-in through the middle)

Pointing ChatGPT or Claude straight at the OAuth setup your web and mobile apps already use rarely works:

  • Wrong audience. Your provider issues tokens for your API. The MCP server must refuse any token not issued for it, so a token for api.example.com isn't a token for mcp.example.com.
  • No passthrough. Forwarding the app's token to your API is forbidden by the spec. A token leaked from one AI app would open your whole API.
  • Registration doesn't fit. The apps register themselves, by client ID metadata document or dynamic registration. Many providers support neither.
  • Consent can't name the AI app. Your provider's consent screen was written for your own apps. It can't name the AI app or list the tools that will act on the account.

The fix is a second authorization server that belongs to the MCP server, with its own issuer at the MCP server's address, chained to your provider. To ChatGPT and Claude it's the only sign-in server. To your provider, the MCP server is one more OAuth client, like your mobile app. When someone connects:

  1. The app gets a 401. Its protected resource metadata names the MCP server's own authorization server.
  2. The app registers there, by metadata document or dynamic registration. Your provider never needs to support either.
  3. The person approves the AI app. A consent screen names the app and lists its tools, before anything is sent to your provider. The MCP spec asks for this when a server signs in at a provider with one fixed client.
  4. The person signs in with their usual login. The MCP server sends them to your provider as an ordinary OAuth client, with its own PKCE, and checks the provider's iss on the way back when one is sent.
  5. The MCP server learns who signed in. It exchanges the code server to server and reads the user ID from a verified ID token, the userinfo endpoint or a signed access token.
  6. The app gets its own code. It exchanges it with its PKCE verifier and the resource parameter for a token whose audience is that MCP server only.
  7. Each tool call checks the app's token, finds the grant behind it and calls your API with your provider's token, for that call only.

The person sees one consent screen, then the login page they already know. No second account is created.

Party Holds Works at Lifetime
ChatGPT or Claude The MCP server's access and refresh tokens That MCP server only Access up to 1 hour, never past the provider token behind it; refresh token rotated on use; grant lapses after 90 days unused
MCP server Your provider's access and refresh tokens, encrypted Your API Provider token refreshed with the app's refresh once under 10 minutes remain
Your API Your provider's token, as from your own apps Your API Your provider's settings

A token leaked from an AI app opens only that MCP server, and your API only ever sees your provider's tokens. Setting your provider's token audience to the MCP server fixes the first problem only: registration and consent still don't fit.

Your side of the setup: your provider's issuer (its metadata supplies the endpoints), a client there for the MCP server (its own metadata document, dynamic registration, or a client you create with the MCP server's callback allowed), and an API that accepts your provider's tokens, as it already does for your web app.

Sources

All read on 4 November 2026.

Originally published on transica.dev. I wrote it with help from an AI model and checked each claim against the linked sources.

๐Ÿ“ฐ Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.