Код: Выделить всё
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'
Следуя документу о безопасности Spring, я настраиваю:
Код: Выделить всё
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
Код: Выделить всё
@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 Security предлагает только «authorization-grant-type»
Вопрос: Как передать Grant_type с помощью RestClient и Spring-boot-starter-oauth2-client?
Подробнее здесь: https://stackoverflow.com/questions/793 ... restclient
Мобильная версия