
* Implement Transport classes * Implement authentication strategy classes * Revamp authentication with Transport and Strategy * Revamp strategy and OAuth so that they can use a callable dependency * Update docstring * Make ErrorCode a proper Enum and cleanup unused OpenAPI utils * Remove useless check * Tweak typing in authenticator * Update docs * Improve logout/destroy token logic * Update docs * Update docs * Update docs and full examples * Apply formatting to examples * Update OAuth doc and examples * Add migration doc * Implement Redis session token * Add Redis Session documentation * RedisSession -> Redis * Fix links in docs
2.6 KiB
Full example
Here is a full working example with JWT authentication to help get you started.
!!! warning Notice that SECRET should be changed to a strong passphrase. Insecure passwords may give attackers full access to your database.
SQLAlchemy
Open :octicons-link-external-16:
=== ":octicons-file-code-16: requirements.txt"
```
--8<-- "examples/sqlalchemy/requirements.txt"
```
=== ":octicons-file-code-16: main.py"
```py
--8<-- "examples/sqlalchemy/main.py"
```
=== ":octicons-file-code-16: app/app.py"
```py
--8<-- "examples/sqlalchemy/app/app.py"
```
=== ":octicons-file-code-16: app/db.py"
```py
--8<-- "examples/sqlalchemy/app/db.py"
```
=== ":octicons-file-code-16: app/models.py"
```py
--8<-- "examples/sqlalchemy/app/models.py"
```
=== ":octicons-file-code-16: app/users.py"
```py
--8<-- "examples/sqlalchemy/app/users.py"
```
MongoDB
Open :octicons-link-external-16:
=== ":octicons-file-code-16: requirements.txt"
```
--8<-- "examples/mongodb/requirements.txt"
```
=== ":octicons-file-code-16: main.py"
```py
--8<-- "examples/mongodb/main.py"
```
=== ":octicons-file-code-16: app/app.py"
```py
--8<-- "examples/mongodb/app/app.py"
```
=== ":octicons-file-code-16: app/db.py"
```py
--8<-- "examples/mongodb/app/db.py"
```
=== ":octicons-file-code-16: app/models.py"
```py
--8<-- "examples/mongodb/app/models.py"
```
=== ":octicons-file-code-16: app/users.py"
```py
--8<-- "examples/mongodb/app/users.py"
```
Tortoise ORM
Open :octicons-link-external-16:
=== ":octicons-file-code-16: requirements.txt"
```
--8<-- "examples/tortoise/requirements.txt"
```
=== ":octicons-file-code-16: main.py"
```py
--8<-- "examples/tortoise/main.py"
```
=== ":octicons-file-code-16: app/app.py"
```py
--8<-- "examples/tortoise/app/app.py"
```
=== ":octicons-file-code-16: app/db.py"
```py
--8<-- "examples/tortoise/app/db.py"
```
=== ":octicons-file-code-16: app/models.py"
```py
--8<-- "examples/tortoise/app/models.py"
```
=== ":octicons-file-code-16: app/users.py"
```py
--8<-- "examples/tortoise/app/users.py"
```
What now?
You're ready to go! Be sure to check the Usage section to understand how to work with FastAPI Users.