spring-attic / spring-security-oauth

Support for adding OAuth1(a) and OAuth2 features (consumer and provider) for Spring web applications.
http://github.com/spring-projects/spring-security-oauth
Apache License 2.0
4.7k stars 4.04k forks source link

Could not autowire OAuth2ClientContext in oauth2 client #1275

Open gaurav2887 opened 6 years ago

gaurav2887 commented 6 years ago

In oauth2 client , it's showing error for not able to resolve OAuth2ClientContext injection in the following code. Error: 'Could not autowire. There is more than one bean of OAuth2ClientContext Type'. Any solution?

@Bean
    public OAuth2RestOperations restTemplate(OAuth2ClientContext oauth2ClientContext) {
        return new OAuth2RestTemplate(resource(), oauth2ClientContext);
    }
kanz76 commented 6 years ago

Try first to autowire using the qualifier as follows

@Autowired @qualifier("oauth2ClientContext") OAuth2ClientContext oAuth2ClientContext;

steklopod commented 5 years ago

A very strange thing. I hope this will be fixed. Kotlin:

@Autowired @Qualifier("oauth2ClientContext") private val oauth2ClientContext: OAuth2ClientContext
VCGDEV commented 3 years ago

I was having same issue, it turns out that I forgot to add follow properties:

security:
  oauth2:
    client:
      clientId: bd1c0a783ccdd1c9b9e4
      clientSecret: 1a9030fbca47a5b2c28e92f19050bb77824b5ad1
      accessTokenUri: https://github.com/login/oauth/access_token
      userAuthorizationUri: https://github.com/login/oauth/authorize
      clientAuthenticationScheme: form

as specified in docs spring-security-oauth2