Skip to content

Instantly share code, notes, and snippets.

@robvanderleek
Last active August 20, 2024 12:27
Show Gist options
  • Save robvanderleek/ab7a2d090d94e785b702b7ef86c7bac4 to your computer and use it in GitHub Desktop.
Save robvanderleek/ab7a2d090d94e785b702b7ef86c7bac4 to your computer and use it in GitHub Desktop.
Setting up Basic Auth in FastAPI for endpoints and static files

Setting up Basic Auth in FastAPI for endpoints and static files

Sometimes you want to share something with the world but don't want to have it publicly accessible, and don't want to setup serious authentication like OAuth. In that case, Basic Auth might be just the type of authentication you're looking for.

Setting up basic auth in FastAPI can be done with a just of couple lines of code, but I could not find in the project's documentation how to do it for both endpoints and static files (e.g. a Web App, or plain HTML files).

Based on this discussion I was able to create a minimal implementation that you can find in this repository. Please see the README in the repository how to run and test the setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment