An open API service indexing awesome lists of open source software.

https://github.com/jtemporal/minimal-fastapi-api-auth0


https://github.com/jtemporal/minimal-fastapi-api-auth0

Last synced: 11 months ago
JSON representation

Awesome Lists containing this project

README

          

# FastAPI Demo API with Auth0

This application is a sample on how to integrate Auth0 for authentication in a FastAPI API using APIRouter and module separation.

## How to run the API

1. Clone this repository
```
git clone https://github.com/jtemporal/minimal-fastapi-api-auth0.git && cd minimal-fastapi-api-auth0
```

2. Create a `.config` file from `.config.example` and populate the values from your Auth0 Application.
```
cp .config.example .config
```
Tip: you can use `openssl rand -hex 32` for the secret key.

3. Create a virtual environment and install dependencies

```
# Create a venv
python3 -m venv .env

# Activate
source .env/bin/activate

# Install dependencies
pip install -r requirements.txt
```

4. Start the server

```
uvicorn src.main:app --reload
```

## Making requests to the API

### Call a public endpoint

```sh
curl -X GET http://localhost:8000/api/public
```

### Call a private endpoint

```sh
curl -X GET http://localhost:8000/api/private
-H "Authorization: Bearer " \
-H "Content-Type: application/json"
```

### Call a private endpoint with scopes

```sh
curl -X GET http://localhost:8000/api/private-scoped
-H "Authorization: Bearer " \
-H "Content-Type: application/json"
```

----

Where to find me:
* [Jess' Socials](https://jtemporal.com/socials).

[Sign up for Auth0's developer newsletter here](https://a0.to/nl-signup/python).