gpt4 book ai didi

spring-boot - 带有不记名 token 的 Spring Boot swagger ui

转载 作者:行者123 更新时间:2023-12-02 02:49:24 24 4
gpt4 key购买 nike

我使用不记名 token 来访问我的 api。所以我像这样配置我的 Swagger :

@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("br.com.lumera.intimacaoapi.controller"))
.paths(PathSelectors.any())
.build()
.securitySchemes(Lists.newArrayList(apiKey()))
.securityContexts(Arrays.asList(securityContext()));
}


private ApiKey apiKey() {
return new ApiKey("Bearer", "Authorization", "header");
}

private SecurityContext securityContext() {
return SecurityContext.builder().securityReferences(defaultAuth())
.forPaths(PathSelectors.any()).build();
}

private List<SecurityReference> defaultAuth() {
AuthorizationScope authorizationScope = new AuthorizationScope(
"global", "accessEverything");
AuthorizationScope[] authorizationScopes = new AuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
return Arrays.asList(new SecurityReference("Bearer",
authorizationScopes));
}
}

但是对于每个请求,我的用户都必须输入 Bearer <>。我可以配置 swagger 以在我的用户插入的 token 之前自动放置 'Bearer' 吗?

tks

最佳答案

解决此问题的一种方法是将“Bearer”设置为默认值,如下所示

public ResponseEntity method_name(@ApiParam(defaultValue = "Bearer") String auth) { }

此代码将在 token 输入字段框中显示“Bearer”作为默认值。您可以在输入字段框中的承载后添加 token 。

关于spring-boot - 带有不记名 token 的 Spring Boot swagger ui,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52893841/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com