This Python code sample demonstrates how to build an API server using FastAPI that is secure by design.
Visit the "FastAPI/Python Code Samples: API Security in Action" section of the "Auth0 Developer Resources" to explore how you can secure FastAPI applications written in Python by implementing endpoint protection and authorization with Auth0.
Auth0 is a flexible drop-in solution to add authentication and authorization services to your applications. Your team and organization can avoid the cost, time, and risk that come with building your own solution to authenticate and authorize users. We offer tons of guidance and SDKs for you to get started and integrate Auth0 into your stack easily.
Python 3.10 pip 22.2.2
Create a virtual environment under the root project directory:
macOS/Linux:
python3 -m venv venvWindows:
py -3 -m venv venvThen, activate the virtual environment:
macOS/Linux:
. venv/bin/activateWindows:
venv\Scripts\activatepip install -r requirements.txtCreate a .env file under the root project directory:
touch .envNext, populate it with the following environment variables:
PORT=6060
CLIENT_ORIGIN_URL=http://localhost:4040
RELOAD=Truepython3 application/main.py