All articles

OAuth without registration: Client ID Metadata Documents

In How OAuth works I skipped right past a step that every example quietly depends on: before my meeting planner could talk to Google, I went to a console, registered the app, and copied a client_id (and a client_secret) into my config. Registration is so normal that it doesn't feel like a step at all.

Then AI agents showed up and it stopped being normal. Over the last six months I built support for Client ID Metadata Documents (CIMD) at Clerk, from the first schema change to general availability. This post is the explainer I wish I'd had at the start: the problem, the idea, the flow, and the handful of things the spec says in one sentence that took me a whole PR to get right.

The problem: everyone talks to everyone now

Classic OAuth assumes a small number of clients that know, in advance, which servers they'll talk to. A calendar app integrates with Google. Somebody at the company registers it once, and that's that.

MCP (Model Context Protocol) flips that. An MCP client like Claude Code, Cursor, or ChatGPT can connect to any MCP server a user pastes in, and each of those servers can have its own authorization server. That's N clients times M servers, and nobody sat down in advance to register the pairs.

There were two answers before CIMD, and neither is great:

  • Pre-registration. The server's owner creates a client for every agent they want to allow. This works for the big names and fails for everyone else: a new client can't connect until someone adds it by hand, on every server.
  • Dynamic Client Registration (RFC 7591). The client calls a /register endpoint, describes itself, and gets a fresh client_id back. No human in the loop, which is the point. But every client re-registers on every server, often on every install, so servers pile up thousands of anonymous registrations. And nothing in a registration proves who sent it: anyone can POST a body that says "client_name": "Claude".

The idea: the client ID is a URL

CIMD changes one thing. Instead of the server handing the client an opaque ID, the client's ID is an HTTPS URL that the client controls, and that URL serves a JSON document describing the client.

Here's a real one. This is what Claude Code publishes:

{
  "client_id": "https://claude.ai/oauth/claude-code-client-metadata",
  "client_name": "Claude Code",
  "client_uri": "https://claude.ai",
  "redirect_uris": [
    "http://localhost/callback",
    "http://127.0.0.1/callback"
  ],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}

There's no registration call. The first time Claude Code shows up at an authorization server, it sends that URL as its client_id, and the server goes and reads the document. Every server sees the same ID for the same client, and the ID itself tells you who's vouching for it: whoever controls claude.ai.

The MCP authorization spec now treats this as the default for clients and servers that have never met. Clients SHOULD try, in order: a pre-registered client if they have one, then CIMD if the server supports it, then Dynamic Client Registration, which is kept around for backward compatibility.

Step-by-step: the flow with a URL for a client ID

If you read the last post, this will look familiar. It's still Authorization Code + PKCE. What changes is who knows what, and when.

The flow
Claude Codeauth serverclaude.aiGET /.well-known/…cimd supported: true/authorize?client_id=URLGET client_id URLmetadata JSONPOST /token + verifieraccess + refresh tokenid ✓ redirect ✓ public ✓Consent: Claude Code (claude.ai)

The whole flow

1. The client checks that the server supports CIMD

The authorization server advertises support in its metadata (/.well-known/oauth-authorization-server, trimmed here):

{
  "issuer": "https://auth.example.com",
  "client_id_metadata_document_supported": true,
  "code_challenge_methods_supported": ["S256"]
}

If that flag is missing, the client falls back to Dynamic Client Registration (or gives up).

2. Redirect the user, with the URL as the client ID

GET /oauth/authorize?
  client_id=CLIENT_ID&
  redirect_uri=http://localhost:3118/callback&
  response_type=code&
  scope=profile email offline_access&
  code_challenge=CODE_CHALLENGE&
  code_challenge_method=S256&
  state=RANDOM_CSRF_TOKEN
Host: auth.example.com

CLIENT_ID is the document's URL from above, and the values are shown decoded so they're readable. Notice the redirect URI has a port, 3118, and the document's doesn't. Hold that thought.

3. The server fetches and checks the document

This is the new part. Before it shows anything to the user, the server:

  1. Fetches the client_id URL (with a lot of care, see below).
  2. Checks that the document's client_id is exactly the URL it fetched. A document can't claim to be some other client.
  3. Checks that the redirect_uri from the request is in redirect_uris.
  4. Checks that the client is public: no client_secret, no secret-based auth method. A JSON file on the internet can't keep a secret, so CIMD clients authenticate with PKCE instead.

The user sees a consent screen. The draft says the server SHOULD display the hostname of the client_id, and this matters more than it looks, which I'll get to.

5. Exchange the code

POST /oauth/token
Host: auth.example.com
Content-Type: application/x-www-form-urlencoded

