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] Can't send Authorization header through Swagger

See original GitHub issue

Describe the bug I can’t send Authorization header using Swagger. If i using ANY name, even authorization_, i can send this header, but not clear Authorization header.

Screenshots “None” or “…” in Header() don’t cause any effect except 422 validation error. My code:

@auth_routes.get(
    '/userInfo',
    response_model=AuthResult,
    summary="Getting current user's info from session",
    responses={**ADDITIONAL_RESPONSES}
)
async def get_current_user_info(authorization_: str = Header(...)) -> AuthResult:
    user_info: AuthResult = await auth_service.get_user_info(authorization)
    return user_info

Valid header authorization (or Authorization, name of variable don’t cause any effect on Swagger’s side): Right

Wrong header authorization_ or any x-some-header and etc. : Wrong As we can see, Swagger just sent -H "authorization-:*token*

Environment: Windows 10 on testing machine Ubuntu 16.04 LTS on VPS

Python 3.7 fastapi==0.41.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:5
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
tiangolocommented, Oct 30, 2019

It’s part of the OpenAPI spec.

https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#fixed-fields-10

You cannot declare headers of Accept, Content-Type, or Authorization.

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.

0reactions
wesleymr59commented, Sep 6, 2022

Good morning, my name is Wesley.

I’m facing the same problem regarding the “Authorization” header using the Fast-Api-Jwt lib, if anyone has the solution and can share I will be extremely grateful

Att.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable To Send Bearer Token in Authorization Header In ...
I am able to add the securitySchemes + child options and I get the green Authorize button in my swagger docs, but when...
Read more >
How to Use Swagger Inspector
If you don't have any authentication, headers, or query parameters to add, press Send. The Send button becomes enabled once you've put a...
Read more >
Authorization header not sent by swagger-ui - Google Groups
Firebug does not show the Authorization header getting sent and the API is responding with a 401. You can take a look yourself...
Read more >
Auth token is not passing through header - the Tyk community
Our Nodejs REST API is using the JWT token for authentication. When we are trying to send the request from the Tyk where...
Read more >
Add an authorization header to your swagger-ui with ...
Once you've done that, when you “Try it out” using the Swagger-UI, the authorization header with your bearer token should be sent to...
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