I am currently using Feign, a declarative REST client, with OAuth2 in my Spring Boot (Kotlin) application. To specify the client provider and registration, I use the application.yml properties file with the grant_type set to client_credentials and the token-uri endpoint set to https://url/oauth/token.
Error:
A 403 (Forbidden) error message stating that No audience parameter was provided... because the audience attribute is missing from the request body.
Is it possible to add the audience attribute with a URL value to the token request using FeignClient and OAuth2 in Spring Boot (Kotlin) via configuration properties or do I need to create a custom bean?
I have tried adding the audience attribute using custom parameters in the header and query params, but this did not work. https://docs.spring.io/spring-security/reference/servlet/oauth2/index.html#oauth2-client-customize-request-parameters
I need to add the audience attribute with a value to the request body of the token request.
To enable OAuth2 support, I am using this: https://docs.spring.io/spring-cloud-openfeign/docs/current/reference/html/#oauth2-support.
To add the audience attribute to the request body, I need to provide it in the following format:
POST call to /oauth/token:
{
"grant_type": "client_credentials",
"client_id": "id",
"client_secret": "secret",
"audience": "https://url"
}
The response should be in the following format:
{
"access_token": "token",
"expires_in": 86400,
"token_type": "Bearer"
}
Good to mention that I'm not the owner of the Authentication (0Auth) server and therefore cannot provide a default audience or make any changes.