Persistent Authorization in FastAPI Swagger UI
Table of Contents
When testing authenticated endpoints in FastAPI’s Swagger UI, you normally lose your bearer token every time you refresh the page. This gets annoying fast when you’re actively developing.
The Fix #
Add persistAuthorization: True to your Swagger UI parameters:
| |
That’s it. Your authorization token is now stored in the browser’s local storage and survives page refreshes.
Why This Matters #
During development, you might refresh Swagger UI dozens of times per session. Without persistence, each refresh means:
- Click “Authorize”
- Paste your token
- Click “Authorize” again
- Close the modal
With this one-liner, you authenticate once and forget about it until the token expires.