【问题标题】:obtain an authorization token of an endpoint获取端点的授权令牌
【发布时间】:2020-01-15 05:12:51
【问题描述】:

我需要获取api1中端点的授权令牌,将用户和密码作为参数传递,这个端点会在spring boot中从api2调用它,有人可以帮我吗??

【问题讨论】:

标签: spring-boot api token


【解决方案1】:

你可以只提供一个 RestController 端点:

@PostMapping(value = "/getToken", consumes = APPLICATION_JSON_VALUE)
public String getToken(HttpServletRequest request, @RequestBody String json) 

在此示例中,您可以传递带有用户名/密码和您可能需要的任何其他额外属性的 JSON。如果您觉得更容易,可以用 DTO 替换上面的字符串。另一种选择是传递 2 个参数

@PostMapping(value = "/getToken", consumes = APPLICATION_JSON_VALUE)
public String getToken(HttpServletRequest request, @RequestParam String username, @RequestParam String password)

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 2016-11-29
    • 2017-04-09
    • 2017-11-06
    • 1970-01-01
    • 2016-10-13
    • 2018-06-13
    • 2021-07-27
    • 1970-01-01
    相关资源
    最近更新 更多