# Discovery document

> Apps and libraries configure themselves from the realm's public documents, which list its endpoints, grants, algorithms and signing keys.

Give an app's library the realm's issuer, `https://foobar.cvyuh.com/oauth2`, and it finds everything else on its own: the
sign-in and token endpoints, the grants and client authentication methods the realm accepts, the algorithms it signs
with, and the keys to check its tokens. You never copy endpoint addresses into an app by hand.

The documents follow your settings, so they always say what the realm offers now. Turn on device sign-in, say, and
its endpoint appears; turn it off, and it's gone.

## Before you begin

- **Who can do it:** anyone can read the documents: they are public. Changing the key settings that shape them needs a
  realm administrator (a group holding `RealmOwner`).
- **Where:** today the key settings are changed through the API ([Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`).
- **First:** nothing. Every realm publishes its documents from the start.

## How it works

| Document | Address |
|---|---|
| Authorization server metadata | `https://foobar.cvyuh.com/.well-known/oauth-authorization-server/oauth2` |
| OpenID configuration (the same, plus OpenID fields) | `https://foobar.cvyuh.com/oauth2/.well-known/openid-configuration` |
| Signing keys | `https://foobar.cvyuh.com/oauth2/jwks` |
| Token status lists | `https://foobar.cvyuh.com/oauth2/status/<list>`: see [status lists](../../revoke-access/status-lists/) |
| Shared signals configuration | `https://foobar.cvyuh.com/.well-known/ssf-configuration/oauth2`, while signals are on |
| AuthZEN metadata, for the decision endpoints | `https://foobar.cvyuh.com/.well-known/authzen-configuration`: see [ask the realm](/gateway/decisions/ask-the-realm/) |

```sh
curl https://foobar.cvyuh.com/.well-known/oauth-authorization-server/oauth2
```

A realm on its default settings answers, in part:

```json
{
  "issuer": "https://foobar.cvyuh.com/oauth2",
  "jwks_uri": "https://foobar.cvyuh.com/oauth2/jwks",
  "authorization_endpoint": "https://foobar.cvyuh.com/oauth2/authorize",
  "token_endpoint": "https://foobar.cvyuh.com/oauth2/token",
  "pushed_authorization_request_endpoint": "https://foobar.cvyuh.com/oauth2/par",
  "grant_types_supported": ["client_credentials", "authorization_code", "refresh_token"],
  "token_endpoint_auth_methods_supported": [
    "none", "client_secret_basic", "client_secret_post", "private_key_jwt"
  ],
  "token_endpoint_auth_signing_alg_values_supported": ["ES256", "RS256"],
  "dpop_signing_alg_values_supported": ["ES256", "RS256"],
  "response_types_supported": ["code"],
  "code_challenge_methods_supported": ["S256"]
}
```

What appears depends on what the realm offers:

- **Optional endpoints.** Device sign-in, backchannel authentication, registration, first-party sign-in and client
  metadata documents each appear only while you have them on.
- **Pushed requests.** The endpoint appears whenever the realm takes the authorization code grant, and
  `require_pushed_authorization_requests` is `true` only while you require them.
- **Request detail.** The [authorization details](../../../authorization/rich-authorization-requests/)
  types appear once you declare some, and the encryption of [signed request objects](../../client-security/request-objects/) once the realm
  holds a key for it.
- **Deferred grant.** While it is on ([agent guardrails](../../../../gateway/guardrails/agent-guardrails/)):
  `deferred_token_response_supported`, and the deferral code among
  `revocation_endpoint_token_type_values_supported`.
- **Token exchange.** While [token exchange](../../tokens/token-exchange/) is on:
  `identity_chaining_requested_token_types_supported`, naming the identity assertion
  (`urn:ietf:params:oauth:token-type:id-jag`) and the chaining grant (`urn:ietf:params:oauth:token-type:jwt`), and
  `id_jag_signing_alg_values_supported` (`RS256`).
- **The jwt-bearer grant.** While it is on: `authorization_grant_profiles_supported`, naming the
  [identity assertion grant](../../tokens/identity-assertion-grant/) (`urn:ietf:params:oauth:grant-profile:id-jag`).
- **The mtls alias.** While the alias is served and the realm's `mtls` is on
  ([certificate-bound tokens](../../client-security/certificate-bound-tokens/)): `tls_client_certificate_bound_access_tokens: true`, and
  `mtls_endpoint_aliases`, naming the token, introspection and revocation endpoints at `mtls.<issuer host>`, and
  pushed requests and userinfo there too while the realm offers them.
- **OpenID.** The OpenID configuration answers only while the realm offers `openid` and the browser sign-in grant.

## Set it up

Nothing to set directly: the documents follow your settings. Two key settings shape them, changed in the realm's
`keySettings`:

| Where | Setting | What it does |
|---|---|---|
| Realm, `keySettings` | `publication.maxAgeSecs` | How long clients may cache the signing keys (300 by default) |
| Realm, `keySettings` | `algorithm.oauth2.introspection` | What a signed [introspection](../../revoke-access/introspection/) answer may use (`RS256` and `ES256` by default), listed as `introspection_signing_alg_values_supported` |

## Limits and defaults

| Setting or limit | Default | Range |
|---|---|---|
| `publication.maxAgeSecs`: how long clients may cache the keys | 300 | set in `keySettings` |
| Issuers | one per host name, or one with a base URL | fixed |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A library says the issuer doesn't match | It was given `https://foobar.cvyuh.com` without `/oauth2`, or another host name | Give it exactly `https://foobar.cvyuh.com/oauth2`; set a [base URL](/platform/realms/realm-base-url/) for one issuer across names |
| `openid-configuration` answers `404` | The realm doesn't offer `openid`, or the authorization code grant is off | Add both to the realm's settings |
| An endpoint you expect is missing | The setting behind it is off (device sign-in, pushed requests, first-party apps) | Turn the setting on; the document follows at once |

## Audit record

Reading the documents writes no record. Changes to the settings they reflect are in **Audit → Config**.

## Good to know

- **Each host name is its own issuer**, unless you set a [base URL](../../../../platform/realms/realm-base-url/).
  Neither letter case nor a port makes a different issuer: the issuer is the host name alone.
- **Only an issuer whose host the realm claims has an mtls alias**, so a realm on a base URL at another's host lists
  neither `mtls_endpoint_aliases` nor `tls_client_certificate_bound_access_tokens`.
- **All of these documents are public.** The metadata, the OpenID configuration, the signing keys and the status
  lists may be read by any web page ([browser apps](../../single-sign-on/browser-apps/)). The shared signals configuration is for
  servers: a page on another site can't read it.
- **The keys document carries the encryption key too**, while the realm takes encrypted request objects.

## Related

- [Call the API](../../../../develop/api/): the conventions every call follows.
- [Apps and agents](../../../../develop/apps-and-agents/): every endpoint apps and agents call.
- [Check what clients discover](../../../../platform/guides/what-clients-discover/): the task, start to finish.
- [Signing keys](../../../../platform/keys/signing-keys/): the keys the documents publish.
- [Realm base URL](../../../../platform/realms/realm-base-url/): one issuer whatever host a client uses.
- [Client metadata documents](../client-metadata-documents/): the client's side of the same idea.