client_id=CLIENT_ID&
code=AUTH_CODE&
code_verifier=CODE_VERIFIER&
grant_type=authorization_code&
redirect_uri=http://localhost:3118/callback

No client_secret. The code_verifier proves that whoever is redeeming the code is whoever started the flow. From here on it's plain OAuth: access token, refresh token, done.

What the spec says in one line and takes a PR to get right

The draft is short and readable. These are the parts where the short sentence hides the real work.

"Fetch the document" means "fetch a URL a stranger gave you"

The client_id arrives on an unauthenticated request. Anyone on the internet can make your authorization server issue an HTTP request to any URL they like. That's a textbook SSRF (server-side request forgery) setup, and the spec is blunt about it: never fetch a URL that resolves to a special-use address (loopback, private ranges, link-local, cloud metadata endpoints, and so on).

What that turned into in practice:

  • Check the address you actually connect to, not just the hostname in the URL. A hostname can resolve to 10.0.0.1 on the second lookup.
  • Don't follow redirects. The spec says MUST NOT, and it also kills a whole class of tricks.
  • Require a 200, cap the response size (the draft suggests 5 KB), and set a short timeout. Ours is three seconds.
  • Rate-limit fetches per host, so one person can't turn your server into a crawler.

Caching is a correctness feature, not just a speed one

You don't want to fetch the document on every authorization request: it's slow, and it means a blip on the client's server breaks logins on yours. The spec says to respect Cache-Control, enforce a maximum and a minimum cache lifetime, and never cache errors or invalid documents. It also says a transient fetch failure shouldn't by itself undo trust you already established.

We ended up with a cache that serves the last good copy for a short window if a refetch fails. A client whose hosting has a bad five minutes keeps working; a client that publishes a broken document does not.

Exact match, except on localhost

Remember port 3118? This one bit us after launch.

Claude Code is a CLI. It can't predict which local port will be free, so its document registers http://localhost/callback with no port, and at runtime it binds a port and sends http://localhost:3118/callback. With strict exact matching, those don't match, and real users got a 400 when they tried to connect.

The fix was already written down, just in a different RFC. RFC 8252 §7.3, the OAuth-for-native-apps spec, says the server "MUST allow any port to be specified at the time of the request for loopback IP redirect URIs." The CIMD draft repeats the same exception. So we allow any port, and only the port, for loopback redirect URIs. Scheme, host, path, and query still have to match exactly. And the token exchange is bound to the exact port the code was issued for, so a code sent to :3118 can't be redeemed by something on :4000.

A related one we caught later: 0.0.0.0 is not loopback. It's the "unspecified" address, meant for binding a listening socket, but browsers will happily route a request for it to whatever is listening on your machine. Since it isn't loopback, the port exception never applied, but a portless http://0.0.0.0/callback could still be registered and then match exactly. We now reject it (and its [::] and shorthand cousins) at registration.

The name and logo are claims, not facts

Back to step 4. CIMD doesn't stop a client from lying about its name. I can host a document at https://totally-legit.example/client.json that says "client_name": "Claude Code", and the document is perfectly valid. The draft calls this out directly: the name and logo are asserted by the client.

What CIMD gives you is an identity that can't be forged: the URL. That's why the consent screen should lead with the hostname. "Claude Code (claude.ai)" and "Claude Code (totally-legit.example)" look very different to a user. Localhost redirects deserve an extra warning too, because a document can't prove which program on your machine is listening.

Somebody still decides who gets in

Saying "any client can connect without registering" makes some security teams nervous, and reasonably so. The spec leaves trust policy to the server. At Clerk we turned that into a setting: allow any compatible client; allow only pre-approved clients plus ones that already connected; or allow only pre-approved clients. Owners can also pre-approve one client at a time, and the scopes they pick on their side always win over whatever a document asks for. The Clerk docs cover the details.

Should you care?

If you build an OAuth client, especially an agent: host one small JSON file on a domain you control and use its URL as your client_id. You stop registering on every server, and every server sees one stable ID for you. Use "token_endpoint_auth_method": "none", list your redirect URIs, and use PKCE.

If you run an authorization server: you're about to see a lot of clients you've never met. CIMD lets you treat them as known identities instead of a growing pile of anonymous registrations. Fetch like a paranoid person, cache like an optimist, show the hostname, and keep a switch for who's allowed in.

Registration was never really about paperwork. It was about the server knowing who the client is. CIMD keeps that, and drops the paperwork.

Or skip the hard parts. If Clerk is the authorization server for your app or MCP server, none of the server-side work above is yours to do. I built CIMD support into Clerk, so the careful fetching, the caching, the loopback rules, and the "who gets in" setting are already there. The docs show how to set it up.