Quarkus: how to test secured API endpoints with swagger-ui

霸气de小男生 提交于 2021-01-03 07:08:02

问题


We have a Quarkus application with some secured endpoints. For development and easy testing without much effort, we would like to use Swagger UI as described at https://quarkus.io/guides/openapi-swaggerui. But this seems to only work for unprotected endpoints.

Is there a way to also make request to protected endpoints in Swagger UI?


回答1:


You need to add a security scheme to your specification:

One way to do it is by using annotations:

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

After you enable security scheme, authorize button will appear on swagger ui. Securirty scheme can be basic, bearer etc..



来源:https://stackoverflow.com/questions/64037662/quarkus-how-to-test-secured-api-endpoints-with-swagger-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!