OAuth2 token audience
There are two types of audience concepts in OAuth 2.0 and OpenID Connect:
- OAuth 2.0 access token audience: OAuth 2.0 access tokens are "internal-facing". In other words, the
audclaim of an OAuth 2.0 access token defines the endpoints at which the token can be used. - OpenID Connect ID token audience: OpenID Connect ID tokens are "external-facing". The
audclaim of an OpenID Connect ID Token defines which clients should accept it.
Add audiences to the client allow list
To specify the intended audiences for an OAuth 2.0 access token, the OAuth 2.0 client needs to proactively define the audiences it needs access to when creating or updating the client. This can be done by including the audience parameter in the client's metadata.
The audience parameter is a list of case-sensitive URLs. The URLs can't contain whitespaces.
{
client_id: "...",
// ..
audience: ["https://api.my-cloud.com/user", "https://some-tenant.my-cloud.com/"],
// ..
}
If you're a developer looking to manage OAuth2 clients, you can find more information in the Manage OAuth2 Clients document.
Clients that register through OpenID Dynamic Client Registration can set audience. If they omit it or send null, they receive
the configured default audience. An explicit empty list remains empty. See
Set the audience of dynamically registered clients.
Audience in Authorization Code, Implicit, and hybrid flows
When performing an OAuth 2.0 Authorization Code Grant, Implicit Grant, or hybrid flow, developers can request audiences at the
/oauth2/auth endpoint using the audience query parameter:
https://$PROJECT_SLUG.projects.oryapis.com/oauth2/auth
?client_id=...
&scope=...
&audience=https://api.my-cloud.com/user+https://some-tenant.my-cloud.com/
The audience query parameter can contain multiple strings separated by a URL-encoded space (+ or %20). The audience values
must also be URL-encoded.
The values are validated against the allowed audiences defined in the OAuth 2.0 client. For instance, if an OAuth 2.0 client
allows the audience https://api.my-cloud/user, it can request audience values like https://api.my-cloud/user or
https://api.my-cloud/user/1234, but not https://api.my-cloud/not-user or https://something-else/.
Path prefix matching applies to hierarchical URIs with a matching scheme and host, such as https://api.my-cloud/user. An opaque
URI, such as a URN like urn:my-cloud:user, has no host or path and must match an allow list entry exactly. A client that allows
urn:my-cloud:user can request urn:my-cloud:user, but not urn:my-cloud:user:1234 or urn:my-cloud:other.
The requested audience from the query parameter is then part of the login and consent request payload as the field
requested_access_token_audience. Developers can then alter the audience using grant_access_token_audience when accepting the
consent request. For example:
// Copyright © 2026 Ory Corp
import { Configuration, OAuth2Api, OAuth2ConsentRequest } 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,
}),
)
// Older SDK releases do not declare the RFC 8707 field yet.
export type ConsentRequestWithResources = OAuth2ConsentRequest & {
requested_resources?: string[]
}
export function grantedConsentAudience(request: ConsentRequestWithResources) {
const allowedAudiences = request.client?.audience ?? []
return (request.requested_access_token_audience ?? [])
.concat(
(request.requested_resources ?? []).filter(
(resource) => allowedAudiences.indexOf(resource) >= 0,
),
)
.filter((audience, index, all) => all.indexOf(audience) === index)
}
export async function acceptConsent(consentChallenge: string) {
const { data } = await ory.getOAuth2ConsentRequest({ consentChallenge })
return await ory
.acceptOAuth2ConsentRequest({
consentChallenge: consentChallenge,
acceptOAuth2ConsentRequest: {
// Ask the user before granting these values. This example applies the same
// exact client-audience allow-list policy as Ory's built-in consent apps.
grant_access_token_audience: grantedConsentAudience(data),
},
})
.then(({ data }) => data)
}
When introspecting the OAuth 2.0 Access Token, the response payload includes the audience:
// 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 introspectToken(accessToken: string) {
const { data } = await ory.introspectOAuth2Token({ token: accessToken })
console.log(data.aud)
}
Audiences when refreshing tokens
Each refresh request to /oauth2/token validates the audiences that were both requested with audience and granted by the
consent app against the client's current allow list, using the same matching rules as the authorization request. If any of them is
no longer allowed, refresh fails with invalid_request before issuing tokens or rotating the refresh token. The same refresh
token works again after the allow list permits those audiences.
The consent app may grant additional audiences outside the client's allow list, or omit requested audiences from the grant. Audiences that were not both requested and granted do not cause refresh to fail, and refreshed access tokens retain the full granted audience. To withdraw a consent-added grant, revoke the grant or refresh token.
Audiences in Client Credentials Grant
When performing the Client Credentials Grant, the audience parameter from the POST body of the /oauth2/token request is
decoded and validated according to the rules described in the previous section, excluding login and consent, which are not a part
of this flow.
Target an access token to a resource
RFC 8707 resource indicators let a client request an access token for specific
protected resources, such as MCP servers. The client sends one resource parameter per resource:
https://$PROJECT_SLUG.projects.oryapis.com/oauth2/auth
?client_id=...
&response_type=code
&resource=https%3A%2F%2Fcalendar.example.com
&resource=https%3A%2F%2Fcontacts.example.com
Each value must be an absolute URI without a fragment and must exactly match an entry in the client's audience allow list. Ory
Hydra Authorization doesn't normalize or prefix-match resources. Invalid or unauthorized values fail with invalid_target.
Choose between audience and resource
The audience parameter is specific to Ory and predates RFC 8707. The resource parameter is the standard, and MCP clients send
it. Use resource for new clients. Keep audience only for existing integrations, or if you need its prefix matching. While
resource indicators are turned off, only audience sets the token audience.
Before you turn it on
- Add every resource URI your clients request to each client's
audienceallow list. For clients that use dynamic client registration, such as MCP clients, set the default audience for dynamic client registration. - If you use a custom consent app, update it to grant resources as described in Grant resources in the consent app.
Turn on resource indicators
- Ory Network: New projects have resource indicators turned on. For existing projects, use the Enable OAuth2 for MCP
toggle in OAuth 2 → General in the Ory Console, or set
services.oauth2.config.feature_flags.resource_indicators_enabledtotruethrough the project API. - Self-hosted Ory Hydra: Resource indicators are off by default. To turn them on, set
feature_flags.resource_indicators_enabledtotrue, orFEATURE_FLAGS_RESOURCE_INDICATORS_ENABLED=true.
While resource indicators are off, Ory Hydra Authorization ignores resource.
We intend to remove the resource_indicators_enabled flag and turn resource indicators on for everyone in a later release.
Migrate your clients and consent apps before then.
Grant resources in the consent app
The consent request lists the requested resources in requested_resources. To approve a resource, add its exact URI to
grant_access_token_audience:
{
"grant_scope": ["read"],
"grant_access_token_audience": ["https://calendar.example.com", "https://contacts.example.com"]
}
Grant at least one requested resource, on both the normal and the skipped-consent path. If you grant none, the flow fails with
invalid_target. Copying requested_access_token_audience isn't enough, because it doesn't contain the requested resources.
The consent screens built into Ory Network grant either all requested resources or none. To let users approve only some of them, use a custom consent app.
Select resources at the token endpoint
When you exchange an authorization or device code, or refresh a token, you can repeat resource to narrow the access token to
some of the granted resources:
curl --request POST https://$PROJECT_SLUG.projects.oryapis.com/oauth2/token \
--data-urlencode grant_type=authorization_code \
--data-urlencode code=... \
--data-urlencode resource=https://calendar.example.com
The access token then contains only the selected resources:
{
"aud": ["https://calendar.example.com"]
}
If you omit resource, the access token contains the full granted audience. The refresh token always keeps the full grant, so a
later refresh can select a different granted resource. A resource server must verify that its own URI appears in aud.
Behavior details
- Request objects: When the authorization request uses
requestorrequest_uri, aresourceclaim in the request object replaces anyresourcequery parameters. If the request object has noresourceclaim, the query parameters are used. audienceandresourcetogether: Both end up in the same granted audience.audiencekeeps prefix matching, whileresourcerequires an exact match. Onlyresourcenarrows the access token at the token endpoint.- Audiences added by the consent app: These are included when the token request omits
resource. A client can't select them explicitly unless they're also in its allow list. - Refresh after allow list changes: Refresh rechecks only audiences that were requested with
audienceand granted, as described in audiences when refreshing tokens. Granted resources are not rechecked, but aresourceparameter on the refresh request must still be an exact entry in the client's current allow list, or refresh fails withinvalid_target. Removing a resource from the allow list doesn't affect existing grants. To withdraw a granted resource, revoke the consent session or the refresh token. - Implicit and hybrid flows: The access token receives the requested resources that were also granted.
- Changing the setting during a flow: Each request uses the current setting, so turning resource indicators on or off can affect authorization and device flows that are already in progress.