https://github.com/auth0-developer-hub/api_flask_python_hello-world
https://github.com/auth0-developer-hub/api_flask_python_hello-world
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/auth0-developer-hub/api_flask_python_hello-world
- Owner: auth0-developer-hub
- Created: 2021-12-07T19:54:39.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-24T17:51:14.000Z (about 4 years ago)
- Last Synced: 2024-04-23T21:56:32.733Z (about 2 years ago)
- Language: Python
- Size: 16.6 KB
- Stars: 14
- Watchers: 0
- Forks: 13
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Hello World API: Flask Auth0 Sample
This Python code sample demonstrates how to implement authorization in a Flask API server using Auth0.
## Run the Project
Create a virtual environment under the root project directory:
**macOS/Linux:**
```bash
python3 -m venv venv
```
**Windows:**
```bash
py -3 -m venv venv
```
Activate the virtual environment:
**macOS/Linux:**
```bash
. venv/bin/activate
```
**Windows:**
```bash
venv\Scripts\activate
```
Install the project dependencies:
```bash
pip install -r requirements.txt
```
Create a `.env` file under the root project directory and populate it with the following content:
```bash
CLIENT_ORIGIN_URL=http://localhost:4040
AUTH0_AUDIENCE=
AUTH0_DOMAIN=
```
Run the project in development mode:
```bash
flask run
```
## API Endpoints
The API server defines the following endpoints:
### 🔓 Get public message
```bash
GET /api/messages/public
```
#### Response
```bash
Status: 200 OK
```
```json
{
"message": "The API doesn't require an access token to share this message."
}
```
### 🔐 Get protected message
```bash
GET /api/messages/protected
```
#### Response
```bash
Status: 200 OK
```
```json
{
"message": "The API successfully validated your access token."
}
```
### 🔐 Get admin message
```bash
GET /api/messages/admin
```
#### Response
```bash
Status: 200 OK
```
```json
{
"message": "The API successfully recognized you as an admin."
}
```