Getting a management API token using client_credentials grant with Spring WebFlux WebClient

Hello all,

I am trying to implement the client_credentials grant to get a token in my spring boot resource server. I have tried to do the request through postman and it works. The problem I am facing is that i have no way to add the missing audience parameter to the token request.

I have the client filter configured like this.

WebClient webClient(ReactiveClientRegistrationRepository clientRegistrations,
                    ServerOAuth2AuthorizedClientRepository authorizedClients) {
    ServerOAuth2AuthorizedClientExchangeFilterFunction oauth2 = new ServerOAuth2AuthorizedClientExchangeFilterFunction(
            clientRegistrations, authorizedClients);
    return WebClient.builder()

I am injecting the instance and trying to do a request to get the user by email

 return this.webClient.get()
            .uri(this.usersUrl + "/api/v2/users-by-email?email={email}", email)

Is there a way to skip the need to add the audience parameter or a way to add it to the webclient request in the filter function?

Not sure about Spring’s ServerOAuth2AuthorizedClientExchangeFilterFunction, but in case it helps (or if you have no other choice :slight_smile: ) you can use auth0-java's requestToken method to get a token:


AuthRequest request = auth.requestToken("https://{YOUR_DOMAIN}/api/v2/");
try {
    TokenHolder holder = request.execute();
} catch (APIException exception) {
    // api error
} catch (Auth0Exception exception) {
    // request error