You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to setup SwaggerUI for exposing my APIs. I require to add authorization token in the request headers while making the API calls, is there a way to configure this on the UI?
My Swagger Configuration file looks like this -
@Configuration@EnableSwagger2@ComponentScan(basePackages = "com.rokitt.**")
publicclassSwaggerConfiguration {
@BeanpublicDocketpetApi() {
returnnewDocket(DocumentationType.SWAGGER_2).groupName("galactica-api").apiInfo(apiInfo()).paths(apiPaths()).build();
}
privatePredicate<String> apiPaths() {
returnor(regex("/rest/.*"));
}
privateApiInfoapiInfo() {
returnnewApiInfoBuilder().title("Galactica APIs").description("Backend APIs for Galactica")
.termsOfServiceUrl("http://springfox.io").contact("Backend Team").license("Apache License Version 2.0")
.licenseUrl("https://github.com/springfox/springfox/blob/master/LICENSE").version("2.0").build();
}
// these components have been copied from// http://springfox.github.io/springfox/docs/current/#getting-started// in an attempt to configure authToken in the header while making the api calls// but it is still not workingprivateSecurityContextsecurityContext() {
returnSecurityContext.builder().securityReferences(defaultAuth()).forPaths(PathSelectors.regex("/rest/.*")).build();
}
privateList<SecurityReference> defaultAuth() {
AuthorizationScopeauthorizationScope = newAuthorizationScope("global", "accessNothing");
AuthorizationScope[] authorizationScopes = newAuthorizationScope[1];
authorizationScopes[0] = authorizationScope;
returnLists.newArrayList(newSecurityReference("mykey", authorizationScopes));
}
}
The text was updated successfully, but these errors were encountered:
You miss set securityContext to Docket like : @bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.vnpt.technology"))
.paths(postPaths()).build().apiInfo(metaData()).securitySchemes(Lists.newArrayList(apiKey()))
.securityContexts(Lists.newArrayList(securityContext()));
}
I am trying to setup SwaggerUI for exposing my APIs. I require to add authorization token in the request headers while making the API calls, is there a way to configure this on the UI?
My Swagger Configuration file looks like this -
The text was updated successfully, but these errors were encountered: