【问题标题】:oauth2 client in Spring BootSpring Boot 中的 oauth2 客户端
【发布时间】:2018-08-22 07:10:39
【问题描述】:

此问题基于this thread 中的解决方案。我实现了最佳答案,但得到的结果好坏参半。

String stringObj = restTemplate.getForObject(http://server/rest/api/users?access_token=991949410990808314, String.class);

在代码中,我试图访问一个简单的 GET 端点,但是我得到了 401 Unauthorized,但是如果我将其余的 url + 令牌复制到我的浏览器,它会返回预期的 json 对象。有人知道为什么吗?

【问题讨论】:

    标签: java spring spring-boot oauth-2.0 client


    【解决方案1】:

    这不是因为您需要将“授权”放在标题中并放入您的休息电话吗? 喜欢

    HttpHeaders headers = new HttpHeaders();
    headers.add("Authorization", "Basic " + base64Creds);
    

    【讨论】:

      【解决方案2】:

      我遇到的问题是

      @Autowired
      RestTemplate restTemplate;
      

      restTemplate 没有像我想象的那样被注入。我刚做的时候它起作用了:

      RestTemplate restTemplate = new RestTemplate();
      

      如果有人知道为什么@Autowired 不起作用,我很想听听。谢谢。

      【讨论】:

      猜你喜欢
      • 2016-09-28
      • 2017-09-26
      • 2018-05-07
      • 2016-06-27
      • 2012-10-22
      • 2018-12-05
      • 2016-10-31
      • 2013-06-20
      • 1970-01-01
      相关资源
      最近更新 更多