From f0e5c8c30ef202dbcb4352b657c60ab6028bdd31 Mon Sep 17 00:00:00 2001 From: Brian Wiborg Date: Thu, 2 Oct 2025 02:04:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20builtin=20section;=20add?= =?UTF-8?q?=20ohmyapi=5Fauth=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 12 ++++++------ docs/README.md | 8 ++++++++ docs/auth.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ mkdocs.yml | 2 ++ 4 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 docs/README.md create mode 100644 docs/auth.md diff --git a/README.md b/README.md index 0963c0b..1db797e 100644 --- a/README.md +++ b/README.md @@ -31,10 +31,10 @@ pipx install ohmyapi ## Docs -See: `docs/` +See `docs/` or: -- [Projects](docs/projects.md) -- [Apps](docs/apps.md) -- [Models](docs/models.md) -- [Migrations](docs/migrations.md) -- [Routes](docs/routes.md) +``` +poetry run mkdocs serve +``` + +Go to: [http://localhost:8000/](http://localhost:8000/) diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..c553ce9 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,8 @@ +# OhMyAPI Docs + +- [Projects](projects.md) +- [Apps](apps.md) +- [Models](models.md) +- [Migrations](migrations.md) +- [Routes](routes.md) +- [Auth/Permissions](auth.md) diff --git a/docs/auth.md b/docs/auth.md new file mode 100644 index 0000000..2526966 --- /dev/null +++ b/docs/auth.md @@ -0,0 +1,45 @@ +# Authentication + +OhMyAPI comes bundled with a builtin authentication app. +Simply add `ohmyapi_auth` to your `INSTALLED_APPS` and configure a `JWT_SECRET`. + +## Enable Auth App + +`settings.py`: + +``` +INSTALLED_APPS = [ + "ohmyapi_auth", + ... +] + +JWT_SECRET = "t0ps3cr3t" +``` + +Remember to `makemigrations` and `migrate` to create the necessary database tables. + +``` +ohmyapi makemigrations +ohmyapi migrate +``` + +## Permissions + +With the `ohmyapi_auth` app comes everything you need to implement API-level permissions. +Use FastAPI's `Depends` pattern in combination with either the provided or custom permissions. + +```python +from ohmyapi.router import APIRouter, Depends + +from ohmyapi_auth import ( + models as auth, + permissions, +) + +router = APIRouter() + + +@router.get("/") +def get(user: auth.User = Depends(permissions.required_authenticated)): + ... +``` diff --git a/mkdocs.yml b/mkdocs.yml index c634233..20db47a 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -7,3 +7,5 @@ nav: - Models: models.md - Migrations: migrations.md - Routes: routes.md + - Builtin: + - Auth / Permissions: auth.md