# Client metadata documents

> Apps you don't know in advance, such as MCP clients and AI tools, sign your users in by publishing a document about themselves, with no registration.

An app publishes a small JSON document at an `https` address, such as `https://notes.example.com/oauth-client.json`,
and uses that address as its client ID. When it signs a user in, the realm fetches the document and builds the client
from it. There is no registration and nothing stored, and a change the app publishes reaches the realm once the
realm's copy stops being fresh.

Use it when many apps you don't know in advance should be able to sign your users in: MCP clients, which are
expected to identify themselves this way, and AI tools. Nobody vetted such an app, so the realm gives it the least
that is useful, and users always see a consent page naming it. Support turns it on for your realm; you say which
scopes and APIs such apps may reach.

## Before you begin

- **Who can do it:** accepting such apps at all (`clientIdMetadataDocuments`) is turned on for your realm by support:
  ask for it. A realm administrator (a group holding `RealmOwner`) then sets the scopes, APIs and blocked apps;
  `RealmViewer` can read them.
- **Where:** today this is done through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** decide which APIs such apps may call. With none, they can sign in but get no token.

## How it works

The app serves its document as JSON at its client ID:

```http
GET /oauth-client.json HTTP/1.1
Host: notes.example.com

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: max-age=3600

{
  "client_id": "https://notes.example.com/oauth-client.json",
  "client_name": "Notes",
  "redirect_uris": ["https://notes.example.com/callback", "http://127.0.0.1/callback"],
  "token_endpoint_auth_method": "none"
}
```

It then signs users in like any other app, with that URL as its `client_id`.

**An app that proves itself with keys** lists `private_key_jwt`, or `self_signed_tls_client_auth` to prove itself by
its own certificate, in `token_endpoint_auth_methods_supported`, and publishes its keys in `jwks` or at `jwks_uri`,
one or the other. The realm takes the first method in that list it allows here: `private_key_jwt` or
`self_signed_tls_client_auth` for an app that publishes keys, else `none`. An app may still send the single
`token_endpoint_auth_method` instead, and may name the algorithm its assertions use in
`token_endpoint_auth_signing_alg`.

An app proving itself by its certificate calls the token endpoint at the realm's mtls alias
([certificate-bound tokens](../../client-security/certificate-bound-tokens/)). With `"tls_client_certificate_bound_access_tokens": true`
its access tokens are bound to that certificate; only an app proving itself by its certificate may ask, and a
document asking otherwise isn't taken.

### How the realm fetches the document

- **Only over public `https`, and only the answer itself.** A redirect is never followed, and anything but a `200`
  served as JSON is refused.
- **At most 64 KiB, within 5 seconds.**
- **Fresh for as long as the app says.** The realm keeps its copy for the app's `Cache-Control: max-age`, between 60
  seconds and an hour. With no `max-age`, it's five minutes. With `no-store` or `no-cache`, it's 60 seconds.
- **The last good copy covers an outage.** If the app's server can't be reached, the last good copy is used for up to
  an hour past its time.
- **A failed fetch waits.** One that fails, with no good copy to fall back on, isn't tried again for 30 seconds.

## Set it up

Once support has turned `clientIdMetadataDocuments` on, list the APIs such apps may get tokens for in
`cimdResources`. Without `cimdResources` they can sign in but get no token:

```sh
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/oauth2Settings/oauth2Settings \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{ "cimdResources": ["https://app.example.com/api"] }'
```

| Where | Setting | What it does |
|---|---|---|
| Realm | `clientIdMetadataDocuments` | Accept such apps at all (default off; turned on by support). While it's on, discovery says `client_id_metadata_document_supported` |
| Realm | `cimdScopes` | The most scopes such an app may get (default `openid`, `profile`) |
| Realm | `cimdResources` | The APIs such an app may get tokens for. None by default, and with none every token request is refused `invalid_target`. With exactly one, it's the default audience |
| Realm | `cimdBlocked` | Exact client ID URLs to refuse, checked before any fetch |

## Good to know

- **The document must name itself.** Its `client_id` equals its URL, compared as written.
- **The URL is strict:** `https`, with a path beyond `/`, and no user name, fragment, or `.` or `..` segment.
- **Public, or proving itself with keys it publishes**, never a secret or a secret's expiry.
- **Return addresses are `https`, or the device itself:** `http://127.0.0.1`, `http://[::1]` or `http://localhost`,
  with any port or path. A return address's query may not carry the sign-in answer's own parameters (`code`,
  `state`, `iss`, `error`, `error_description`, `error_uri`).
- **The sign-in and refresh grants only**, plus the [identity assertion grant](../../tokens/identity-assertion-grant/) if it
  proves itself with keys. A document listing `grant_types` gets only those of these it names, and one naming none of
  them is refused, as is one whose `response_types` leave out `code`.
- **Scopes from `cimdScopes` only**, among those the realm offers. The document can't ask for more.
- **APIs from `cimdResources` only.** With exactly one listed, that one is its default, and a token request may leave
  `resource` out. With more, each request names one.
- **No browser page may call the realm as it**, since it lists no web origins ([browser apps](../../single-sign-on/browser-apps/)).
- **The `none` security profile**, and tokens bound to a key only when it sends a [DPoP](../../client-security/dpop/) proof.
- **Never an agent, never first-party**, and consent is never skipped.
- **A document that can't be used reads as an unknown client.** Whether it is blocked, can't be fetched, or breaks
  one of the rules above, the realm treats the client ID as one it doesn't know. At the token endpoint that is
  `invalid_client`.

## What the user sees

The realm's sign-in page, then always a consent page naming the app by its `client_name` and its address, and what
it asks for. The user allows or refuses it; it shows among their **Authorized Apps** afterwards, where they can take
it back.

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| `clientIdMetadataDocuments` | off | turned on by support |
| `cimdScopes` | `openid`, `profile` | among the realm's scopes |
| `cimdResources` | none: no tokens | absolute URIs |
| `cimdBlocked` | none | exact client ID URLs |
| Document size and fetch time | 64 KiB, 5 seconds | fixed |
| Copy kept fresh | the app's `max-age`, five minutes without one | 60 seconds to an hour |
| Last good copy, if the app's server is down | an hour past its time | fixed |
| Retry after a failed fetch | 30 seconds | fixed |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| The app is treated as unknown (`invalid_client`) | The document can't be fetched, isn't JSON with a `200`, names another `client_id`, breaks a rule above, or the URL is in `cimdBlocked` | Fetch the URL yourself and compare `client_id` to it, character for character |
| The user signs in, but every token request is `invalid_target` | `cimdResources` is empty | List the APIs such apps may call |
| A change to the document isn't seen | The realm's copy is still fresh | Wait out its `max-age`, at most an hour |

## Audit record

Such an app's token requests are `TOKEN_ISSUED` records under the URL as client ID; a user's consent is recorded
as for any app. Changes to `cimdScopes`, `cimdResources` and `cimdBlocked` are in **Audit → Config**.

## Related

- [Accept apps identified by a URL](../../../guides/partners/apps-identified-by-url/): the task, start to finish.
- [Dynamic registration](../dynamic-registration/): register clients with a token you hand out.
- [MCP tool calls](/gateway/mcp-servers/mcp-tool-calls/): decide each MCP tool call at the gateway.
- [Consent](../../../../customer-identity/consent/): the page users see before such an app gets anything.
