报错信息
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jwtTokenEnhancer' defined in class path resource [org/springframework/boot/autoconfigure/security/oauth2/resource/ResourceServerTokenServicesConfiguration$JwtTokenServicesConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter]: Factory method 'jwtTokenEnhancer' threw exception; nested exception is org.springframework.web.client.UnknownContentTypeException: Could not extract response: no suitable HttpMessageConverter found for response type [interface java.util.Map] and content type [text/html;charset=UTF-8]
报以上错误的原因是应为我们没有配置jwt的key-value参数
我们只需要配置
security:
oauth2:
client:
client-id: member-service
client-secret: member123
access-token-uri: http://localhost:8100/oauth/token
user-authorization-uri: http://localhost:8100/oauth/authorize
resource:
jwt:
key-uri: http://localhost:8100/oauth/token_key
# 报错增加下列配置即可
key-value: member123
错误跳转地址错误
error="invalid_grant", error_description="Invalid redirect: http://localhost:8400/login does not match one of the registered values."```
![在这里插入图片描述](https://img-blog.csdnimg.cn/cee3ae68090344fe893b9a41f332fdcc.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5pyJ6Laj55qE54G16a2CX-S4jeS4luS_l-eahOW_gw==,size_20,color_FFFFFF,t_70,g_se,x_16)
场景是为我们访问客户端的接口localhost:8400/member/list准备跳转套登录界面。
在获取授权成功后,发现跳转地址出现问题,使用了我们客户端项目的地址前缀。
解决方案:
![在这里插入图片描述](https://img-blog.csdnimg.cn/5d86dc6fc8a048e69b10fa6a945e35f6.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5pyJ6Laj55qE54G16a2CX-S4jeS4luS_l-eahOW_gw==,size_16,color_FFFFFF,t_70,g_se,x_16)
增加如图所以的配置
错误3
error=“invalid_request”, error_description=“At least one redirect_uri must be registered with the client.”
![在这里插入图片描述](https://img-blog.csdnimg.cn/e714653461114614993c0d3bddf49af3.png)
我们配置了数据库存储客户端的认证信息,数据表中没有配置跳转的URL
![在这里插入图片描述](https://img-blog.csdnimg.cn/51370d15a95f474dbaedec7f76dfb945.png)
解决方案增加跳转地址。