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

go swagger security auth0 #2403

Open
prchowdh opened this issue Sep 10, 2020 · 4 comments
Open

go swagger security auth0 #2403

prchowdh opened this issue Sep 10, 2020 · 4 comments
Labels
auth API authentication generate spec Related to spec generation from code question

Comments

@prchowdh
Copy link

prchowdh commented Sep 10, 2020

I am trying to achieve this : which is applicable for all my api request

 security:
  - auth0: []

But when I put in my go file and generate the swagger , this is what I get

security:
- auth0:
  - '[]'

Could you please help .

@fredbi
Copy link
Contributor

fredbi commented Nov 14, 2020

@prasenjitChowdhury A security requirement is a map, not an array.
You should try instead:

security:
  auth0: []

@prasenjitChowdhury I've been confused in the above. Let's take it from the beginning again.

We have the security definitions object, defined by the swagger:meta annotation. This one is an object with keys. Each key describes a security scheme.

We have the security requirements array, defined either a the spec level or at the operation level. Each element in this array holds a single key referring to a named security scheme. The value attached to that key is an array.

@fredbi fredbi added auth API authentication question labels Nov 14, 2020
@prchowdh
Copy link
Author

Just tried this , doesn't solve the issue . Producing the same issue

@fredbi fredbi added the generate spec Related to spec generation from code label Nov 17, 2020
@fredbi
Copy link
Contributor

fredbi commented Nov 18, 2020

@prasenjitChowdhury

We might need a more complete excerpt of your annotated code to better understand your issue. Please see below the working examples provided.

I've tested this code again and it works with the swagger:meta annotation:

//     Security:
//     - api_key:
//
//     SecurityDefinitions:
//       api_key:
//          type: apiKey
//          name: KEY
//          in: header
//       oauth2:
//         type: oauth2
//         authorizationUrl: /oauth2/auth
//         tokenUrl: /oauth2/token
//         in: header
//         scopes:
//           bla1: foo1
//           bla2: foo2
//         flow: accessCode
//
// swagger:meta

@fredbi
Copy link
Contributor

fredbi commented Nov 18, 2020

With security requirements at the spec level (swagger:meta), this works:

//
//     Security:
//     - api_key:
//     - oauth2: bla1,bla2
//
//     SecurityDefinitions:
//       api_key:
//          type: apiKey
//          name: KEY
//          in: header
//       oauth2:
//         type: oauth2
//         authorizationUrl: /oauth2/auth
//         tokenUrl: /oauth2/token
//         in: header
//         scopes:
//           bla1: foo1
//           bla2: foo2
//         flow: accessCode
//
// swagger:meta

Produces:

 {
         "api_key": {
          "type": "apiKey",
          "name": "KEY",
          "in": "header",
          "authorizationUrl": ""
         },
         "oauth2": {
          "type": "oauth2",
          "in": "header",
          "flow": "accessCode",
          "authorizationUrl": "/oauth2/auth",
          "tokenUrl": "/oauth2/token",
          "scopes": {
           "bla1": "foo1",
           "bla2": "foo2"
          }
         }
        }

And:

 [
         {
          "api_key": []
         },
         {
          "oauth2": [
           "bla1",
           "bla2"
          ]
         }
        ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auth API authentication generate spec Related to spec generation from code question
Projects
None yet
Development

No branches or pull requests

2 participants