在springdoc-openapi-ui中为基本身份验证启用授权按钮

问题描述 投票:0回答:1

如何在springdoc-openapi-ui(OpenAPI 3.0 /swagger-ui.html)中启用“授权”按钮以进行基本身份验证。

必须在Spring @Controller@Configuration类中添加哪些注释?

Authorize button

Authorize form for Basic Authentication

java spring swagger-ui openapi springdoc
1个回答
1
投票

使用@io.swagger.v3.oas.annotations.security.SecurityScheme bean中的注释@Configuration为OpenAPI 3.0定义全局安全性方案:

@Configuration
@OpenAPIDefinition(info = @Info(title = "My API", version = "v1"))
@SecurityScheme(
    name = "basicAuth",
    type = SecuritySchemeType.HTTP,
    scheme = "basic"
)
public class OpenApi30Config {

}

使用参考定义的安全方案的@RestController注释每个需要基本身份验证的@io.swagger.v3.oas.annotations.Operation方法:

@Operation(summary = "My endpoint", security = @SecurityRequirement(name = "basicAuth"))
© www.soinside.com 2019 - 2024. All rights reserved.