Cannot send Authorization Bearer Token using Springfox

后端 未结 7 839
无人及你
无人及你 2021-02-08 05:59

I\'m having trouble understanding why \"Authorization: Bearer __\" is not being sent in my api using Springfox 2.5.0. I have the following configuration:

private         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-08 06:19

    I used springfox-swagger2 version-2.9.2 with below configuration and it works fine to pass JWT token via swagger-ui.

    private ApiKey apiKey() {    
        return new ApiKey("apiKey", Authorization, "header"); 
    }
    
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2).select()
           .apis(RequestHandlerSelectors.basePackage("com.mycompany.dept.controller"))
           .paths(PathSelectors.any())
           .build().apiInfo(metaData()).securitySchemes(Lists.newArrayList(apiKey()));
    }
    

    And in controller we need to use @ApiOperation (value = "Get dummy by id.", authorizations = { @Authorization(value="apiKey") })

    Please refer to https://github.com/springfox/springfox/issues/2194

提交回复
热议问题