code

Spring Security oauth2 클라이언트 - Twitter 문제

starcafe 2023. 7. 22. 10:19
반응형

Spring Security oauth2 클라이언트 - Twitter 문제

내 애플리케이션에 TwitteroAuth2를 추가하고 싶습니다.이전에 저는 페이스북과 구글을 성공적으로 추가했습니다. 제공자를 추가할 필요가 없었습니다.Twitter 데이터를 추가하려고 할 때application.properties파일 및 실행 서버 오류가 발생:

Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through method 'setContentNegotationStrategy' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration$EnableWebMvcConfiguration': Unsatisfied dependency expressed through method 'setConfigurers' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.OAuth2ClientConfiguration$OAuth2ClientWebMvcSecurityConfiguration': Unsatisfied dependency expressed through method 'setClientRegistrationRepository' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.security.oauth2.client.servlet.OAuth2ClientRegistrationRepositoryConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'spring.security.oauth2.client-org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties': Invocation of init method failed; nested exception is java.lang.IllegalStateException: Client id must not be empty.

다음은 내 구성입니다.

spring.security.oauth2.client.registration.facebook.clientId=<SECRET>
spring.security.oauth2.client.registration.facebook.clientSecret=<SECRET>
spring.security.oauth2.client.registration.facebook.redirect-uri=http://localhost:8080/oauth2/callback/facebook
spring.security.oauth2.client.registration.facebook.scope=public_profile email


spring.security.oauth2.client.registration.twitter.clientId=<SECRET>
spring.security.oauth2.client.registration.twitter.clientSecret=<SECRET>
spring.security.oauth2.client.registration.twitter.redirect-uri=http://localhost:8080/oauth2/callback/twitter
spring.security.oauth2.client.registration.twitter.provider=twitter
spring.security.oauth2.client.registration.twitter.authorization-grant-type=token
spring.security.oauth2.client.provider.twitter.token-uri=https://api.twitter.com/oauth/token
spring.security.oauth2.client.provider.twitter.authorization-uri=https://api.twitter.com/oauth/authorize
spring.security.oauth2.client.provider.twitter.user-info-uri=https://api.twitter.com/oauth/request_token

나는 고객 ID를 추가해서 어디가 문제인지 확인합니다.그리고 구성에 대한 addoauth URL을 수정했으면 합니다.

@업데이트 문제 발견 :) 여기에 오타가 있습니다.

spring.security.oauth2.client.registration.twiter.authorization-grant-type=token

@업데이트 이제 다른 문제가 있습니다. 다음은 제 구성입니다.

spring.security.oauth2.client.registration.twitter.client-id=<SECRET>
spring.security.oauth2.client.registration.twitter.clientSecret=<SECRET>
spring.security.oauth2.client.registration.twitter.redirect-uri=http://localhost:8080/oauth2/callback/twitter
spring.security.oauth2.client.registration.twitter.authorization-grant-type=authorization_code
spring.security.oauth2.client.provider.twitter.token-uri=https://api.twitter.com/oauth/access_token
spring.security.oauth2.client.provider.twitter.authorization-uri=https://api.twitter.com/oauth/authorize

그리고 전화를 건 후: http://127.0.0.1:8080/oauth2/auth/twitter:

  • 당신의 질문은 트위터에서 oauth2 클라이언트를 사용하는 것에 관한 것으로 불가능합니다.Twitter는 사용자와 관련된 Oauth 2.0 흐름을 지원하지 않습니다.

  • 응용 프로그램만 지원합니다. OAuth 2.0 베어러 토큰:

    OAuth 2.0 Bearer Token은 Twitter API로 인증하기 위한 응용 프로그램 전용 인증 방법입니다.이 방법은 응용 프로그램에 따라 다르므로 사용자를 포함하지 않습니다.

    https://developer.twitter.com/en/docs/basics/authentication/oauth-2-0

  • 최종 사용자와 관련된 흐름의 경우 Oauth 1.0a https://developer.twitter.com/en/docs/basics/authentication/oauth-1-0a 를 사용합니다.

  • 아래 다이어그램에서 볼 수 있듯이 Oauth 1.0a 흐름에서 사용자를 권한 부여 서버로 리디렉션할 때 응용 프로그램이 먼저 권한 부여 서버와 대화하여 요청 토큰을 가져오고 해당 토큰을 전달해야 합니다.그리고 그것은 토큰입니다, 트위터가 Oauth 1.0a이기 때문에 누락되었다고 불평하는 것입니다.즉, A 단계 없이 B 단계를 수행하고 있습니다.

    enter image description here

다이어그램 참조

https://oauth.net/core/1.0/

grant_type을 client_credentials로 변경하거나 oauth 토큰 URL을 다음으로 변경합니다.https://api.twitter.com/oauth2/token.

또한 Spring의 소셜 공급자 API를 통해 트위터와 상호 작용할 수 있는 아래 사이트들이 있습니다.

https://docs.spring.io/spring-social-twitter/docs/current/reference/htmlsingle/

https://developer.twitter.com/en/docs/basics/authentication/api-reference/token

언급URL : https://stackoverflow.com/questions/58380651/spring-security-oauth2-client-problem-with-twitter

반응형