com.feingto.cloud.config.feign.AuthClientConfiguration Maven / Gradle / Ivy
package com.feingto.cloud.config.feign;
import com.feingto.cloud.config.annotation.ExcludeComponentScan;
import feign.Contract;
import feign.Logger;
import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.cloud.security.oauth2.client.feign.OAuth2FeignRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.client.OAuth2ClientContext;
import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails;
/**
* Feign OAuth2 配置
*
* @author longfei
*/
@Slf4j
@Configuration
@ConditionalOnBean(annotation = FeignClient.class)
@ExcludeComponentScan
public class AuthClientConfiguration {
@Bean
public Contract feignContract() {
return new feign.Contract.Default();
}
@Bean
@ConditionalOnProperty(name = "security.oauth2.client.grant-type", havingValue = "client_credentials")
public RequestInterceptor oauth2FeignRequestInterceptor(OAuth2ClientContext oAuth2ClientContext,
ClientCredentialsResourceDetails resource) {
return new OAuth2FeignRequestInterceptor(oAuth2ClientContext, resource);
}
@Bean
public Logger.Level feignLoggerLevel() {
return Logger.Level.FULL;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy