本文介绍了Quarkus:如何使用swagger-ui测试安全的API端点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个带有一些安全端点的Quarkus应用程序.为了轻松进行开发和轻松测试,我们希望使用Swagger UI,如 https://quarkus中所述.io/guides/openapi-swaggerui .但这似乎仅适用于不受保护的端点.

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.

有没有办法向Swagger UI中的受保护端点发出请求?

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

推荐答案

您需要在规范中添加一个安全方案:

You need to add a security scheme to your specification:

一种方法是使用批注:

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

启用安全方案后,授权按钮将出现在swagger ui上.安全方案可以是基本方案,也可以是载体方案.

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

这篇关于Quarkus:如何使用swagger-ui测试安全的API端点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 10:51