How to specify Token URL in swagger ui if you use multi OAuth2PasswordBearer
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
admin_oauth2_schema = OAuth2PasswordBearer(
tokenUrl=path.join(settings.ROOT_PATH + "/auth/admin-token")
)
candidate_oauth2_schema = OAuth2PasswordBearer(
tokenUrl=path.join(settings.ROOT_PATH, "/auth/candidate-token")
)
Description
In my app I have two token urls for different user. So how can I specify one of them in swagger ui? Currently, swagger ui will use one of the token url based on the last oauth Depends you used in your code.
For example in my last router file I use depends candidate_oauth2_schema
than the token url in swagger ui will become /auth/candidate-token
but if I add another API below which uses depends admin_oauth2_schema
then the token url will change to “/auth/admin-token”.
Operating System
Windows
Operating System Details
No response
FastAPI Version
0.70.1
Python Version
3.9.0
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
OAuth 2.0 - Swagger
The flows object can specify multiple flows, but only one of each type. ... tokenUrl, The token URL to use for this flow....
Read more >Security - First Steps - FastAPI
When we create an instance of the OAuth2PasswordBearer class we pass in the tokenUrl parameter. This parameter contains the URL that the client...
Read more >Authorize button in swagger ui of FastAPI - Stack Overflow
What is the use of "Authorize" button and "/token" url both in swagger UI? I have already gone through the fastapi docs but...
Read more >The Ultimate FastAPI Tutorial Part 10 - Auth via JSON Web ...
The Ultimate FastAPI Tutorial Part 10 - Auth via JSON Web Token (JWT). In part 10 of the FastAPI tutorial, we'll look at...
Read more >Explaining FastAPI scopes - Lambert Labs
We recently started using a framework called FastAPI. ... so that developers can consume the APIs in a web interface: Swagger UI or...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have found the solution. You can specify different
scheme_name
for yourOAuth2PasswordBearers
.Example:
This way, Swagger UI will be able to different these two
OAuth2PasswordBearers
and will provide you useful UI to handle multiple oauth2 schemes.Thanks 👍🏻 Was scratching my head for hours lol.