Skip to content

Instantly share code, notes, and snippets.

@RICH0423
Created September 25, 2017 06:46
Show Gist options
  • Save RICH0423/2515552e957e608cff973310467d5db9 to your computer and use it in GitHub Desktop.
Save RICH0423/2515552e957e608cff973310467d5db9 to your computer and use it in GitHub Desktop.
Pass JWT token in swagger with Spring Boot and springfox
package com.rich.api.config;
import java.util.Arrays;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
/**
*
* @author rich
*
*/
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.delta.ssir.dbee.controller"))
.paths(PathSelectors.any())
.build()
.apiInfo(apiInfo())
.securitySchemes(Arrays.asList(apiKey()));
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("REST API")
.description("The REST API for demo swagger.").termsOfServiceUrl("")
.contact(new Contact("RICH LEE", "", "rich.lee@gmail.com"))
.license("Apache License Version 2.0")
.licenseUrl("https://www.apache.org/licenses/LICENSE-2.0")
.version("0.0.1")
.build();
}
private ApiKey apiKey() {
return new ApiKey("authkey", "Authorization", "header");
}
}
@artemrogov
Copy link

it's ok! Thank you)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment