Support for RFC 8707 OAuth2 Resource Indicators #35743
Replies: 9 comments 5 replies
-
|
I am the contributor of resource request parameter and audience in access token PR. Thanks @thomasdarimont for your work and detail post. By the way, the original issue is wrong. Keycloak correctly support audience request parameter only for Token Exchange (most commonly used than resource for Token Exchange. Based on 2.1 of OAuth 2.0 Token Exchange, both audience and resource should be possible. It is complex. We may leave it out of first implementation. What will be done for token exchange with resource and audience based on your PR @thomasdarimont ? Unfortunately, @stianst has closed my more detailed issue. @mposolda has proposed 'use the approach based on protocol mapper'. So, your PR approach. We like that you have added also URI checks. Although we do not support it now, it is nice to have it. The most important for us is supporting Resource Indicators. Way is less important. We propose continuing reviewing your PR. PS. JSON Web Token (JWT) Profile for OAuth 2.0 Access Tokens mentions aud as required parameter in access token. We have proposed also Keycloak supporting this with an optional default value (no migration needed) if aud does not exist. |
Beta Was this translation helpful? Give feedback.
-
|
New use case: |
Beta Was this translation helpful? Give feedback.
-
|
FYI the way to configure allowed resource indicators via the authorization services resources is similar to what Ping Federate offers: |
Beta Was this translation helpful? Give feedback.
-
|
@thomasdarimont Also, in section 2.5.1.1 Canonical Server URI, it states that
which might means that supporting RFC 8707 by an Authorization Server is not mandatory. What do you think about that? |
Beta Was this translation helpful? Give feedback.
-
|
Hello there! :) what is the status of this? @thomasdarimont |
Beta Was this translation helpful? Give feedback.
-
|
The latest 2025-06-18 MCP authorization specification requires the use of OAuth2 Resource Indicators. From the Note about Resource Indicators from Quarkus MCP OIDC Client blog post. |
Beta Was this translation helpful? Give feedback.
-
|
I have an alternative proposal for resource indicators that is aiming to be more aligned with existing mechanisms for audience scoped tokens in Keycloak: Resource indicator support could be implemented many different ways in Keycloak; in fact there are at least 3 pull requests already:
One challenge with the above pull requests is not aligning well with how audience scopes tokens can already be issued by Keycloak today. Keycloak supports two mechanisms currently to audience scope tokens:
Taking the current support for audience scoped tokens in Keycloak today the ideal would be to introduce resource indicators in a similar fashion. At a very high-level this proposal introduces two things:
This effectively leaves client scopes and protocol mappers unchanged and makes behaviour consistent with token exchange. Starting very simple if we support a single resource parameter in the request that allows specifying the target client with In this case we will simply filter the values of the Evolving on the above we want to support Supporting multiple resource parameters in a request follows the same pattern as token exchange; when processing the audience values we simply check if there is a resource parameter that matches, and include all audience values that have a matching resource parameter. The next question is the format of the value in the The full implementation would be:
Processing of tokens in token manager would do the following:
Making things a little bit more complicated we want to support multiple If the client requests A benefit to this approach compared to other proposals is flexibility in terms of clients can leverage multiple mechanisms for audience scoping tokens while all result in the same behaviour and does not require additional configuration through extra protocol mappers, etc. As a follow-up later on when we introduce more formal linking of clients and services; as well as services being able to advertise the format of tokens they expect; we can then allow the client to select what audience included using different mechanisms (scope, aud, or resource parameters), while at the same time allow services to decide what value(s) they require in the aud claim. For example a client may request Proposed milestonesWe’ll want to break the implementation of resource indicators into multiple parts aka milestones, rather than deliver it all in a single pull request. Milestone 1 - Support resource=urn:client:<client-id>This milestone aims to be the initial wiring of supporting resource indicators and we will only support the simplest case of a resource indicator that matches a client by client-id. In this milestone we know that resource parameters should behave exactly like audience parameters in token exchange. Milestone 2 - Support URLs as resource valuesAdd support to configure a Resource URL for a client; which then allows a client to use resource parameter values matching the resource URL of a client included in the audiences of the token. Milestone 3 - Support multiple resource parametersUpdate authorization and token request handling to support multi-valued parameters. Milestone 4 - Support multiple Resource URIs per-clientAdd support to configure more than a single Resource URI for a client; and/or support sub-resources (from the wildcard example earlier). Milestone 5 - Add support for resource parameters to token exchangeSupport both aud and resource parameters in token exchange, including a combination of both at the same time. |
Beta Was this translation helpful? Give feedback.
-
|
The issue for resource indicators has been updated with more details: |
Beta Was this translation helpful? Give feedback.
-
|
Very rough PoC for the above proposal: #46763 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
This discussion aims to arrive at a design proposal to properly support RFC 8707 Resource Indicators for OAuth 2.0 as a feature for Keycloak.
Resource Indicators allow the restriction of Access Tokens for Resource Servers to specific resources, enabling fine-grained control over an access token's capability.
A part of the functionality enabled by the Resource Indicators could also be solved with scopes, however the audience
audclaim is be used to express the systems whereas thescopeclaim is often used to express the capabilities / permissions associated with a token.Supporting Resource Indicators in Keycloak includes the following requirements:
resourceparametersresourceparametersresourceindicator valueRelated issues:
Considerations for R1)
According to RFC 8707 Section 2, the value of the
resourceparameter must be an absolute URI, howeverRFC 8707 Section 2also later says:'...the parameter value identifies a resource to which the client is requesting access. The parameter can carry the location of a protected resource, typically as an HTTPS URL or a more abstract identifier....', which might also allow custom schemes, e.g.,
acme://foo.Since the resource indicator support is about managing the audience
audclaim, we might need to allow to use aclient_idas resource indicators. This eases using the resource indicator support in existing Keycloak ecosystems, without having to assign resource indicators to resource servers / clients managed by Keycloak.Currently, Keycloak does not support configuring allowed resource URIs for a registered client, which can act as an OAuth 2.0 resource server.
However, support for restricting the resource identifiers is crucial to supporting the resource identifiers feature.
Some requirements for specifying resource identifiers:
Considerations for R2)
An authorization request might contain one or more
resourceparameters. Currently, Keycloak does not support repeated request parameters; therefore, the parameter processing in services/src/main/java/org/keycloak/protocol/oidc/endpoints/request/AuthzEndpointRequestParser.java and related code must be updated to allow multipleresourceparameters.The validation of the authorization request parameters must be extended to include a check for the requested
resourceparameters against the set of allowed resource identifiers.The initially requested resource values must be available for later processing by the token endpoint handling. One way to solve this is to store the requested resource identifiers in the client session.
Considerations for R3)
The token endpoint must be extended to support the resource parameter in the token request. Additionally, it must support validating the requested resource(s) against the resources previously associated with the authorization code grant stored in the client session.
Considerations for R4)
To adjust the audience
audclaim in the access token based on the requested resource, we can use a custom OIDC protocol mapper. A suitable name for the protocol mapper might beResource Identifier Mapper.Usage example
For example, we use a
photozSaaS application comprising multiple services that expose various parts of user data.We now imagine that we have a
photozclient configured in Keycloakthat allows the following resource identifiers, which represent the internal resource servers / or logical resources:
https://api.acme.com/accountshttps://api.acme.com/photoshttps://api.acme.com/gallerieshttps://api.acme.com/invoiceshttps://api.acme.com/paymentshttps://api.acme.com/ordersNote that this denotes an abstract list of resource types. Resources could also refer to more concrete resources, e.g.,
https://api.acme.com/photos/42.Authorization request
We want our application to have access to photos and accounts of the
photozservice.The following authorization request will register the allowed resource identifiers
https://api.acme.com/photosandhttps://api.acme.com/gallerieswith the client session created after successful end-user authentication.Note that this authorization request determines which resources a client can request access to in subsequent token requests. In this example, the application can only request access to photos and galleries but no other resources.
Request Token for accessing photos
The application wants an access token that supports accessing the photos resource. To do this, it sends the following token request:
Access Token for accessing photos
The returned access token now contains the following
audaudience claim:Note that due to checks in the
photosapplication backend, this Token does not allow access to other resources like gallery, etc.Request Access Token for accessing photos & galleries
Now, the application also wants to access information about registered galleries.
This requires us to upgrade the audience claim, by adding
https://api.acme.com/galleries.To do this, it sends the following token refresh request:
Access Token for accessing photos and galleries
The returned access token now contains the following
audaudience claim:Note that this Token now allows access to photos and gallery resources.
It is also possible to obtain an access token that can only access galleries but no photos:
Request Access Token for accessing galleries only
Now, the application also wants to downgrade the token access to only access galleries.
This requires us to downgrade the audience claim, by removing
https://api.acme.com/photos.To do this, it sends the following token refresh request:
Access Token for accessing photos and galleries
The returned access token now contains the following
audaudience claim:Note that this Token now allows access to photos and gallery resources.
It is also possible to obtain an access token that can only access galleries but no photos:
Attempt to Access Token for other resources
If the application attempts to access other resources, which were not part of the initial authorization request, this request will fail, because the requested resource
https://api.acme.com/invoiceswas not part of the initial request.Access Token Error Response
Implementation options
O1) Using a Protocol Mapper to define allowed clients to solve R1
Idea: Use the configuration of the
Resource Identifier MapperOIDC protocol mapper that is necessary to adjust the audience based on the requested resources to also store the list of allowed resource identifiers per client.Example Resource Identifier Mapper configuration with Resource Identifiers

