Oauth 2.0 招摇过市:授权令牌未传递到请求头中
我使用springfox 2.9.2 我有如下api:Oauth 2.0 招摇过市:授权令牌未传递到请求头中,oauth-2.0,swagger,springfox,Oauth 2.0,Swagger,Springfox,我使用springfox 2.9.2 我有如下api: @Api(tags = "Users") @RestController @RequestMapping("users") public class UsersController { @ApiOperation(value = "Creates a user") @ApiResponses(value = { @ApiResponse(code = 201, message = "user cre
@Api(tags = "Users")
@RestController
@RequestMapping("users")
public class UsersController {
@ApiOperation(value = "Creates a user")
@ApiResponses(value = {
@ApiResponse(code = 201, message = "user created"),
@ApiResponse(code = 401, message = "not authorized")})
@PostMapping(value = "/add")
public ResponseEntity addUser(@Valid @RequestBody UserDTO userDTO) {
...
}
要进行此呼叫,用户需要授权令牌
授权:承载{令牌}
witch来自身份验证服务器。
我试着在swagger中对这个服务器进行第一次调用,并将其传递给控制器请求,如上面的请求。
我也是
如果我将令牌设置为:
.securitySchemes(Arrays.asList(apiKey()))
private ApiKey apiKey() {
return new ApiKey("JWT", AUTHORIZATION_HEADER, "header");
}
它工作得很好。
知道为什么会发生这种情况吗?据我所知,只有在您将其配置为使用令牌时,Swigger才会使用令牌,并且使用Swigger UI页面右上角的“授权”按钮完成配置 因此,理想的情况是:
在此之后,所有后续呼叫都应该使用此令牌,直到您按logout。此处有类似问题。您能解决这个问题吗?我们目前正在使用隐式流进行Swagger,但令牌没有传递给服务。而且,没有人调用getTokenName:Swagger不应该直接设置auth令牌;因此,您应该复制令牌并使用右上角显示的“授权”按钮进行设置。我不确定我是否理解您的答案。“授权”按钮将执行登录并在浏览器URL AFAIK中返回访问令牌。但是Swagger应该从URL中提取令牌,并将其传递到Authorization Bear header字段。我不知道Swagger是否直接发送auth调用。我看到您使用的是JWT,我的设置与您的示例相同,我通常将令牌复制并粘贴到授权弹出窗口中,其中包含令牌的文本框。所有其他的电话都是这样的。你可以看看这个:-我说的是第一个说api_键的。
curl -X GET "http://localhost:8080/users/get" -H "accept: */*"
.securitySchemes(Arrays.asList(apiKey()))
private ApiKey apiKey() {
return new ApiKey("JWT", AUTHORIZATION_HEADER, "header");
}