Spring cloud feign Security consumer calls 401

return authentication error
Full authentication is required to access this resource

when using feign consumer to call provider

detailed error
{"timestamp": 1524018915085, "status": 401, "error": "Unauthorized", "message": "Full authentication is required to access this resource", "path": "/ activity-provider-service/user/add/12312321"}

Direct access to the provider can be successful, and this error will be reported by invoking the provider service through the consumer

if you turn off security authentication, you can access it successfully

clipboard.png

clipboard.png

clipboard.png

clipboard.png

Mar.07,2021

have you solved


solution add interceptor

  1. add yml profile
security:
  oauth2:
    client:
      clientId: yourClientId
      clientSecret: yourClientSecret
      accessTokenUri: http://localhost:3000/oauth/token
      grant-type: client_credentials
      scope: service
    resource:
      user-info-uri: http://localhost:3000/me
  1. write Feign interceptor
@Configuration
public class FeignConfig {
    @Bean
    @ConfigurationProperties(prefix = "security.oauth2.client")
    public ClientCredentialsResourceDetails clientCredentialsResourceDetails() {
        return new ClientCredentialsResourceDetails();
    }

    @Bean
    public RequestInterceptor oauth2FeignRequestInterceptor(){
        return new OAuth2FeignRequestInterceptor(new DefaultOAuth2ClientContext(), clientCredentialsResourceDetails());
    }

    @Bean
    public OAuth2RestTemplate clientCredentialsRestTemplate() {
        return new OAuth2RestTemplate(clientCredentialsResourceDetails());
    }
}
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e437d3-26f77.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e437d3-26f77.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?