swagger-ui
swagger-ui copied to clipboard
Cant see authentication button when using basic auth security scheme
Springfox swagger 2.4.0
Docket:
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket api() {
AuthorizationScope[] authScopes = new AuthorizationScope[1];
authScopes[0] = new AuthorizationScopeBuilder()
.scope("read")
.description("read access")
.build();
SecurityReference securityReference = SecurityReference.builder()
.reference("test")
.scopes(authScopes)
.build();
List<SecurityContext> securityContexts = Arrays.asList((SecurityContext.builder().securityReferences
(Arrays.asList((securityReference))).build()));
return new Docket(DocumentationType.SWAGGER_2)
.securitySchemes(Arrays.asList((new BasicAuth("test"))))
.securityContexts(securityContexts)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.paths(Predicates.not(PathSelectors.ant("/admin/**")))
.paths(Predicates.not(PathSelectors.ant("/admin.json")))
.paths(Predicates.not(PathSelectors.ant("/error/**")))
.paths(Predicates.not(PathSelectors.ant("/exception/**")))
.build();
}
@Bean
SecurityConfiguration security() {
return new SecurityConfiguration(
"test-app-client-id",
"test-app-client-secret",
"test-app-realm",
"test-app",
"apiKey",
ApiKeyVehicle.HEADER,
"api_key",
"," /*scope separator*/);
}
}
Controller interface:
@ApiOperation(value = "Get Person", response = UserResponse.class, authorizations = {@Authorization(value="test")})
@ApiResponses(value = { @ApiResponse(code = 404, message = "Person not found", response=ExceptionResponse.class) })
ResponseEntity<UserResponse> getPerson(@ApiParam(value="User Id", required=true) @PathVariable("id") int userId);
Relevent json
"/users/{id}":{
"get":{
"tags":[
"user-controller"
],
"summary":"Get Person",
"operationId":"getPersonUsingGET",
"consumes":[
"application/json"
],
"produces":[
"application/json"
],
"parameters":[
{
"name":"device-id",
"in":"header",
"description":"Device ID",
"required":true,
"type":"ref"
},
{
"name":"id",
"in":"path",
"description":"User Id",
"required":true,
"type":"integer",
"format":"int32"
}
],
"responses":{
"404":{
"description":"Person not found",
"schema":{
"$ref":"#/definitions/ExceptionResponse"
}
},
"200":{
"description":"OK",
"schema":{
"$ref":"#/definitions/UserResponse"
}
},
"401":{
"description":"Unauthorized"
},
"403":{
"description":"Forbidden"
}
},
"security":[
{
"test":[
]
}
]
}
}
},
"securityDefinitions":{
"test":{
"type":"basic"
}
}

Sorry, didn't mean to post this here