求大神解答,我使用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