我正在使用以下spring引导依赖项。
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.5</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
我为rest端点配置了如下的授权头。
@RestController
@Api(tags = "Welcome Controller", description = "Welcome API")
public class HomeController {
@ApiOperation(value = "Sent secret message", notes = "Sent secret message")
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Access Token", required = false, allowEmptyValue = false, paramType = "header", dataTypeClass = String.class, example = "Bearer access_token") })
@GetMapping("/secret-message")
public Object tokenResponse() {
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return principal;
}
}
但是当我打开swagger并尝试用bearer令牌执行rest端点时,这个authorization头并没有作为请求的一部分发送。我们如何解决这个问题?
参考文献https://github.com/tiangolo/fastapi/issues/1037httpshttp://github.com/tiangolo/fastapi/issues/612
1条答案
按热度按时间w41d8nur1#
这个问题与最新版本的swagger有关。但在swagger2.9.2中一切都很顺利