Pros:
resourceparameter handling is enabled. If the mapper is not configured for a client, then requests with aresourceparameter will be rejected.Cons:
O2) Add direct support for configuring resource identifiers for clients to solve R1
Idea: Users can specify allowed resource identifiers directly on the client configuration. This could be implemented similarly to how allowed redirect URIs are configured, e.g., using a
resource_identifierstable similar to how the "Allowed redirect URIs" are stored in theredirect_uristable. However, for better database usage, we should add a realm column.Note that this approach would include changes to the admin UI to allow configuring the set of permitted resource identifiers.
Example for custom client configuration with additional resource identifiers list:

Pros:
Cons:
O3) Leverage resource definitions from authorization services to solve R1
Idea: Use the existing authorization services to express client specific resource identifiers.
We could use a custom resource type like: urn:keycloak:resource-identifier to declare a resource identifier. The actual resource identifier can be expressed via the resource identifier URI(s). Support for finding a client by a resource identifier could be implemented on top of resource lookup against the authorization services.
Definition of a photo resource identifier:

Overview of allowed resource identifiers:

Pros:
Cons:
O4) Add new dedicated SPI to validate allowed resource indicators R1, R5
Idea: Introduce a
OAuth2ResourceIndicatorResolverSPI that allows users to implement their ownResource Indicator validation mechanisms. In order to allow client specific behaviour uses could use a client attribute to select
a specific OAuth2ResourceIndicatorResolver implementation.
This spi could also support to lookup a client by a resource indicator.
Pros:
Cons:
O5) Use a Validator to to check for allowed resource indicators R1
Idea: Use a org.keycloak.validate.Validator for resource indicators to check if given resource indicator is allowed for a client.
In order to allow client specific behaviour uses could use a client attribute to select a specific Validator implementation.
Pros:
Cons:
Existing implementation proposals
What do you think about adding Resource Server support? Feedback and remarks are very welcome :)
Beta Was this translation helpful? Give feedback.
All reactions