spring-boot - 如何使用 Spring Boot 在 swagger 标头中配置 jwt 令牌
问题描述
我已经在 Spring Boot 应用程序中配置了 swagger 但我不知道如何验证 jwt 授权令牌 swagger 版本是 2.4.0
@Bean
public Docket newsApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.securitySchemes(Lists.newArrayList(apiKey()))
.securityContexts(Lists.newArrayList(securityContext()));
}
@Bean
SecurityContext securityContext() {
return SecurityContext.builder()
.securityReferences(defaultAuth())
.forPaths(PathSelectors.any())
.build();
}
List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope
= new AuthorizationScope("global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Lists.newArrayList(
new SecurityReference("JWT", authorizationScopes));
}
private ApiKey apiKey() {
return new ApiKey("JWT", "Authorization", "header");
}
解决方案
推荐阅读
- javascript - 热链接图像使用 React 和 Webpack 渲染得非常慢
- python - 404 错误的 Django Rest Framework 自定义消息
- facebook - 访问 Facebook 应用权限页面公共内容访问
- c# - 如何根据 C# 中的 Id 在嵌套列表中填充数据?
- woocommerce - 停止为每种语言发送 WooCommerce 新订单电子邮件
- python - 比较DF中两列的(子)字符串
- testing - 詹金斯。如何更改文件内容
- python-requests - 使用机器人框架的肥皂调用
- javascript - 将信息从外部传递到 AngularJs 中的模态
- .net - VB .NET FTP 逐行写入文件