Unable to authenticate application using Twitter OAuth with Spring Security OAuth2 Client

Viewed 295

I’m trying to authenticate users from Twitter using Spring Security OAuth2 Client. I have the following configuration:

spring:
  security:
    oauth2:
      client:
        registration:
          twitter:
            client-id: ${TWITTER_OAUTH_CLIENT_ID}
            client-secret: ${TWITTER_OAUTH_CLIENT_SECRET}
            authorization-grant-type: authorization_code
            redirect-uri: ${BASE_URL}/login/oauth2/code/twitter
            scope:
            - tweet.read
        provider:
          twitter:
            authorization-uri: https://twitter.com/i/oauth2/authorize
            token-uri: https://api.twitter.com/2/oauth2/token

The ${TWITTER_OAUTH_CLIENT_ID}, ${TWITTER_OAUTH_CLIENT_SECRET}, and ${BASE_URL} are all set as environment variables, don’t seem to be having issues with those.

When I click the login button I’m taken to twitter’s login page and I authenticate without issue but afterwards I’m taken to a page with the message:

You weren’t able to give access to the App. Go back and try logging in again.

Set my redirect URL in Twitter's OAuth2 settings as https://myapp.com/login/oauth2/code/twitter

Using the following security dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

Anyone know what I am doing incorrectly?

0 Answers
Related