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

Basic authentication header not send through "Try it out" operation #2075

Closed
gabriel-detassigny opened this issue Apr 6, 2016 · 9 comments · Fixed by #2192
Closed

Basic authentication header not send through "Try it out" operation #2075

gabriel-detassigny opened this issue Apr 6, 2016 · 9 comments · Fixed by #2192
Milestone

Comments

@gabriel-detassigny
Copy link

Hi,

I was trying to use Basic Authentication in Swagger-UI, using the latest master version.

The Authorize button works fine : it shows me a form for basic authentication to set username and password.

However, when I try API endpoints with the "Try it out" button, it doesn't send the corresponding Authorization HTTP header. Am I doing anything wrong? My spec seems ok as far as I can tell.

{
    "swagger": "2.0",
    "info": {
        "title": "API",
        "description": "Internal API",
        "version": "1.0"
    },
    "host": "localhost",
    "basePath": "/",
    "schemes": [
        "http"
    ],
    "produces": [
        "application/json; versions=1"
    ],
    "paths": {
        "/account": {
            "get": {
                "tags": [
                    "account"
                ],
                "summary": "Get the current user account information",
                "responses": {
                    "200": {
                        "description": "User info"
                    }
                },
                "security": [
                    {
                        "login": []
                    }
                ]
            }
        }
    },
    "definitions": {},
    "securityDefinitions": {
        "login": {
            "type": "basic",
            "description": "Basic authentication"
        }
    }
}

Please let me know if you need any more details!

@fehguy
Copy link
Contributor

fehguy commented Apr 6, 2016

Security definitions declare "what" security exists. It doesn't say "where" to apply them. Add a "security" attribute with the name of the scheme (login in your case) on the operations which require it.

@gabriel-detassigny
Copy link
Author

There is already a security attribute, if you look at the /account endpoint:

"security": [
      {
           "login": []
      }

@webron
Copy link
Contributor

webron commented Apr 6, 2016

@fehguy - I've asked @gabriel-detassigny to open this ticket coming from another one. Tested it and it indeed doesn't work.

@FlaxHaxx
Copy link
Contributor

FlaxHaxx commented Jun 4, 2016

I have the same problem when using the latest master version. Clicking the "Try it out!" button doesn't send the Authorization header that was set using the form.

@fehguy
Copy link
Contributor

fehguy commented Jun 4, 2016

OK I've reproduced this. Looks like the security is named basic instead of login when authorizing. I'll send a PR and update this issue.

Jonahss pushed a commit to eaze/swagger-ui that referenced this issue Aug 12, 2016
vincent-zurczak pushed a commit to roboconf/swagger-ui that referenced this issue Aug 19, 2016
@fehguy fehguy added this to the v2.2.1 milestone Aug 23, 2016
kodekracker pushed a commit to 91springboard/swagger-ui that referenced this issue Mar 2, 2017
@sontrananh
Copy link

i have same problem when using swagger ui 3.0.18. Clicking the "Excute" button doesn't send the Authorization header that was set using the form.

@toddsingleton
Copy link

I'm experiencing this same problem in v3.1.7. @sontrananh, were you able to find a workaround?

@webron
Copy link
Contributor

webron commented Sep 5, 2017

Commenting on a closed ticket that was opened on an entirely different version of the project - isn't going to help. If you have an issue, please open a new ticket.

@sontrananh
Copy link

@toddsingleton: i had that problem because i deploy swagger in a server but i deploy service in another server with different ip. And i disable csrf check of browers to fix it

JuanSW18 pushed a commit to Digital-Paw/digital-paw-swagger-ui that referenced this issue Aug 23, 2024
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