fast-api-oauth

Example oauth with fast-api

Installation

Poetry

Install Poetry

Install dependencies

poetry install

API Server

Run server

Run server with:

poetry run uvicorn oauth_app.main:app --reload

API

Available at: http://localhost:8000/

OpenAPI docs

Visit http://localhost:8000/docs#/

Database

Start the database

Start the database with:

docker-compose up

Initialize Database

To initialize the database with migrations and a superuser run:

python run_init_db.py

Migrations

1. Make changes to models or add new models

  • If changes were made to existing models:

    1. Create a new revision with:
      alembic revision --autogenerate -m "Updated model"
  • If a new model was added:

    1. Import it into oauth_app.app.database.base
    2. Create a new revision with:
      alembic revision --autogenerate -m "New model"

2. Commit changes to database

Commit the new revisions to the database with:

alembic upgrade head

Tests

Requirements

Must have docker and docker-compose installed

Run tests

Run tests with:

pytest -s -v