当前位置:   article > 正文

OAuth2.0踩坑之路一(获取此资源的范围不足)_error": "insufficient_scope", "error_description":

error": "insufficient_scope", "error_description": "insufficient scope for

在学习该文章时

OAuth2.0 实现单点登录_oauth2.0单点登录_一只咸鱼。。的博客-CSDN博客

一、问题一:openfeign远程调用

[403] during [GET] to [http://nacos-order/order/info] [OrderFeignService#getOrder()]: [{"error":"insufficient_scope","error_description":"Insufficient scope for this resource","scope":"nacos-order"}]

但明明在验证服务器已经修改了资源范围并且都重启了:

根据搜索资料没有将scope添加到新的 OAuth2Request 中造成的。

地址如下:api - 使用 Spring Boot 和 OAuth2 获取此资源的范围不足 - IT工具网

二、问题二:OAuth2RestTemplate远程调用

java.lang.IllegalStateException: No instances available for nacos-order

由于自己的骚操作,手动用密码模式获取token,导致两个客户端资源服务token并没有都更新,一个是最新的一个是旧的,导致用OAuth2RestTemplate远程调用的时候发送上述异常!!! 

新token

 旧token

 OAuth2RestTemplate调用另一个客户端资源服务时解析的还是旧token,所以scope没有发生变化。

但用openfeign远程调用时没有发生该问题,可能是因为在请求方配置了令牌中继

  1. @Configuration
  2. public class RequestInterceptorConfig implements RequestInterceptor {
  3. /**
  4. * 配置令牌中继
  5. */
  6. @Override
  7. public void apply(RequestTemplate requestTemplate) {
  8. OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails)
  9. SecurityContextHolder.getContext().getAuthentication().getDetails();
  10. requestTemplate.header("Authorization","Bearer" + details.getTokenValue());
  11. }
  12. }

总结:

不要自己搞骚操作!

token没有同步导致scope还是旧的

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/277137
推荐阅读
相关标签
  

闽ICP备14008679号