Cannot send Authorization Bearer Token using Springfox

后端 未结 7 856
无人及你
无人及你 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:10

    The below solution worked for me in swagger 2.8.0 version.

    Add the below code in your Docket configuration

    @Bean
        public Docket api() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .securitySchemes(Collections.singletonList(new ApiKey("JWT", "Authorization", "header")))
                    .securityContexts(Collections.singletonList(
                            SecurityContext.builder()
                                    .securityReferences(
                                            Collections.singletonList(SecurityReference.builder()
                                                    .reference("JWT")
                                                    .scopes(new AuthorizationScope[0])
                                                    .build()
                                            )
                                    )
                                    .build())
                    )
                    .select()
                    .apis(RequestHandlerSelectors
                            .basePackage("com.test.controller"))
                    .paths(PathSelectors.regex("/.*"))
                    .build().apiInfo(apiEndPointsInfo());
        }
    

    In the text box after clicking Authorize button in the swagger UI, type Bearer "XXXXXXXX(Token)"

提交回复
热议问题