qq_37768414 2020-05-30 15:21 采纳率: 0%
浏览 2681

spring security oauth2不能内部调用/oauth/token接口

求大神解答,我使用springcloud 整合 spring security oauth2,现在已经可以通过/oauth/token接口拿到token,能成功访问资源服务。然后我想自己定义一个接口,在接口里调用/oauth/token。先是使用RestTemplate去调用/oauth/token,但是直接抛出了401的异常
restTemplate.getForEntity("http://localhost:8008/oauth/token", Object.class, map)
然后我试着使用请求转发来访问/oauth/token

    @GetMapping("/login")
    public void login(@RequestParam String client_id,
                      @RequestParam String client_secret,
                      @RequestParam String grant_type,
                      @RequestParam String username,
                      @RequestParam String password,
                        HttpServletRequest request,
                        HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/oauth/token").forward(request, response);
    }

但是返回
{"error":"unauthorized","error_description":"There is no client authentication. Try adding an appropriate authentication filter."}
那怎么才能在内部调用/oauth/token拿到token呢

完整代码可见github

  • 写回答

3条回答 默认 最新

  • wangyuncc 2020-07-21 19:45
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog