This Python code sample demonstrates how to implement authorization in a Flask API server using Auth0.
Create a virtual environment under the root project directory:
macOS/Linux:
python3 -m venv venvWindows:
py -3 -m venv venvActivate the virtual environment:
macOS/Linux:
. venv/bin/activateWindows:
venv\Scripts\activateInstall the project dependencies:
pip install -r requirements.txtCreate a .env file under the root project directory and populate it with the following content:
CLIENT_ORIGIN_URL=http://localhost:4040
AUTH0_AUDIENCE=
AUTH0_DOMAIN=Run the project in development mode:
flask runThe API server defines the following endpoints:
GET /api/messages/publicStatus: 200 OK{
"message": "The API doesn't require an access token to share this message."
}GET /api/messages/protectedStatus: 200 OK{
"message": "The API successfully validated your access token."
}GET /api/messages/adminStatus: 200 OK{
"message": "The API successfully recognized you as an admin."
}