OAuth2FeignRequestInterceptor不支持服务注册和发现
@Bean
@ConfigurationProperties(prefix = "security.oauth2.client")
public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {
return new ClientCredentialsResourceDetails();
}
@Bean
public RequestInterceptor oauth2FeignRequestInterceptor(){
return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails());
}
地址固定例子
security:
oauth2:
client:
clientId: account-service
clientSecret: 123456
accessTokenUri: http://192.168.199.218:5000/uaa/oauth/token
grant-type: client_credentials
scope: server
以上调用地址不能用上服务注册发现,也不能用ribbon的负载均衡功能了
希望使用服务注册发现
security:
oauth2:
client:
clientId: account-service
clientSecret: 123456
accessTokenUri: http://auth-service/uaa/oauth/token
grant-type: client_credentials
scope: server
如果这里授权地址配置为服务注册的服务名称,OAuth2FeignRequestInterceptor里的RestTemplate不支持SERVICE_NAME方式,这个问题等待spring cloud官方解决吧。