Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding 'audience' to ClientRegistration for OAuth2.0 client-credentials flow #7379

Closed
j-chao opened this issue Sep 5, 2019 · 5 comments
Closed
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: invalid An issue that we don't feel is valid

Comments

@j-chao
Copy link

j-chao commented Sep 5, 2019

Summary

There doesn't seem to be a way to specify the audience/resource server for a token request to an authorization server via client-credentials grant-type flow.

Actual Behavior

There is no way obvious way to define the audience of the token, when requesting for a token.

Expected Behavior

There should be a way to specify an 'aud' with the creation of the ClientRegistration object.

Configuration

Spring Boot 2.2.0.M4 project
Java 12
maven

Version

Spring Security 5.2.0.M3

Sample

The payload of the jwt token that is returned should contain the audience as specified in the request. ie:

Request:

curl -X POST \
  https://login.microsoftonline.com/31f52c3f-25dd-415f-b9b9-36a2e0391777/oauth2/token \
  -d 'grant_type=client_credentials&client_id=<my_client_id>&client_secret=<my_client_secret>&resource=https%3A%2F%2Fmy-resource.com'

Payload of returned JWT token:

{
  "aud": "https://my-resource.com",
  "iss": "https://sts.windows.net/31f52c3f-25dd-415f-b9b9-36a2e0391777/",
  "iat": 1567705779,
  "nbf": 1567705779,
  "exp": 1567709679,
  ...
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 5, 2019
@jgrandja
Copy link
Contributor

jgrandja commented Sep 9, 2019

@j-chao The aud claim in a JWT will only be returned depending on the Authorization Server configuration for the Client. The Client can only request one or more scope, as per the Client Credentials Access Token Request, and based on the requested scope(s) the Authorization Server will assigned one or more aud in the returned JWT.

So assigning an aud to a ClientRegistration doesn't make sense here as it will be completely ignored (or rejected) by a standard Authorization Server. Take a look at the Client Registration metadata in the Authorization Server in combination with the scope registered and requested by the Client.

I'm going to close this as answered.

As an FYI, there is a way to customize the Access Token request for non-standard parameters (resource). See the documentation for DefaultAuthorizationCodeTokenResponseClient which would be very similar to how DefaultClientCredentialsTokenResponseClient would be customized.

@jgrandja jgrandja closed this as completed Sep 9, 2019
@jgrandja jgrandja self-assigned this Sep 9, 2019
@jgrandja jgrandja added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 9, 2019
@ahezzati
Copy link

ahezzati commented May 21, 2020

@jgrandja some authorization servers like Auth0 mandates "audience" in the request body, if it is not there it returns "Non-global clients are not allowed access to APIv1" failure message. https://medium.com/@svkristof_86488/non-global-clients-are-not-allowed-access-to-apiv1-88877f1e855b

The work around I did was to put property for each audience, all of them have the same key value except the last value should match registrationId, and I made the concatenation in my custom Converter<OAuth2ClientCredentialsGrantRequest, RequestEntity<?>> where I add "audience" as a form parameter.
Example will be: myapplication.audience.abc=audience1, myapplication.audience.xyz=audience2 where (abc) and (xyz) are registrationIds.

It works but it will be better if it is supported out-of-the-box from Spring Boot.

@pierre-sion
Copy link

Postman offers the possibility to customize the "audience" and "resource" parameters when requesting a token using the client-credentials flow. It shows that there is a need for such a feature.

@Biglr
Copy link

Biglr commented Jul 13, 2022

@jgrandja some authorization servers like Auth0 mandates "audience" in the request body, if it is not there it returns "Non-global clients are not allowed access to APIv1" failure message. https://medium.com/@svkristof_86488/non-global-clients-are-not-allowed-access-to-apiv1-88877f1e855b

Yeah, I had the same problem. It would be great if this could be added to spring security, would've saved me a couple of hours of debugging, digging and frustration...

If any one should require some assistance, let me know. I might be able to save you some time

@wujek-srujek
Copy link

Please consider reopening this and implementing this feature. Especially since the 'status: invalid' label is invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

7 participants