swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

Conflict SwaggerUi authorizations with Basic Auth to make requests

Open brubraz opened this issue 10 years ago • 4 comments

Hi,

I found a conflict where swaggerui.authorizations overwrites basic auth to make call to API. For an example, I need to have an authorization to access /api-docs and I put this Authorization on index.html

authorizations: {
          fun: new SwaggerClient.ApiKeyAuthorization("Authorization", 'Basic c3dhZ2dlcjpTSXVUaE9lWW9Vcm...', "header")
        },

Fine, SwaggerUi is able to get api-docs.json. Now, I want to register my Basic Authentication to make calls on API. When I click on Authorize and try to login with basic auth, all my requests send old authorization (auth proved by swaggerUi) instead of using auth proved by myself.

There is a way that I can force SwaggerUi to clear the authorizations after to download api-docs.json?

brubraz avatar Jun 14 '16 07:06 brubraz

yes, in your operations, just create another key name. So you have "fun" for authorizing the /api-docs, but you can assign a requirement for on each operation to use a different auth scheme, other than fun.

fehguy avatar Jun 14 '16 17:06 fehguy

Thanks @fehguy, I tried to find something about assign a requirement for each operation to use a different auth, but I didn't find something that could help me. May you show an example?

brubraz avatar Jun 14 '16 23:06 brubraz

Logout click isn't working here. I'm using last version.

brubraz avatar Jun 15 '16 12:06 brubraz

Take a look at the specification here:

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md

You simply define a security attribute on each operation, with the corresponding name of the securityDefinition.

fehguy avatar Nov 23 '16 23:11 fehguy