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

and or for authentication #1149

Open
Lehp opened this issue Feb 25, 2022 · 7 comments · May be fixed by #1659
Open

and or for authentication #1149

Lehp opened this issue Feb 25, 2022 · 7 comments · May be fixed by #1659

Comments

@Lehp
Copy link
Contributor

Lehp commented Feb 25, 2022

Is your feature request related to a problem? Please describe.
I have to declare multiple possibiliteies of authentication. My Yaml file needs to look like image+ but i don't know if it's possible to configure this.

Describe the solution you'd like
I would like to be able to declare multiple options for a parameter

Describe alternatives you've considered
Using Tag multiple time is not accepted by our tool. like @description test @description test2
Desired Result

@ubogdan
Copy link
Contributor

ubogdan commented Mar 3, 2022

I never used the Oauth part. Any input is welcome.

@akojo @sdghchj @Nerzal

@sdghchj
Copy link
Member

sdghchj commented Mar 4, 2022

I never used the Oauth part. Any input is welcome.

@akojo @sdghchj @Nerzal

Me too.

@akojo
Copy link
Contributor

akojo commented Apr 14, 2022

I'm a bit late to the game here, but looking at the OpenAPI v2 spec it defines security as being a list of security requirement objects (ORed together), each of which can contain multiple security requirements (ANDed). That is, the most general form for a security requirement would look like:

security:
- BasicAuth: []
  OAuth2Application:
  - write:pets
  - read:pets
- ApiKeyAuth: []

Which would specify one of two authentication options:

  • Basic auth and Oauth2 application auth
  • API key auth

Considering this it would be best to allow multiple @Security tags to specify a list of security requirement and then additionally some special syntax to handle the rarer cases of ANDing requirements. For the above example swag annotations would then look like:

// @Security BasicAuth && Oauth2Application[write:pets, read:pets]
// @Security ApiKeyAuth

A bit less contrived example: allowing either API key or basic authentication would then be simply

// @Security ApiKeyAuth
// @Security BasicAuth

which would translate to

security:
- BasicAuth: []
- ApiKeyAuth: []

@lucasoares
Copy link

Would be nice to be able to configure multiple security tags.

In my use case I need to configure two authentications, both using headers and right now I can't. I created a code to modify the generated json to include my own security definition :(

@Lehp
Copy link
Contributor Author

Lehp commented May 25, 2022

I don't know what exactly you want but the "OR" functionality i implemented works like this
image

So This should be possible:

image

@akojo @lucasoares

@lucasoares
Copy link

I don't know what exactly you want but the "OR" functionality i implemented works like this image

So This should be possible:

image

@akojo @lucasoares

I was having trouble to configure multiple security definitions but now I got it.

The problem I'm having now is to apply the same security for every single handler without the need to copy paste the @Security to each handler.

@bekabaz
Copy link

bekabaz commented May 31, 2023

I don't know what exactly you want but the "OR" functionality i implemented works like this image
So This should be possible:
image
@akojo @lucasoares

I was having trouble to configure multiple security definitions but now I got it.

The problem I'm having now is to apply the same security for every single handler without the need to copy paste the @Security to each handler.

Isn't that a bug with the usage of || as an AND? || implies an OR, however that generated swagger doc is in the format of an AND. If I'm wrong I apologize

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

Successfully merging a pull request may close this issue.

6 participants