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

For Token Authorization to work need to specify authorizations = { @Authorization(value="Authorization") } #2661

Closed
ngawor opened this issue Sep 5, 2018 · 13 comments

Comments

@ngawor
Copy link

ngawor commented Sep 5, 2018

Using swagger2-2.9.2 and swagger-ui-2.9.2:

Previous token authentication stopped working from 2.5 (the token is no longer being passed). In order to resolve this, I had to add:

authorizations = { @authorization(value="Authorization") }

to every method I wanted to pass the token. This wasn't necessary in previous versions, and my code did not change.

I see some discussion of this here:
#2194

but it is marked closed.

@selvaebi
Copy link

selvaebi commented Sep 6, 2018

Same issue with me , am using RepositoryRestResource so couldnt include for all methods

@selvaebi
Copy link

selvaebi commented Sep 6, 2018

Sorry , it is working @ngawor u can use the below config,


  .securitySchemes(Arrays.asList(new ApiKey("Authorization","Authorization","header")))
                .securityContexts(Arrays.asList(securityContext))
                .alternateTypeRules(getSubstitutionRules());

    SecurityReference securityReference = SecurityReference.builder()
            .reference("Authorization")
            .scopes(new AuthorizationScope[0])
            .build();

    SecurityContext securityContext = SecurityContext.builder()
            .securityReferences(Arrays.asList(securityReference))
            .build();

@ngawor
Copy link
Author

ngawor commented Sep 6, 2018

This worked - thank you @selvaebi ! I think the documentation needs to be updated to reflect this is necessary.

@MartinTopchyan
Copy link

@ngawor can you send me your swagger configuration?? the same bug in my swagger but my conf does not work

@selvaebi
Copy link

Hi @MartinTopchyan the above config will work perfectly , can you paste ur config , let we check we can help.

@MartinTopchyan
Copy link

MartinTopchyan commented Sep 13, 2018

ApiInfo apiInfo() {
    return new ApiInfoBuilder()
        .title("")
        .description("")
        .termsOfServiceUrl("")
        .version(this.projectVersion)
        .contact(new Contact("", "", ""))
        .build();
  }

  @Bean
  public Docket api() {
    return new Docket(DocumentationType.SWAGGER_2)
        .select()
        .apis(RequestHandlerSelectors.basePackage(""))
        .paths(PathSelectors.any())
        .build()
        .enable(true)
        .apiInfo(apiInfo())
        .securitySchemes(Arrays.asList(apiKey()))
        .securityContexts(Arrays.asList(securityContext));
  }

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

  SecurityReference securityReference = SecurityReference.builder()
      .reference("Authorization")
      .scopes(new AuthorizationScope[0])
      .build();

  SecurityContext securityContext = SecurityContext.builder()
      .securityReferences(Arrays.asList(securityReference))
      .build();

This is my swagger config

@MartinTopchyan
Copy link

@selvaebi

@selvaebi
Copy link

ahh the reference name should match , change to SecurityReference.builder()
.reference("apiKey") or new ApiKey("Authorization", "Authorization", "header");

@MartinTopchyan
Copy link

@selvaebi am I understand you right??
SecurityReference securityReference = SecurityReference.builder()
.reference("apiKey")
.scopes(new AuthorizationScope[0])
.build();

@MartinTopchyan
Copy link

@selvaebi Thank you so much it works perfect

@dilipkrish
Copy link
Member

Thanks everyone for jumping in to answer questions! I'll add a note to document it. Would anyone of you have the bandwidth to help with a PR to help with documenting it?

@stale
Copy link

stale bot commented Jun 24, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 24, 2020
@stale
Copy link

stale bot commented Jul 8, 2020

This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue.

@stale stale bot closed this as completed Jul 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants