spring-boot - Springfox 中的授权范围
问题描述
我尝试为我的 Spring 引导应用程序配置 swagger。我使用此链接进行配置https://www.baeldung.com/spring-boot-swagger-jwt。我改变了一些部分
@Bean
public Docket swaggerCustomConfiguration() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiDetails())
.securityContexts(Collections.singletonList(securityContext()))
.securitySchemes(Collections.singletonList(apiKey()))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.paths(Predicates.not(PathSelectors.regex("/error.*")))
.build()
.protocols(swaggerProtocols)
.host(swaggerHostUrl);
}
private ApiInfo apiDetails() {
return new ApiInfoBuilder()
.title(swaggerTitle)
.description(swaggerDescription)
.termsOfServiceUrl(termsOfServiceUrl)
.version("v" + serverVersionCode + "-" + serverVersionName)
.build();
}
private ApiKey apiKey() {
return new ApiKey("Bearer", "Authorization", "header");
}
private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth()).build();
}
private List<SecurityReference> defaultAuth() {
final AuthorizationScope readScope = new AuthorizationScope("read", "read scope");
final AuthorizationScope writeScope = new AuthorizationScope("write", "write scope");
return Collections.singletonList(new SecurityReference("Bearer",
new AuthorizationScope[]{readScope, writeScope}));
}
但我不知道的是AuthorizationScope
。我不知道到底在做AuthorizationScope
什么。可以介绍任何链接来帮助我。
解决方案
我知道这不完全是您问题的答案,但您可以考虑转向 springdoc。它是更新的,在我看来,使用库更好、更容易。看看它:
Springfox 已经成为使用如此多的错误和难以配置的功能的痛苦。
推荐阅读
- python - 尽管安装了 keras-rl2,但未解决导入“rl.agents”?
- pycaret - pycaret 多类分类返回数字,如何获取标签?
- android - Smack 4.4.2 通过证书建立安全连接
- publish-subscribe - Conversejs 群聊订阅 (ejabberd)
- android - 安排包含开始日期和结束日期的函数的最佳方法是什么?
- tensorflow - 当 Tensorflor 模型应为布尔值时的十进制输出 (1/0)
- python - 在Python中向量化矩阵演算的有效方法?
- shopify - Shopify 订单 API 中的双倍折扣行
- ag-grid - 如何在 ag-grid 中也为固定行添加复选框选择
- java - 合并 Java 应用程序资源