0

How can I add Spring Security authentication to Swagger using annotations?

My SwaggerConfig is like:

private ApiInfo apiInfo() {
    return new ApiInfoBuilder().title("Spring REST Sample with Swagger")
            .description("Spring REST Sample with Swagger").license("Apache License Version 2.0").version("1.0")
            .build();
}

@Bean
public Docket docket() {
    Docket docket = new Docket(DocumentationType.SWAGGER_2);
    docket.protocols(new HashSet<String>(Arrays.asList("http")));
    docket.apiInfo(apiInfo()).select()
            .apis(RequestHandlerSelectors.basePackage("com.zycus.endpoint"))
            .paths(PathSelectors.any()).build();
    return docket;
}
dur
  • 15,689
  • 25
  • 79
  • 125
  • What authentication are you using? Username-password / token / Oauth ? Spring security is irrelevant here. – gaganbm Apr 12 '17 at 20:10
  • @gaganbm i am using Oauth2 Authentication. – Satish Keshri Apr 13 '17 at 07:00
  • You need to provide security schema and security definitions. You may find some examples here http://stackoverflow.com/a/34020486/564503. Looks like it doesn't work properly with old versions of swagger. Have a look at https://github.com/springfox/springfox/issues/870 – gaganbm Apr 13 '17 at 19:07

0 Answers0