Spring Boot Oauth2 Client и MercadoLibre: как исправить «OAuth2AuthenticationException: [invalid_token_response]»? - PullRequest
0 голосов
/ 12 мая 2019

несколько дней назад я начал работать с API MercadoLibre, и для аутентификации перед запуском необходимо использовать oAuth 2.0. Но у меня возникают проблемы с использованием аутентификации на стороне сервера. Я работаю с Spring Boot 2 и React.

Я размещаю код в Heroku, так как MercadoLibre запрашивает работу с действительными URL-адресами вместо Localhost, и я уже заставил его работать со встроенным поставщиком GitHub oAuth 2.0.

Моя конфигурация:

spring:
    security:
      oauth2:
        client:
          registration:
            github:
              clientId: <ID>
              clientSecret: <SECRET>
              redirectUriTemplate: "{baseUrl}/oauth2/callback/{registrationId}"
              scope:
                - user:email
                - read:user
            mercadolibre:
              clientId: <ID>
              clientSecret: <SECRET>
              authorizationGrantType: authorization_code
              redirectUriTemplate: "{baseUrl}/oauth2/callback/{registrationId}"
              clientAuthenticationMethod: post
              scope: read,write,offline_access
          provider:
            mercadolibre:
              authorization-uri: https://auth.mercadolivre.com.br/authorization
              token-uri: https://api.mercadolibre.com/oauth/token
              user-info-uri: https://api.mercadolibre.com/users/me
              user-info-authentication-method: form
              user-name-attribute: nickname

app:
  auth:
    tokenSecret: <SECRET>
    tokenExpirationMsec: 864000000
  oauth2:
    # After successfully authenticating with the OAuth2 Provider,
    # we'll be generating an auth token for the user and sending the token to the
    # redirectUri mentioned by the frontend client in the /oauth2/authorize request.
    # We're not using cookies because they won't work well in mobile clients.
    authorizedRedirectUris:
      - http://localhost:3000/oauth2/redirect
      - myandroidapp://oauth2/redirect
      - myiosapp://oauth2/redirect

Большая часть кода взята с https://github.com/callicoder/spring-boot-react-oauth2-social-login-demo

Мне не хватает следующей проблемы:

app[web.1]: org.springframework.security.oauth2.core.OAuth2AuthenticationException: [invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 406 Not Acceptable
app[web.1]:     at org.springframework.security.oauth2.client.authentication.OAuth2LoginAuthenticationProvider.authenticate(OAuth2LoginAuthenticationProvider.java:110) ~[spring-security-oauth2-client-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]

И до того, как он вылетит. Вот несколько журналов отладки.

app[web.1]: DEBUG 4 --- [io-49732-exec-6] o.s.s.authentication.ProviderManager     : Authentication attempt using org.springframework.security.oauth2.client.oidc.authentication.OidcAuthorizationCodeAuthenticationProvider
app[web.1]: DEBUG 4 --- [io-49732-exec-6] .s.a.DefaultAuthenticationEventPublisher : No event was found for the exception org.springframework.security.oauth2.core.OAuth2AuthenticationException
app[web.1]: DEBUG 4 --- [io-49732-exec-6] .s.o.c.w.OAuth2LoginAuthenticationFilter : Authentication request failed: 

Спасибо за вашу помощь. Больше информации о MercadoLibre: https://developers.mercadolibre.com/

...