spring - 尝试检索 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,只有查询参数?
解决方案
对我来说,错误是[invalid_token_response] 尝试检索 OAuth 2.0 访问令牌响应时发生错误:401 Unauthorized
问题是过期/过时的客户端 ID 和机密。(我之前使用过 Client Id 和 Secret 并且有效)
推荐阅读
- user-interface - 自定义网格布局行大小
- typescript - 什么 AsyncGenerator TypeScript 类型会产生 Promise?
- c++ - 为什么使用 MSVC 编译器编译 zlib 可以正常工作,但使用 Cygwin 时会出现语法错误?
- c++ - 为什么'[[fallthrough]]'需要方括号'[[]]'?
- reactjs - 反应原生屏幕之间的导航
- angular - Angular mat-table 在每一行中显示动态键值对
- database - 如何有效地等待 RDBS (PostgreSQL) 表中的数据可用?
- c++ - c++ 重载函数,包括布尔和整数参数
- android - 带有房间数据库的搜索视图
- r - 包含 map() 函数以将字符向量中的每个元素制成表格会返回错误