Quarkus Swagger-UI Authorization
Asked Answered
K

1

11

Im currently working with Quarkus and Swagger-UI as delivered by quarkus-smallrye-openapi. We have OIDC from Azure AD as security, which is currently not supported by Swagger-UI (see Swagger-Docs), so I can't add the "real" authorization to swagger. This means, I can't use Swagger since my endpoints are at least secured with @RolesAllowed. We have an endpoint to fetch a mock-security token, but I don't know how to tell swagger to take this token. Basically I want to tell swagger-ui "Here, I have this token, add it as Authorization: Bearer XXXto all requests", but I don't know how to do that in Quarkus.

Kentish answered 1/10, 2020 at 11:37 Comment(2)
Please take a look: #64038162Pentothal
You want this token to fetched automatically from OIDC or you want to place it and be used by your APIs in Swagger ?Peag
L
11
  1. Register security scheme
@Path("/sample")
@SecuritySchemes(value = {
        @SecurityScheme(securitySchemeName = "apiKey", 
                        type = SecuritySchemeType.HTTP,
                        scheme = "Bearer")}
)
public class SampleResource {
  1. Mark the operation's security requirement with the scheme name registered.
    @GET
    @SecurityRequirement(name = "apiKey")
    String hello() {
  1. Authorize option should be now available on swagger page. Enter your mock api key here. enter image description here

  2. Trigger the service from swagger ui. You could now see Authorization: Bearer <VALUE> header set in request.

Leesen answered 6/10, 2020 at 5:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.