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

Cookie Authentication Failed on chrome #5596

Closed
LaysDragon opened this issue Sep 8, 2019 · 3 comments
Closed

Cookie Authentication Failed on chrome #5596

LaysDragon opened this issue Sep 8, 2019 · 3 comments

Comments

@LaysDragon
Copy link

LaysDragon commented Sep 8, 2019

Q&A (please complete the following information)

  • OS: windows 10
  • Browser: chrome
  • Version: 76.0.3809.132 x64
  • Method of installation: dist assets from unpkg (//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js)
  • Swagger-UI version: 3.23.8
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Example Swagger/OpenAPI definition:

{
    "openapi": "3.0.0",
    "info": {
        "title": "API",
        "version": "0.1"
    },
    "servers": [
        {
            "url": "\/api",
            "description": "Default API Server"
        }
    ],
    "paths": {
        "\/account\/current": {
            "get": {
                "operationId": "Current::index",
                "responses": {
                    "200": {
                        "content": {
                            "application\/json": {
                                "schema": {
                                    "$ref": "#\/components\/schemas\/Account"
                                }
                            }
                        }
                    },
                    "401": {
                        "$ref": "#\/components\/responses\/Unauthorized"
                    }
                },
                "security": [
                    {
                        "default": []
                    }
                ]
            }
        },
        "\/v2\/swagger.json": {
            "get": {
                "operationId": "Swagger_json::index",
                "responses": {
                    "200": {
                        "description": "Swagger API Definition"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Account": {
                "properties": {
                    "id": {
                        "type": "integer"
                    }
                },
                "type": "object"
            }
        },
        "responses": {
            "Unauthorized": {
                "description": "Unauthorized"
            }
        },
        "securitySchemes": {
            "default": {
                "type": "apiKey",
                "name": "ci_session",
                "in": "cookie"
            }
        }
    }
}

Swagger-UI configuration options:

const ui = SwaggerUIBundle({
                url: "api/v2/swagger.json",
                dom_id: '#swagger-ui',
                presets: [
                SwaggerUIBundle.presets.apis,
                SwaggerUIBundle.SwaggerUIStandalonePreset
                ]
            })
api/v2/swagger.json

Describe the bug you're encountering

Cannot auth the request with cookie auth method.

To reproduce...

Steps to reproduce the behavior:

  1. Go to GET /account/current
  2. Click on Try it out
  3. Click on Execute
  4. Check request detail in Network in Chrome Developer Tool

Expected behavior

The execute function in Try it out not working as excepted,it ignored the cookie sitting in Security requirement and caused the auth failed and get 401 from my server

Screenshots

Additional context or thoughts

I try to track the stack and found swagger-ui have set the cookie in the request but the fetch function ignored it or using the brower's cookie instead.

image
image

@hkosova
Copy link
Contributor

hkosova commented Sep 9, 2019

Cookie authentication currently does not work in Swagger UI and Swagger Editor because of browser security restrictions that prevent web pages from modifying certain headers (such as Cookie) programmatically. Please see swagger-api/swagger-js#1163 for details and future updates regarding this issue.

A possible workaround is to use the withCredentials option and rely on browser-supplied cookies instead.

@LaysDragon
Copy link
Author

Thanks for reply :3
well I understand the problem now.swagger cannot function properly with cookie auth until somebody set up a extension to help with such cookie setting. for now on I login manually at login api and let brower deal the cookie instead as workaround

@shockey
Copy link
Contributor

shockey commented Sep 28, 2019

Closing as resolved — we'll continue tracking this generally in swagger-api/swagger-js#1163.

@shockey shockey closed this as completed Sep 28, 2019
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

No branches or pull requests

3 participants