Manage OAuth 2.0 and OpenID Connect clients
OAuth2 clients are applications that securely authenticate with an authorization server to obtain access to an HTTP service. Every OAuth2 client is either confidential or public, depending on whether it can keep a secret. Applications that run on infrastructure you control, for example, backends and services, are confidential clients. They authenticate with a client secret. Applications distributed to users, for example, single-page apps, mobile, and native apps, are public clients. Anyone can read the code and extract an embedded secret, so they authenticate with PKCE and have no secret at all.
For each of your confidential clients, you register a client record with the client's secret for authentication. Public clients do
not have a client secret in the registered client record. In Ory, you set whether the client is confidential or public with
token_endpoint_auth_method value, where none means public.
This documentation article explains how to manage OAuth2 clients using the Ory Console, Ory SDK, Ory CLI, and Ory REST APIs.
Create OAuth2 client
To create a new OAuth2 client, use the following methods:
Clients that use the client_secret_basic or client_secret_post token-endpoint-auth-method are able to perform secret
rotation.
- Ory Console
- Ory CLI
- Ory SDK
- REST API
The Ory Console is a web-based user interface that allows you to manage OAuth2 clients. To create a new client:
- Go to OAuth 2 → Clients and applications in the Ory Console
- Click Create OAuth2 Client and complete the form.
- When creating a confidential client, copy the client secret when printed. It is only shown once.
ory create oauth2-client \
--grant-type authorization_code --grant-type refresh_token --grant-type client_credentials \
--response-type code \
--scope openid --scope offline_access \
--token-endpoint-auth-method client_secret_post \
--redirect-uri https://my-app.com/callback --redirect-uri http://my-other-app.com/callback
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function createOAuth2Client() {
await ory.createOAuth2Client({
oAuth2Client: {
grant_types: ["authorization_code", "refresh_token"],
redirect_uris: ["https://example.com"],
scope: "offline openid",
token_endpoint_auth_method: "client_secret_post",
},
})
}
See API documentation.
Supported grant types
When you create or update a client, including through OpenID Dynamic Client Registration, Ory validates the client's
grant_types. Grant types the deployment doesn't support are rejected with a 400 Bad Request error of type
invalid_client_metadata. Matching is case-insensitive.
Ory Network supports the following grant types on all plans:
authorization_codeimplicitclient_credentialsrefresh_tokenurn:ietf:params:oauth:grant-type:jwt-bearer
Ory Network projects on the Enterprise plan additionally support the urn:ietf:params:oauth:grant-type:device_code and password
grant types. Requests that add the device authorization grant to a client are rejected for projects on other plans. Self-hosted
Ory Hydra supports the grant types listed above plus urn:ietf:params:oauth:grant-type:device_code.
Clients created before this validation was introduced keep their existing grant types and can still be updated. Only grant type values that are newly added to a client are validated.
Redirect URI requirements
Redirect URIs must match exactly. Wildcard patterns such as https://*.example.com/callback are not supported in any environment,
including development mode.
The OAuth 2.0 specification (RFC 6749, Section 3.1.2.2) requires exact URI matching. On shared platforms such as Heroku, Vercel, and Netlify, wildcard subdomains would allow any tenant on that platform to intercept authorization codes or tokens intended for your application.
URL scheme requirements
redirect_uris and post_logout_redirect_uris reject the javascript:, data:, and vbscript: schemes, which browsers execute
as script. The same applies to frontchannel_logout_uri, which the logout page loads in the browser. Custom schemes for native
apps, such as com.example.app:/callback, keep working. Requests that violate these rules fail with 400 Bad Request error.
Dynamic preview and review environments
If your CI/CD pipeline creates ephemeral environments with unpredictable URLs, use one of these approaches.
Programmatic client updates (recommended)
Update the client's redirect_uris via the API when a review app is deployed, and remove the URI when the environment is torn
down. This approach works for any number of preview environments and requires no manual intervention.
Add the preview URL when the review app is deployed:
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function addRedirectUri(clientId: string, newUri: string) {
const { data: client } = await ory.getOAuth2Client({ id: clientId })
await ory.setOAuth2Client({
id: clientId,
oAuth2Client: {
...client,
redirect_uris: [...(client.redirect_uris ?? []), newUri],
},
})
}
Remove the URI when the review app is destroyed:
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function removeRedirectUri(clientId: string, uriToRemove: string) {
const { data: client } = await ory.getOAuth2Client({ id: clientId })
await ory.setOAuth2Client({
id: clientId,
oAuth2Client: {
...client,
redirect_uris: (client.redirect_uris ?? []).filter(
(u) => u !== uriToRemove,
),
},
})
}
Explicit URI listing
If the set of preview URLs is small and stable, register each URI explicitly when creating or updating the client:
ory update oauth2-client {client.id} \
--redirect-uri https://preview-1.example.com/callback \
--redirect-uri https://preview-2.example.com/callback
Custom domain
Point a stable domain you control at the review environment (for example, preview.yourapp.com). The redirect URI stays constant
across deployments and requires no client updates.
Update OAuth2 client
To update an existing OAuth2 client, use the following methods:
If you use secret rotation, setting a new secret through the update client API clears all rotated secrets.
- Ory Console
- Ory CLI
- Ory SDK
- REST API
- Go to OAuth 2 → Clients and applications in the Ory Console.
- Locate the client you want to update.
- Click on the pen symbol to update the client's configuration.
- When you are finished, scroll to the top and click Save.
To replace the entire client, pass a complete client definition from a file. Fields missing from the file are reset to their default values:
ory update oauth2-client --project <project-id> --workspace <workspace-id> {client.id} \
--file client.json
To change individual fields without touching the rest of the configuration, pass them as flags instead. See Patch OAuth2 client.
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Api, OAuth2Client } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function updateOAuth2Client(
id: string,
update: Partial<OAuth2Client>,
) {
// setOAuth2Client replaces all values (empty ones too),
// which is why we include the original client.
const { data: original } = await ory.getOAuth2Client({ id })
await ory.setOAuth2Client({
id,
oAuth2Client: {
...original,
...update,
},
})
}
See API documentation.
Patch OAuth2 client
To partially update an existing OAuth2 client, use the following methods:
If you use secret rotation, setting a new secret through the patch client API clears all rotated secrets.
- Ory Console
- Ory CLI
- Ory SDK
- REST API
- Go to OAuth 2 → Clients and applications in the Ory Console.
- Locate the client you want to update.
- Click on the pen symbol to update the client's configuration.
- When you are finished, scroll to the top and click Save.
Pass only the fields you want to change as flags. All other fields keep their current values:
ory update oauth2-client --project <project-id> --workspace <workspace-id> {client.id} \
--scope openid --scope offline_access \
--redirect-uri https://a-new-callback
// Copyright © 2026 Ory Corp
import { Configuration, JsonPatch, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function patchOAuth2Client(id: string, patches: JsonPatch[]) {
await ory.patchOAuth2Client({
id,
jsonPatch: [
...patches,
{
op: "replace",
path: "owner",
value: "New owner",
},
],
})
}
See API documentation.
Rotate OAuth2 client secret
OAuth2 client secret rotation allows you to change a client's secret without downtime. When you rotate a secret, the old secret remains valid until you remove it. This allows you to update the secret wherever your applications store it, then restart or redeploy anything that reads it, without service interruption.
Secret rotation is available only for clients that use the client_secret_basic or client_secret_post token endpoint
authentication method. Ory keeps up to five rotated secrets per client. When you rotate again, the oldest rotated secret is
dropped and can no longer authenticate.
If you use secret rotation, setting a new secret through the update or patch client APIs clears all rotated secrets.
How secret rotation works
- Rotation generates a new secret for the client. Both the old and the new secrets can be used to authenticate from this point on.
- Update the secret wherever it's stored, then restart or redeploy whatever applications read it.
- Verify that the application can authenticate with the new secret.
- Delete the old secret. Only the new secret authenticates from this point on.
Rotate OAuth2 client secret
To rotate an OAuth2 client secret, use the following methods:
- REST API
- Ory SDK
curl -X POST https://{project.slug}.projects.oryapis.com/admin/clients/{client-id}/secrets/rotate \
-H "Authorization: Bearer ory_pat_..."
The response includes the new client_secret. Ory returns this value once and stores only its hash, so it can't be
retrieved later. Save it now, wherever you keep the current secret.
To rotate to a secret you choose instead of a generated one, send it in the request body:
curl -X POST https://{project.slug}.projects.oryapis.com/admin/clients/{client-id}/secrets/rotate \
-H "Authorization: Bearer ory_pat_..." \
-H "Content-Type: application/json" \
-d '{"client_secret": "your-client-secret"}'
The body is optional. Omit it, and Ory generates a random secret.
See API documentation.
import { Configuration, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${projectSlug}.projects.oryapis.com`,
accessToken: "ory_pat_..."
})
)
const { data: client } = await ory.rotateOAuth2ClientSecret({
id: clientId
})
// Save the new client_secret immediately
console.log("New secret:", client.client_secret)
// Or rotate to a secret you choose:
await ory.rotateOAuth2ClientSecret({
id: clientId,
rotateOAuth2ClientSecretBody: {
client_secret: "your-client-secret"
}
})
Secrets remain valid indefinitely until you explicitly remove them. Always remove old secrets once your secret rotation process is complete to ensure that compromised credentials cannot be used.
Rotate to a secret you choose
By default, Ory generates the new secret. Supply client_secret in the request body to rotate to a specific value instead. The
secret must be at least 6 bytes. Ory generates 26-byte secrets, so a shorter supplied secret is weaker than the one you would get
by omitting the field.
Ory does not check the supplied value against the client's current or rotated secrets. Supplying the current secret is treated as an ordinary rotation: the secret keeps working, and it uses up one of the five rotated secret slots.
Remove old secret
Once your application is authenticating with the new secret everywhere, delete the old secret to revoke access:
- REST API
- Ory SDK
curl -X DELETE https://{project.slug}.projects.oryapis.com/admin/clients/{client-id}/secrets/rotate \
-H "Authorization: Bearer ory_pat_..."
After removing the old secret, only the current (new) secret is valid. The old secret can no longer authenticate.
See API documentation.
await ory.deleteRotatedOAuth2ClientSecrets({
id: clientId
})
// Old secret is now revoked.
Secret rotation workflow example
Here's a complete workflow for rotating a client secret:
# 1. Get current client
CLIENT_ID="your-client-id"
# 2. Rotate the secret
NEW_SECRET=$(curl -X POST "https://{project.slug}.projects.oryapis.com/admin/clients/$CLIENT_ID/secrets/rotate" \
-H "Authorization: Bearer ory_pat_..." | jq -r '.client_secret')
echo "New secret: $NEW_SECRET"
# 3. Update your client's services with the new secret
# (Both the old and the new secrets work during this period)
# 4. Verify the new secret works
curl -X POST "https://{project.slug}.projects.oryapis.com/oauth2/token" \
-u "$CLIENT_ID:$NEW_SECRET" \
-d "grant_type=client_credentials"
# 5. Once all your client's services are updated, remove the old secret
curl -X DELETE "https://{project.slug}.projects.oryapis.com/admin/clients/$CLIENT_ID/secrets/rotate" \
-H "Authorization: Bearer ory_pat_..."
# Old secret is now revoked
Delete OAuth2 client
To delete an existing OAuth2 client, use the following methods:
- Ory Console
- Ory CLI
- Ory SDK
- REST API
- Go to OAuth 2 → Clients and applications in the Ory Console.
- Locate the client you want to update.
- Click on pen symbol to update the client's configuration.
- Scroll to the bottom and click Delete Client.
ory delete oauth2-client {client.id}
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Api } from "@ory/client"
const ory = new OAuth2Api(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function deleteOAuth2Client(id: string) {
await ory.deleteOAuth2Client({ id })
}
See API documentation.
What happens when you delete a client
Deletion takes effect immediately. As soon as the request returns, the client can no longer obtain tokens, its existing access and refresh tokens stop being valid, and remembered consent no longer applies to it.
Stateless JWT access tokens are the exception. They are not stored, so they cannot be revoked and stay valid until their exp
claim passes. See Stateless JWT access tokens.
The data belonging to the client — including its tokens and consent sessions — is removed afterwards, in batches. This keeps deletion fast for clients that have issued large numbers of tokens. Remembered login sessions aren't client-specific, so they remain after a client is deleted.
The client ID stays reserved during deletion, giving the cleanup time to finish before the ID can be taken by a new client.
Creating a client with that ID during this window fails with 409 Conflict and the error code client_id_reserved.
To replace only the client's secret, rotate it instead of deleting the client.
OpenID Dynamic Client Registration
OpenID Dynamic Client Registration enables automatic registration of OAuth2 clients with the authorization server. When enabled, clients can be created, retrieved, updated, patched, and deleted dynamically without manual configuration. To enable OpenID Dynamic Client Registration, use the Ory CLI:
ory patch oauth2-config --project <project-id> --workspace <workspace-id> \
--replace "/oidc/dynamic_client_registration/enabled=true"
OpenID Connect dynamic registration involves the use of a registration_access_token, which is a bearer token that allows a
client to make requests to the OpenID Connect dynamic registration endpoint. The token is issued by the authorization server and
can only be used by the client that it was issued to.
It's important to note that the registration_access_token is a sensitive piece of information that should be kept secure. It
should only be used by the client that it was issued to and should not be shared with any other parties.
Updating a client through PATCH /admin/clients/{id} or PUT /admin/clients/{id}, including editing it in the Ory Console,
invalidates its registration_access_token. This prevents the client from overwriting changes that an administrator made.
Afterward, requests to GET, PUT, and DELETE /oauth2/register/{id} fail with 401 Unauthorized, so the client can no longer
read, update, or delete its own registration. The client keeps working for OAuth2 and OpenID Connect flows, and you can still
manage it through the admin API and the Ory Console.
Set the audience of dynamically registered clients
A client's audience is the allow list of audiences and resources that the client can request access tokens for. During OpenID
Dynamic Client Registration, Ory uses the configured default audience when the request omits audience or sends null. An
explicit audience takes precedence, including an empty list. The default is empty unless you configure it.
In Ory Network, add the URLs in the Default audiences field of OAuth 2 → OpenID Connect in the Ory Console, or use the Ory CLI:
ory patch oauth2-config --project <project-id> --workspace <workspace-id> \
--replace '/oidc/dynamic_client_registration/default_audience=["https://mcp.example.com/mcp"]'
For self-hosted Ory Hydra, set oidc.dynamic_client_registration.default_audience:
oidc:
dynamic_client_registration:
enabled: true
default_audience:
- https://mcp.example.com/mcp
The environment variable equivalent is OIDC_DYNAMIC_CLIENT_REGISTRATION_DEFAULT_AUDIENCE, which accepts a comma-separated list.
Ory applies the default audience only during registration when audience is unset:
- Changing the default audience only affects clients that register afterward. Existing clients keep their audience.
- Dynamic client registration updates use the supplied audience. Omitting it or sending
nullkeeps the client's current audience, and defaults are not reapplied. To clear the audience, send an empty list. - You can also update the client through the admin API or Ory Console.
The default audience only allows clients to request these audiences. A client still has to request an audience or resource, and your consent app decides what to grant. Requests are matched against the audience as described in OAuth2 token audience.
Example: Get an access token for an MCP server
MCP clients register through dynamic client registration and request access tokens for an MCP server with a resource parameter.
This example assumes that the default audience is https://mcp.example.com/mcp and that
resource indicators are enabled.
-
The client registers. The response contains the audience that Ory assigned:
curl -X POST https://$PROJECT_SLUG.projects.oryapis.com/oauth2/register \-H 'Content-Type: application/json' \-d '{"client_name": "My MCP client","redirect_uris": ["http://127.0.0.1:33418/callback"],"grant_types": ["authorization_code", "refresh_token"],"response_types": ["code"],"token_endpoint_auth_method": "none","scope": "openid offline_access"}'{"client_id": "<client-id>","audience": ["https://mcp.example.com/mcp"]} -
The client starts the authorization code flow with PKCE and names the MCP server as the resource:
https://$PROJECT_SLUG.projects.oryapis.com/oauth2/auth?response_type=code&client_id=<client-id>&redirect_uri=http%3A%2F%2F127.0.0.1%3A33418%2Fcallback&scope=openid+offline_access&state=<state>&code_challenge=<code-challenge>&code_challenge_method=S256&resource=https%3A%2F%2Fmcp.example.com%2Fmcp -
The user signs in and gives consent. The consent app grants the resource by adding
https://mcp.example.com/mcpfromrequested_resourcestogrant_access_token_audience. The consent screens built into Ory Network do this for you. -
The client exchanges the authorization code for tokens and sends the code verifier and the resource:
curl -X POST https://$PROJECT_SLUG.projects.oryapis.com/oauth2/token \--data-urlencode 'grant_type=authorization_code' \--data-urlencode 'client_id=<client-id>' \--data-urlencode 'code=<code>' \--data-urlencode 'redirect_uri=http://127.0.0.1:33418/callback' \--data-urlencode 'code_verifier=<code-verifier>' \--data-urlencode 'resource=https://mcp.example.com/mcp' -
The
audclaim of the access token contains the MCP server. The MCP server must check that its own URI is inaud, for example by introspecting the token:{"active": true,"client_id": "<client-id>","aud": ["https://mcp.example.com/mcp"]}
Requesting a resource that isn't in the client's audience, such as https://other.example.com/mcp, fails with invalid_target.
Register OAuth2 and OpenID Connect clients
Use the SDK or REST API to register an OAuth2 and OpenID Connect client:
- Ory SDK
- REST API
// Copyright © 2026 Ory Corp
import { Configuration, OidcApi } from "@ory/client"
const ory = new OidcApi(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function createOidcDynamicClient() {
const { data } = await ory.createOidcDynamicClient({
oAuth2Client: {
grant_types: ["authorization_code", "refresh_token"],
redirect_uris: ["https://example.com"],
scope: "offline openid",
token_endpoint_auth_method: "client_secret_post",
},
})
console.log(data.registration_access_token) // Write this down, it is only sent once!
console.log(data.client_id, data.client_secret /* ... */)
}
See API documentation.
The response includes the registration_access_token which is needed to manage the client. The token will only be shown once!
Get OAuth2 and OpenID Connect clients
The GET endpoint requires the client to authenticate with the registration_access_token regardless of the
token_endpoint_auth_method. It can be used to retrieve the OAuth2 and OpenID Connect client.
- Ory SDK
- REST API
// Copyright © 2026 Ory Corp
import { Configuration, OidcApi } from "@ory/client"
const ory = new OidcApi(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function getOidcDynamicClient(
id: string,
registrationAccessToken: string,
) {
const { data } = await ory.getOidcDynamicClient(
{
id,
},
{
headers: {
Authorization: `Bearer ${registrationAccessToken}`,
},
},
)
}
See API documentation.
Update OAuth2 and OpenID Connect clients
The POST endpoint requires the client to authenticate with the registration_access_token regardless of the
token_endpoint_auth_method. It can be used to update the OAuth2 and OpenID Connect client.
- Ory SDK
- REST API
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Client, OidcApi } from "@ory/client"
const ory = new OidcApi(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function createOidcDynamicClient(
id: string,
updatedClient: OAuth2Client,
) {
const { data } = await ory.setOidcDynamicClient({
id: id,
oAuth2Client: {
...updatedClient,
grant_types: ["authorization_code", "refresh_token"],
// ...
},
})
console.log(data.registration_access_token) // Write this down, it is only sent once!
}
See API documentation.
Delete OAuth2 and OpenID Connect clients
The DELETE endpoint requires the client to authenticate with the registration_access_token regardless of the
token_endpoint_auth_method. It can be used to delete the OAuth2 and OpenID Connect client.
- Ory SDK
- REST API
// Copyright © 2026 Ory Corp
import { Configuration, OidcApi } from "@ory/client"
const ory = new OidcApi(
new Configuration({
basePath: `https://${process.env.ORY_PROJECT_SLUG}.projects.oryapis.com`,
accessToken: process.env.ORY_API_KEY,
}),
)
export async function deleteOidcDynamicClient(
id: string,
registrationAccessToken: string,
) {
await ory.deleteOidcDynamicClient(
{
id,
},
{
headers: {
Authorization: `Bearer ${registrationAccessToken}`,
},
},
)
}
See` API documentation.
Client ID metadata documents
Client ID Metadata Documents (CIMD) let an application use the HTTPS URL of its metadata document as its OAuth2 client_id. Hydra
fetches the document when it needs to resolve the client. The application can start an authorization flow without registering a
client first.
Hydra implements draft-ietf-oauth-client-id-metadata-document-02. Client metadata documents written for earlier revisions of the draft work without changes.
With Dynamic Client Registration, the application registers a client and manages it through the registration API. With CIMD, the application hosts and updates its own metadata, and these clients don't appear in the client-management API. Prefer CIMD where you can: it stores no client record, so there is nothing to provision or clean up, and it always requires PKCE and limits redirect URIs to the document's own origin, loopback addresses, and native-app schemes.
The configuration below applies to self-hosted commercial Hydra. CIMD is disabled by default. These settings are not yet available through Ory Network project configuration or the Ory Console. Support for Ory Network is coming soon.
Enable client ID metadata documents
Add the following to your Hydra configuration and restart Hydra:
oauth2:
client_id_metadata_document:
mode: allowlist
allowed_url_patterns:
- https://app.example.com/oauth/client-metadata.json
The mode setting controls which client IDs Hydra resolves from documents:
| Mode | Behavior |
|---|---|
disabled | Does not resolve clients from metadata documents. This is the default. |
allowlist | Resolves URLs matching allowed_url_patterns. An empty list matches nothing. |
open | Resolves any valid client ID metadata URL, subject to document validation. |
Start with allowlist and list the applications you expect. Use open only if any application on the internet may start an
authorization flow with your server. In either mode, a document cannot skip the consent screen.
Anyone who can publish a document chooses the URLs Hydra fetches for it. Hydra fetches documents and their key sets under the same
clients.http rules as other outbound requests. Before you enable client ID metadata documents, make sure Hydra cannot reach
internal addresses on their behalf: set clients.http.disallow_private_ip_ranges to true and keep
clients.http.private_ip_exception_urls limited to hosts you control, or enforce the same with an egress proxy or network policy.
Allowlist entries use https://host[:port]/path. The host and the path must match exactly, except that the last path segment can
be *, which matches one segment, or **, which matches one or more:
| Entry | Matches |
|---|---|
https://app.example.com/oauth/client-metadata.json | Only this URL |
https://app.example.com/oauth/* | Documents directly under /oauth/, such as /oauth/app.json |
https://app.example.com/oauth/** | Every path under /oauth/, such as /oauth/clients/app.json |
To accept documents from several hosts, add one entry per host. You can configure up to 256 patterns. Hydra validates them when loading configuration.
Registered clients continue to work in every mode. If a registered client has the same ID as a metadata URL, Hydra uses the registered client and ignores the document.
Hydra advertises client_id_metadata_document_supported: true in /.well-known/openid-configuration when the mode is open or
when allowlist has at least one entry.
Set the audience and scopes of resolved clients
A client resolved from a metadata document can request only the audiences in audience and the scopes in scope. Hydra ignores
the document's own audience and scope, because a client publishes one document for every authorization server. It cannot know
which resources this one protects, and it learns the scopes a resource needs from that resource when it connects.
With resource indicators turned on, every resource the client sends must match an audience entry exactly,
or the request fails with invalid_target. A requested scope that isn't allowed fails with invalid_scope. Consent still decides
what is granted.
For MCP, list the canonical URI of each MCP server that uses this Hydra as its authorization server, and the scopes those servers
use. The URI is the resource value the server publishes in its protected resource metadata, and the value MCP clients send:
oauth2:
client_id_metadata_document:
audience:
- https://mcp.example.com/mcp
scope:
- openid
- offline_access
- files:read
audience is empty by default, so resolved clients can't request an audience until you configure one. scope defaults to
openid and offline_access, which allows a login with refresh tokens. It must contain at least one scope. With these defaults,
MCP clients cannot connect: they send a resource and request the MCP server's scopes, so set both before you enable client ID
metadata documents for MCP.
Block a client ID metadata document
To stop Hydra from resolving a metadata URL, for example after the application's keys or domain are compromised, register a client with that URL as its ID. A registered client takes precedence over the document, so the block applies immediately on every Hydra instance.
Register a client that nobody can use: it has no redirect URIs and authenticates with a secret that you discard.
curl -X POST "$HYDRA_ADMIN_URL/admin/clients" \
-H 'Content-Type: application/json' \
-d '{
"client_id": "https://app.example.com/oauth/client-metadata.json",
"client_name": "Blocked: app.example.com",
"grant_types": ["authorization_code"],
"response_types": ["code"],
"token_endpoint_auth_method": "client_secret_basic"
}'
Don't store the client_secret from the response. With this client in place:
- New authorization requests fail with
invalid_request, because the client has no redirect URIs. - Refresh requests fail with
invalid_client, because the client now has to authenticate with a secret the application doesn't have. - Access tokens that were already issued stay valid until they expire. To revoke them now, delete them:
curl -X DELETE "$HYDRA_ADMIN_URL/admin/oauth2/tokens?client_id=https%3A%2F%2Fapp.example.com%2Foauth%2Fclient-metadata.json"
JWT access tokens can't be revoked this way and stay valid until their exp claim passes.
To give an application your own configuration instead of blocking it, register the client with the redirect URIs, grants and authentication method you want. Hydra then uses that client and ignores the document.
Deleting the blocking client doesn't unblock the URL right away, because
the ID of a deleted client stays reserved. After the deletion grace period, run
hydra janitor --clients to release the ID. The document is then used again.
How Hydra fetches and caches documents
Hydra reuses a document for as long as its Cache-Control header allows, but at least five minutes and at most one hour. When the
document's host is unavailable or refuses the request, for example with 403, 429, or 503, Hydra keeps using the last valid
document for up to a day longer. When the host answers 404 or 410, redirects, or serves an invalid document, Hydra stops using
the previous document. Each Hydra instance keeps its own copy, so an instance that hasn't fetched a document yet can't use it
while the host is down.
Each instance fetches at most 20 documents at once, and at most two from one domain, such as example.com for app.example.com
and docs.example.com. A fetch times out after five seconds. This keeps a slow domain from delaying the documents of other
domains.
Publish a metadata document
Serve a JSON document at a stable HTTPS URL, such as https://app.example.com/oauth/client-metadata.json:
{
"client_id": "https://app.example.com/oauth/client-metadata.json",
"client_name": "Example application",
"redirect_uris": ["https://app.example.com/callback"],
"token_endpoint_auth_method": "none",
"grant_types": ["authorization_code", "refresh_token"],
"response_types": ["code"]
}
The document's client_id must exactly match its URL. The URL must have a non-root path, must not contain credentials, a
fragment, or . or .. path segments, and must be at most 255 bytes long. Serve the document from a domain name with a public
address, directly and without redirects, and keep it under 5 KiB.
Hydra uses only HTTPS redirect URIs on the same origin as the metadata URL. Native applications can also use HTTP loopback
redirect URIs or reverse-domain private-use schemes such as com.example.app:/callback. Hydra ignores every other entry, such as
HTTPS redirect URIs on other hosts, plain HTTP on a public host, or private-use schemes of another shape. A document that leaves
no usable redirect URI is rejected. The authorization request must match a declared redirect URI according to Hydra's
redirect-matching rules.
CIMD supports the authorization code flow, optional refresh tokens, and public subject identifiers. The document's grants must
also be enabled on the server. A refresh token requires the offline_access scope, and the user must consent to it.
For client authentication, use none for public clients or private_key_jwt with public keys in jwks or an HTTPS jwks_uri. A
jwks_uri must be on the same origin as the metadata URL. Hydra fetches the metadata document itself without following any
redirect, and fetches a jwks_uri following only redirects that stay on that same origin. A document can instead list the methods
it supports in token_endpoint_auth_methods_supported. Hydra then uses private_key_jwt if the list includes it and the document
publishes keys, otherwise none if the list includes it, and rejects the document if neither applies. If a document sets both
fields, the declared method must be in the list. A key set at jwks_uri must meet the
requirements for client key sets. Client secrets and symmetric authentication
methods are not supported. A document cannot set administrative options such as skip_consent, and Hydra ignores its metadata,
audience and scope, as described in
Set the audience and scopes of resolved clients.
Start an authorization flow
Configure your OAuth2 client library with the metadata URL as its client ID and a redirect URI from the document. Use the normal
/oauth2/auth and /oauth2/token endpoints. CIMD requires PKCE, including for clients using private_key_jwt: send an S256 code
challenge in the authorization request and the matching verifier when exchanging the code.
The application's name is self-asserted. In a custom login or consent UI, display the hostname of a client_id that is an HTTPS
URL alongside client_name, so users can identify the application requesting access.
Hydra removes control and formatting characters, such as bidirectional overrides, from client_name. If the name is empty or
longer than 100 characters, Hydra uses the client_id hostname instead. logo_uri, client_uri, policy_uri and tos_uri are
kept only if they use HTTPS. Hydra keeps up to 10 contacts and drops entries longer than 254 characters or containing control or
formatting characters.
Update client metadata
Update the hosted document to change the application's metadata. Changes take effect within one hour, or sooner if the document's
Cache-Control header allows it. There is no API call to update these clients.
Signing keys at a jwks_uri follow the same rules as for registered clients, see
Caching of client key sets. Inline jwks only change together with the document,
so publish a new public key at least one hour before signing with it, and remove the previous key after that.
Removing the document stops the client within one hour. From then on, new authorizations fail, refresh tokens stop working, and
opaque access tokens introspect as inactive. JWT access tokens stay valid until they expire. The same happens when the document's
host stays unreachable for more than a day, or when you change mode so that the URL is no longer allowed. To stop a client
immediately, block it.
Limits of clients resolved from a document
Some features aren't available for clients that use a metadata document:
- Logout isn't supported. Logout with
id_token_hintdoesn't work for these clients, and documents can't declarepost_logout_redirect_uris,frontchannel_logout_uri, orbackchannel_logout_uri. - Per-client CORS isn't supported, and documents can't declare
allowed_cors_origins. Use the global CORS settings for browser-based applications.
Example OAuth2 clients
Here are some examples of creating OAuth2 clients with different options:
Client credentials
ory create oauth2-client \
--grant-type client_credentials \
--scope my-scope \
--token-endpoint-auth-method client_secret_basic
Token endpoint auth method
ory create oauth2-client \
--grant-type authorization_code \
--response-type code \
--scope openid \
--token-endpoint-auth-method client_secret_post \
--redirect-uri https://my-app.com/callback
Multiple redirect URIs
ory create oauth2-client \
--grant-type authorization_code --grant-type refresh_token \
--response-type code \
--scope openid --scope offline_access \
--token-endpoint-auth-method client_secret_post \
--redirect-uri https://my-app.com/callback --redirect-uri http://my-other-app.com/callback