首页 > 解决方案 > 尝试检索 OAuth 2.0 访问令牌时出错 响应:406 Not Acceptable

问题描述

我正在尝试使用 spirng-oauth2-client 将我的项目与第三方身份验证服务器连接(按照此指令),现在当我运行应用程序时,在授权步骤之后,我将重定向回我的应用程序,并且显示此错误的页面:

[invalid_token_response] An error occurred while attempting to retrieve the OAuth 2.0 Access Token Response: 406 Not Acceptable: [Media is not supported]

在另一个 Stack Overflow 帖子的答案评论中,有人建议这是因为“Spring 使用 FORM 参数为身份验证代码生成 POST,而 mercadolibre 不需要正文,只有查询参数”。

我现在有这个配置:

应用程序属性

spring.security.oauth2.client.registration.mercadolivre.provider=mercadolivre
spring.security.oauth2.client.registration.mercadolivre.client-id=...
spring.security.oauth2.client.registration.mercadolivre.client-secret=...
spring.security.oauth2.client.registration.mercadolivre.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.mercadolivre.redirect-uri={baseUrl}/login/oauth2/code/{registrationId}
spring.security.oauth2.client.provider.mercadolivre.authorization-uri=https://auth.mercadolivre.com.br/authorization
spring.security.oauth2.client.provider.mercadolivre.token-uri=https://api.mercadolibre.com/oauth/token

安全.java

@Configuration
public class Security extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
         .anyRequest().authenticated()
         .and()
         .oauth2Login()
          .defaultSuccessUrl("/");
    }
}

任何人都知道如何更改 Spring 行为以匹配服务所需的?我的意思是,为没有正文的身份验证代码制作 POST,只有查询参数?

标签: springspring-oauth2oauth2client

解决方案


对我来说,错误是[invalid_token_response] 尝试检索 OAuth 2.0 访问令牌响应时发生错误:401 Unauthorized

问题是过期/过时的客户端 ID 和机密。(我之前使用过 Client Id 和 Secret 并且有效)


推荐阅读