Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api key input missing in swagger ui after upgrading version to 2.6.1 #1804

Closed
prajapatkiran opened this issue May 8, 2017 · 23 comments
Closed
Labels
Milestone

Comments

@prajapatkiran
Copy link

I have a spring boot application which uses swagger. The project runs absolutely fine in swagger version 2.5.0. I had to update the swagger version to v2.6.1 to get @ApiIgnore working for some new requirement. After I upgraded the version I dont see api_key input field in swagger-ui.
Below is my project configuration:

I tried with both 2.6.1 and 2.7.0-SNAPSHOT. Here are the dependencies
pom.xml

    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.7.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.7.0-SNAPSHOT</version>
    </dependency>

swagger-ui

SwaggerConfig.java

@Bean
public Docket newsApi() {
    return new Docket(DocumentationType.SWAGGER_2)
            .select()
            .apis(RequestHandlerSelectors.basePackage("some.package"))
            .paths(PathSelectors.any())
            .build()
            .pathMapping("/")
            .produces(Sets.newHashSet(APPLICATION_JSON_VALUE))
            .consumes(Sets.newHashSet(APPLICATION_JSON_VALUE))
            .directModelSubstitute(LocalDateTime.class, Date.class)
            .directModelSubstitute(OffsetDateTime.class, Date.class)
            .directModelSubstitute(Instant.class, Date.class)
            .directModelSubstitute(HttpStatus.class, String.class)
            .apiInfo(apiInfo())
            .useDefaultResponseMessages(false);
}
@Bean
SecurityConfiguration security() {
    return new SecurityConfiguration(
            null,
            null,
            null, // realm Needed for authenticate button to work
            null, // appName Needed for authenticate button to work
            BEARER,// apiKeyValue
            ApiKeyVehicle.HEADER,
            AUTHORIZATION, //apiKeyName
            null);
}

MvcConfig.java

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    super.addResourceHandlers(registry);
    //Adding swagger-ui webjars resources mapping so swagger-ui can be served
    if (!registry.hasMappingForPattern("/webjars/**")) {
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    if (!registry.hasMappingForPattern("/swagger-ui.html")) {
        registry.addResourceHandler("/swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
    }
}
@dilipkrish
Copy link
Member

The API key is configured via the security bean. Where you have BEARER, it should be BEARER KEY....

@dilipkrish dilipkrish added this to the 2.7.0 milestone May 8, 2017
@prajapatkiran
Copy link
Author

That is something which we expect the user to enter in swagger ui. Bearer is the default value which shows up in the text box. My issue is that after changing the swagger version I dont see the input text box at all.
Please see snapshot below.

Before upgrade:
swagger-ui2

After upgrade:
swagger-ui

@ThatsOurJake
Copy link

This too is happening to me, before version 2.7 the input box would appear, now the input box isn't no longer renders but the security is still applied

@dilipkrish
Copy link
Member

When we upgrade to 3.x of swagger-ui we'll address this

@KhushbooRathi
Copy link

Hi,
We need this this oAuth functionality in our project. Will you please let me know when the stable version of swagger 3.0 is released?

Thanks,
Khushboo

@dilipkrish
Copy link
Member

Not sure at the moment. Sometime in the next couple of months

@ngawor
Copy link

ngawor commented Nov 7, 2017

I am now hitting other swagger bugs due to do my inability to upgrade in order to keep token support. This fix is very important to us.

@dilipkrish
Copy link
Member

@ngawor What fix are you referring to. This is a question targeting 2.6.1 version of this library.

@ngawor
Copy link

ngawor commented Nov 13, 2017

@dilipkrish I have yet to find a version higher than 2.5 that will allow the Bearer token to be passed successfully. Are you saying that exists?

@dilipkrish
Copy link
Member

@ngawor I'm not sure, so I trust your observation that this is an issue with 2.7.0. I'll change this ticket to a bug instead. I'd like some help/pointers on what needs to happen to get this resolved. A PR would be very welcome.

@harrygu
Copy link

harrygu commented Dec 19, 2017

I would like to express that this is a critical bug to fix. Without the fix, I cannot upgrade to any version above 2.5 because the newer versions do not allow us to get over api key-based authentication.

@dilipkrish dilipkrish added this to the 2.8.0 milestone Jan 2, 2018
@dilipkrish
Copy link
Member

This has been fixed via upgrading to swagger ui 3.x (#2153)

@harrygu
Copy link

harrygu commented Jan 17, 2018

@dilipkrish Could you please give an example for how to enable the Api Key field at the top of the screen in 2.8.0? It seems there have been lots of changes in the new release.

@batizhao
Copy link

batizhao commented Jan 27, 2018

@dilipkrish The 2.8.0 version seems to be a problem. Where did I make a mistake?

2.6.0

This version is ok.

Java code

@Bean
public Docket api() {
   return new Docket(DocumentationType.SWAGGER_2)
           .select()
           .apis(RequestHandlerSelectors.basePackage("sh.ideal.ims.controller"))
           .paths(PathSelectors.any())
           .build()
           .apiInfo(apiInfo())
           .securitySchemes(Collections.singletonList(apiKey()));
}

private ApiKey apiKey() {
    return new ApiKey("Authorization", "Bearer", "header");
}

Input at swagger-ui

name: Authorization
in: header
value: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6

curl at swagger-ui

curl -X GET --header 'Accept: application/json' --header 'Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6' 'http://localhost:8001/user'

Update to 2.7.0

This version is ok. BUT name and keyname, need a change of location

Java code

private ApiKey apiKey() {
    return new ApiKey("Bearer", "Authorization", "header");
}

2.8.0

Java code

private ApiKey apiKey() {
    return new ApiKey("Bearer", "Authorization", "header");
}

This version --header 'Bearer: AAA' missing in swagger ui.
See curl at swagger-ui

2018-01-27 10 03 06

Please help me, Thanks.

@dilipkrish
Copy link
Member

@batizhao Just checking, did you click the lock icon in the API and configure the API to be protected?

@batizhao
Copy link

batizhao commented Jan 30, 2018

spring-boot 1.5.9.RELEASE

Java Code

@ApiOperation(value = "xxxxxxx")
@ApiImplicitParam(name = "p", value = "Page No.", dataType = "int", paramType = "query")
@GetMapping()
@PreAuthorize("hasRole('SUPER_ADMIN')")
public RestResponse list(@RequestParam(value = "p", required = false, defaultValue = "1") int pageNum) {
    Page<User> users = userService.findUsers(pageNum);
    return new RestResponse<>(users);
}

application.yml

security:
  basic:
    enabled: false
  oauth2:
    resource:
      jwt:
        keyValue: |
          -----BEGIN PUBLIC KEY-----
          XXXXXXXX
          -----END PUBLIC KEY-----

  ignored: /v2/api-docs,/swagger-resources/**,/swagger-ui.html,/webjars/**,/configuration/ui,/configuration/security

Step 1. Click Button "Authorize"
Step 2. input value "Bearer XXX"
Step 3. Click Button "Authorize",
Step 4. Click "Done".
Step 5. Try it.

--header 'Authorization: Bearer XXX' missing.

2018-01-30 1 28 05
2018-01-30 1 28 13
2018-01-30 1 28 44

@jbforth4
Copy link

Is there an update on this? We want to use the new 2.8 version but cannot get it to work with OAuth.

@dilipkrish
Copy link
Member

It should be fixed in 2.9.0, if not please report back @jbforth4

@spamovy
Copy link

spamovy commented May 14, 2018

@dilipkrish still not working in 2.9.0!

@dilipkrish
Copy link
Member

@spamovy This may be a bug in swagger-ui. Is this reproducible using the the demos project?

@BartoszCoyote
Copy link

still no working.

@dilipkrish
Copy link
Member

@BartoszCoyote please create a new issue. 2.6.1 and 2.9.2 have different versions of swagger-ui

@medialwerk
Copy link

medialwerk commented Jul 26, 2018

We have the same problem with version 2.9.2. I just opened a issue for this version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests