Forked from Auth0 Blog | FastAPI Example
I've updated this repo to the latest versions of all the packages, moved from pip to poetry, and add some test files and mocking examples.
- Python 3.12
- Pyenv or asdf recommended
- Poetry
- just
The configuration you'll need is mostly information from Auth0, you'll need both the tentant domain and the API information.
This app reads its configuration information from a .env file by default.
To create a .env file you can copy the .env.example file and fill the values accordingly:
cp .env.example .envpython3 -m venv .venv
just install
just runTry calling http://localhost:8000/api/public
curl -X 'GET' \
'http://localhost:8000/api/public' \
-H 'accept: application/json'Access http://localhost:8000/docs. From there you'll see all endpoints and can test your API
You can then try to do a GET to http://localhost:8000/api/private which will throw an error if you don't send an access token signed with RS256 with the appropriate issuer and audience in the Authorization header.
curl -X 'GET' \
'http://localhost:8000/api/private' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <FILL YOUR TOKEN HERE>'You can also try to do a GET to http://localhost:8000/api/private-scoped which will throw an error if you don't send an access token with the scope read:messages signed with RS256 with the appropriate issuer and audience in the Authorization header.
curl -X 'GET' \
'http://localhost:8000/api/private-scoped' \
-H 'accept: application/json' \
-H 'Authorization: Bearer <FILL YOUR TOKEN WITH SCOPES HERE>'