📝 Add builtin section; add ohmyapi_auth docs
This commit is contained in:
parent
e53c206b4e
commit
f0e5c8c30e
4 changed files with 61 additions and 6 deletions
12
README.md
12
README.md
|
|
@ -31,10 +31,10 @@ pipx install ohmyapi
|
||||||
|
|
||||||
## Docs
|
## Docs
|
||||||
|
|
||||||
See: `docs/`
|
See `docs/` or:
|
||||||
|
|
||||||
- [Projects](docs/projects.md)
|
```
|
||||||
- [Apps](docs/apps.md)
|
poetry run mkdocs serve
|
||||||
- [Models](docs/models.md)
|
```
|
||||||
- [Migrations](docs/migrations.md)
|
|
||||||
- [Routes](docs/routes.md)
|
Go to: [http://localhost:8000/](http://localhost:8000/)
|
||||||
|
|
|
||||||
8
docs/README.md
Normal file
8
docs/README.md
Normal file
|
|
@ -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)
|
||||||
45
docs/auth.md
Normal file
45
docs/auth.md
Normal file
|
|
@ -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)):
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
@ -7,3 +7,5 @@ nav:
|
||||||
- Models: models.md
|
- Models: models.md
|
||||||
- Migrations: migrations.md
|
- Migrations: migrations.md
|
||||||
- Routes: routes.md
|
- Routes: routes.md
|
||||||
|
- Builtin:
|
||||||
|
- Auth / Permissions: auth.md
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue