0

I am using springdoc version 1.4.3 and springdoc-security version 1.4.3 on my project with spring boot and spring security with the below configuration for my springdoc I am able to access swagger-ui.html but when I authorize(enter the token through swagger-ui) and try to get response from from my rest controller I keep getting access denied.

@Configuration
public class SpringDocConfig {
    @Bean
    public OpenAPI CustomOpenAPI() {
        return new OpenAPI()
            .addSecurityItem(new SecurityRequirement().addList("bearAuth", Arrays.asList("read", "write")))
            .components(new Components()
                .addSecuritySchemes("bearer-key", new SecurityScheme()
                    .type(SecurityScheme.Type.HTTP)
                    .scheme("bearer").bearerFormat("JWT")
                    .in(SecurityScheme.In.HEADER)));
    }
}

here is the controller that I am trying to hit

@GetMapping
@Operation(security = {@SecurityRequirement(name = "bearer-key")})
public List<UserEntity> getAll() { return userService.getAllUsers(); }

how the curl looks from swagger-ui:

curl -X GET "http://localhost:8080/api/v1/users" -H "accept: */*" -H "Authorization: Bearer eyJ..."

Hitting my controller from postman works but it does not work using swagger-ui my requirement is to get it from the latter.

Pseudo
  • 56
  • 1
  • 2
  • 12

1 Answers1

0

You should inspect the http requests from the swagger-ui.

Make sure the swagger-ui is sending the Authorization Header Bearer.