Context

What are you trying to accomplish?

I am trying to use spring-boot-starter-oauth2-client to get a bearer token, where the service is accepting grant_type=client_credentials and not authorization-grant-type.

What other alternatives have you considered? Are you aware of any workarounds?

We are authenticating against a third-party service that will provide the token.

if we do this:

String authStr = "theusername:thepassword";
        String base64Creds = Base64.getEncoder().encodeToString(authStr.getBytes());

        final MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
        params.add("Authorization", "Basic " + base64Creds);

        Consumer<HttpHeaders> consumer = it -> it.addAll(params);
        Map tokenMap = restClient.post()
                .uri("https://thirdpartyservice.com/token?scope=resolve+download&grant_type=client_credentials")
                .contentType(MediaType.APPLICATION_FORM_URLENCODED)
                .headers(consumer)
                .retrieve()
                .body(Map.class);
        System.out.println(tokenMap.get("access_token"));
curl -s -X POST -H "Content-Type: application/x-www-form-urlencoded" -u theusername:thepassword  "https://thirdpartyservice.com/token?scope=resolve+download&grant_type=client_credentials" | jq -r '.access_token'

Above would work and give up the correct token, which we can use to request a resource server.

We saw Dan Vega's cool video https://www.youtube.com/watch?v=nFKcJDpUuZ8 and wanted to try spring-boot-starter-oauth2-client.

We following his example, we configured as follow:

@Configuration
public class RestClientConfig {

    @Bean
    public RestClient restClient(OAuth2AuthorizedClientManager authorizedClientManager) {
        OAuth2ClientHttpRequestInterceptor interceptor = new OAuth2ClientHttpRequestInterceptor(authorizedClientManager);
        return RestClient.builder()
                .requestInterceptor(interceptor)
                .build();
    }

}
return restClient.get()
                .uri("https://resource...")
                .attributes(clientRegistrationId("my-client"))
                .retrieve()
                .body(String.class);
spring:
  application:
    name: client-application
  security:
    oauth2:
      client:
        registration:
          my-client:
            provider: the-provider
            client-id: theusername
            client-secret: thepassword
            authorization-grant-type: client_credentials
            #grant_type: client_credentials
            scope: resolve+download
        provider:
          the-provider:
            token-uri: https://thirdpartyservice.com/token
logging:
  level:
    root: DEBUG

Expected Behavior

We expected this would work

Current Behavior

Unfortunately, this is not working, as the token provider returns 400 error, as it is expecting grant_type.

We tried to replace configuration with "grant_type: client_credentials" but would get Caused by: java.lang.IllegalArgumentException: authorizationGrantType cannot be null

Question: Would it be possible to enhance spring-boot-starter-oauth2-client to change the key authorization-grant-type to grant_type?

Thank you for you time.