几天前,我开始使用MercadoLibre的API,有必要在开始之前使用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/