question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Authorization header is not sent through swagger

See original GitHub issue

It seems that swagger interface cannot send Authorization header.

I added test_auth endpoint with required header authorization like that:

async def check_auth(
        authorization: str = Header(...)
):
    pass

@router.post("/test_auth")
async def test_auth(
        auth = Depends(check_auth)
):
    pass

This works perfectly if I use REST-client with set Authorization header. But, if I use swagger UI it seems that Authorization header always missing. Server responses with status code 422 and:

  "detail": [
    {
      "loc": [
        "header",
        "authorization"
      ],
      "msg": "field required",
      "type": "value_error.missing"
    }
  ]
}

Another observation is if I change the header name to something else (not authorization) it works. But my goal is using Authorization…

FastAPI version: 0.49.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
phy25commented, Feb 25, 2020

Not sure if you have read: https://github.com/tiangolo/fastapi/issues/612#issuecomment-547886504

For Authorization you can use FastAPI’s HTTPBearer.

That sets the required Authorization header in the right place in OpenAPI and references it from your path operation using it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Authorization Header not being sent from Swagger UI 5.0 ...
The generated UI won't have Authorization fields in each endpoint. There should be open locks on the endpoints that had a security requirement ......
Read more >
Why is the Authorization header missing in requests sent ...
When testing the request (I clicked on "Authorize" button at the top right and entered my token) I get following error: "error": "Authorization...
Read more >
Authorization header not sent by swagger-ui
Hello, I'm trying to configure swagger-ui to send a Basic Auth authorization header. I'm not have any luck so far. ... apiKeyName: "Authorization",...
Read more >
Auth token is not passing through header - the Tyk community
I am trying to use the Authorization token in my swagger JSON documentation. My APIs are already using Bearer tokens for their ...
Read more >
API Keys
You can define the 401 “Unauthorized” response returned for requests with missing or invalid API key. This response includes the WWW-Authenticate header, which ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found