mat373
mat373

Reputation: 171

OpenApi authorize all services

How can I add Authorization for all my Swagger services ? I have configure OpenApi and i have main Application with configured swagger, where other services are registred. In swagger-ui i have defined few services and I can choose one from list. For all my services I have configuration:

The "web" application it is main application where all of my services are registred and how can you see there are display as definition list in swagger.

What I'd like to achieve it is add Authorize and this lock for all my services from list for each endpoint.

Upvotes: 0

Views: 624

Answers (1)

brianbro
brianbro

Reputation: 4769

On your code remove MultipleOpenApiResource which is already done by springdoc-openapi .

Use OperationCustomizer, by defining SecurityRequirement name to your different operations.

@Bean
public GroupedOpenApi usersGroup() {
    return GroupedOpenApi.builder().group("users")
            .addOperationCustomizer((operation, handlerMethod) -> {
                operation.addSecurityItem(new SecurityRequirement().addList("basicScheme"));
                return operation;
            })
            .packagesToScan("org.springdoc.demo.app2")
            .build();
}

Note that you have complete working demo here which combines groups and SecurityRequirement:

Upvotes: 1

Related Questions