tortoise-auth 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tortoise_auth-0.2.0/.github/workflows/python-publish.yml +25 -0
- tortoise_auth-0.2.0/.gitignore +209 -0
- tortoise_auth-0.2.0/LICENSE +21 -0
- tortoise_auth-0.2.0/PKG-INFO +30 -0
- tortoise_auth-0.2.0/README.md +93 -0
- tortoise_auth-0.2.0/docs/getting-started/installation.md +95 -0
- tortoise_auth-0.2.0/docs/getting-started/quickstart.md +368 -0
- tortoise_auth-0.2.0/docs/guides/authentication.md +413 -0
- tortoise_auth-0.2.0/docs/guides/configuration.md +340 -0
- tortoise_auth-0.2.0/docs/guides/events.md +378 -0
- tortoise_auth-0.2.0/docs/guides/password-hashing.md +337 -0
- tortoise_auth-0.2.0/docs/guides/password-validation.md +325 -0
- tortoise_auth-0.2.0/docs/guides/signing.md +359 -0
- tortoise_auth-0.2.0/docs/guides/token-backends.md +442 -0
- tortoise_auth-0.2.0/docs/guides/user-model.md +290 -0
- tortoise_auth-0.2.0/docs/index.md +86 -0
- tortoise_auth-0.2.0/docs/integrations/starlette.md +393 -0
- tortoise_auth-0.2.0/docs/reference/api.md +1516 -0
- tortoise_auth-0.2.0/docs/reference/configuration-options.md +213 -0
- tortoise_auth-0.2.0/docs/reference/exceptions.md +311 -0
- tortoise_auth-0.2.0/docs/roadmap.md +54 -0
- tortoise_auth-0.2.0/mkdocs.yml +61 -0
- tortoise_auth-0.2.0/pyproject.toml +118 -0
- tortoise_auth-0.2.0/tests/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/conftest.py +19 -0
- tortoise_auth-0.2.0/tests/models.py +24 -0
- tortoise_auth-0.2.0/tests/test_config.py +64 -0
- tortoise_auth-0.2.0/tests/test_events.py +199 -0
- tortoise_auth-0.2.0/tests/test_hashers/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_hashers/test_argon2.py +53 -0
- tortoise_auth-0.2.0/tests/test_hashers/test_bcrypt.py +49 -0
- tortoise_auth-0.2.0/tests/test_hashers/test_migration.py +49 -0
- tortoise_auth-0.2.0/tests/test_integrations/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_integrations/conftest.py +29 -0
- tortoise_auth-0.2.0/tests/test_integrations/test_starlette.py +286 -0
- tortoise_auth-0.2.0/tests/test_models/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_models/test_api_keys.py +0 -0
- tortoise_auth-0.2.0/tests/test_models/test_totp.py +0 -0
- tortoise_auth-0.2.0/tests/test_models/test_user.py +109 -0
- tortoise_auth-0.2.0/tests/test_rate_limit/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_rate_limit/test_database.py +0 -0
- tortoise_auth-0.2.0/tests/test_rate_limit/test_memory.py +0 -0
- tortoise_auth-0.2.0/tests/test_services/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_services/test_api_keys.py +0 -0
- tortoise_auth-0.2.0/tests/test_services/test_auth.py +300 -0
- tortoise_auth-0.2.0/tests/test_services/test_password.py +0 -0
- tortoise_auth-0.2.0/tests/test_services/test_registration.py +0 -0
- tortoise_auth-0.2.0/tests/test_services/test_totp.py +0 -0
- tortoise_auth-0.2.0/tests/test_signing.py +151 -0
- tortoise_auth-0.2.0/tests/test_tokens/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_tokens/test_jwt.py +437 -0
- tortoise_auth-0.2.0/tests/test_validators/__init__.py +0 -0
- tortoise_auth-0.2.0/tests/test_validators/test_validators.py +136 -0
- tortoise_auth-0.2.0/tortoise_auth/__init__.py +65 -0
- tortoise_auth-0.2.0/tortoise_auth/config.py +101 -0
- tortoise_auth-0.2.0/tortoise_auth/events.py +69 -0
- tortoise_auth-0.2.0/tortoise_auth/exceptions.py +73 -0
- tortoise_auth-0.2.0/tortoise_auth/hashers/__init__.py +61 -0
- tortoise_auth-0.2.0/tortoise_auth/hashers/argon2.py +20 -0
- tortoise_auth-0.2.0/tortoise_auth/hashers/bcrypt.py +11 -0
- tortoise_auth-0.2.0/tortoise_auth/hashers/pbkdf2.py +61 -0
- tortoise_auth-0.2.0/tortoise_auth/integrations/__init__.py +1 -0
- tortoise_auth-0.2.0/tortoise_auth/integrations/starlette.py +142 -0
- tortoise_auth-0.2.0/tortoise_auth/models/__init__.py +10 -0
- tortoise_auth-0.2.0/tortoise_auth/models/api_keys.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/models/base.py +85 -0
- tortoise_auth-0.2.0/tortoise_auth/models/jwt_blacklist.py +37 -0
- tortoise_auth-0.2.0/tortoise_auth/models/rate_limit.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/models/totp.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/py.typed +0 -0
- tortoise_auth-0.2.0/tortoise_auth/rate_limit/__init__.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/rate_limit/database.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/rate_limit/memory.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/services/__init__.py +5 -0
- tortoise_auth-0.2.0/tortoise_auth/services/api_keys.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/services/auth.py +151 -0
- tortoise_auth-0.2.0/tortoise_auth/services/password.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/services/registration.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/services/totp.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/signing.py +97 -0
- tortoise_auth-0.2.0/tortoise_auth/tokens/__init__.py +49 -0
- tortoise_auth-0.2.0/tortoise_auth/tokens/api_keys.py +0 -0
- tortoise_auth-0.2.0/tortoise_auth/tokens/jwt.py +211 -0
- tortoise_auth-0.2.0/tortoise_auth/utils.py +35 -0
- tortoise_auth-0.2.0/tortoise_auth/validators/__init__.py +54 -0
- tortoise_auth-0.2.0/tortoise_auth/validators/common.py +30 -0
- tortoise_auth-0.2.0/tortoise_auth/validators/common_passwords.txt +19640 -0
- tortoise_auth-0.2.0/tortoise_auth/validators/length.py +22 -0
- tortoise_auth-0.2.0/tortoise_auth/validators/numeric.py +16 -0
- tortoise_auth-0.2.0/tortoise_auth/validators/similarity.py +45 -0
- tortoise_auth-0.2.0/uv.lock +1227 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
id-token: write
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
name: Build & publish
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
environment: pypi
|
|
15
|
+
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- uses: astral-sh/setup-uv@v4
|
|
20
|
+
|
|
21
|
+
- name: Build package
|
|
22
|
+
run: uv build
|
|
23
|
+
|
|
24
|
+
- name: Publish to PyPI
|
|
25
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
#poetry.toml
|
|
110
|
+
|
|
111
|
+
# pdm
|
|
112
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
113
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
114
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
115
|
+
#pdm.lock
|
|
116
|
+
#pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# pixi
|
|
121
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
122
|
+
#pixi.lock
|
|
123
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
124
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
125
|
+
.pixi
|
|
126
|
+
|
|
127
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
128
|
+
__pypackages__/
|
|
129
|
+
|
|
130
|
+
# Celery stuff
|
|
131
|
+
celerybeat-schedule
|
|
132
|
+
celerybeat.pid
|
|
133
|
+
|
|
134
|
+
# SageMath parsed files
|
|
135
|
+
*.sage.py
|
|
136
|
+
|
|
137
|
+
# Environments
|
|
138
|
+
.env
|
|
139
|
+
.envrc
|
|
140
|
+
.venv
|
|
141
|
+
env/
|
|
142
|
+
venv/
|
|
143
|
+
ENV/
|
|
144
|
+
env.bak/
|
|
145
|
+
venv.bak/
|
|
146
|
+
|
|
147
|
+
# Spyder project settings
|
|
148
|
+
.spyderproject
|
|
149
|
+
.spyproject
|
|
150
|
+
|
|
151
|
+
# Rope project settings
|
|
152
|
+
.ropeproject
|
|
153
|
+
|
|
154
|
+
# mkdocs documentation
|
|
155
|
+
/site
|
|
156
|
+
|
|
157
|
+
# mypy
|
|
158
|
+
.mypy_cache/
|
|
159
|
+
.dmypy.json
|
|
160
|
+
dmypy.json
|
|
161
|
+
|
|
162
|
+
# Pyre type checker
|
|
163
|
+
.pyre/
|
|
164
|
+
|
|
165
|
+
# pytype static type analyzer
|
|
166
|
+
.pytype/
|
|
167
|
+
|
|
168
|
+
# Cython debug symbols
|
|
169
|
+
cython_debug/
|
|
170
|
+
|
|
171
|
+
# PyCharm
|
|
172
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
173
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
174
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
175
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
176
|
+
#.idea/
|
|
177
|
+
|
|
178
|
+
# Abstra
|
|
179
|
+
# Abstra is an AI-powered process automation framework.
|
|
180
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
181
|
+
# Learn more at https://abstra.io/docs
|
|
182
|
+
.abstra/
|
|
183
|
+
|
|
184
|
+
# Visual Studio Code
|
|
185
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
186
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
187
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
188
|
+
# you could uncomment the following to ignore the entire vscode folder
|
|
189
|
+
# .vscode/
|
|
190
|
+
|
|
191
|
+
# Ruff stuff:
|
|
192
|
+
.ruff_cache/
|
|
193
|
+
|
|
194
|
+
# PyPI configuration file
|
|
195
|
+
.pypirc
|
|
196
|
+
|
|
197
|
+
# Cursor
|
|
198
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
199
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
200
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
201
|
+
.cursorignore
|
|
202
|
+
.cursorindexingignore
|
|
203
|
+
|
|
204
|
+
# Marimo
|
|
205
|
+
marimo/_static/
|
|
206
|
+
marimo/_lsp/
|
|
207
|
+
__marimo__/
|
|
208
|
+
|
|
209
|
+
.idea
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Software Family
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tortoise-auth
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Async authentication and user management for Tortoise ORM. Framework-agnostic, extensible, secure by default.
|
|
5
|
+
Project-URL: Homepage, https://github.com/elie/tortoise-auth
|
|
6
|
+
Project-URL: Documentation, https://elie.github.io/tortoise-auth
|
|
7
|
+
Project-URL: Repository, https://github.com/elie/tortoise-auth
|
|
8
|
+
Project-URL: Issues, https://github.com/elie/tortoise-auth/issues
|
|
9
|
+
Author: Elie
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: 2fa,api-keys,async,auth,authentication,tortoise-orm,totp,user-management
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Framework :: AsyncIO
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Security
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.12
|
|
24
|
+
Requires-Dist: pwdlib[argon2,bcrypt]>=0.2
|
|
25
|
+
Requires-Dist: pyjwt>=2.8
|
|
26
|
+
Requires-Dist: pyotp>=2.9
|
|
27
|
+
Requires-Dist: qrcode[pil]>=7.4
|
|
28
|
+
Requires-Dist: tortoise-orm>=0.21
|
|
29
|
+
Provides-Extra: starlette
|
|
30
|
+
Requires-Dist: starlette>=0.27; extra == 'starlette'
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# tortoise-auth
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
**Async authentication and user management for Tortoise ORM.**
|
|
8
|
+
Framework-agnostic, extensible, secure by default.
|
|
9
|
+
|
|
10
|
+
**tortoise-auth** is a pure-async authentication library built on top of
|
|
11
|
+
[Tortoise ORM](https://tortoise.github.io/). It provides a complete user
|
|
12
|
+
authentication stack — password hashing, token issuance, session management,
|
|
13
|
+
HMAC signing, and lifecycle events — without coupling you to any particular web
|
|
14
|
+
framework. Define your user model, call `configure()`, and you have a
|
|
15
|
+
production-ready auth layer that works with FastAPI, Starlette, Sanic, or any
|
|
16
|
+
other async Python framework.
|
|
17
|
+
|
|
18
|
+
> [!WARNING]
|
|
19
|
+
> **This project is under active development (v0.2.0, Alpha).** The public API
|
|
20
|
+
> may change between releases. Use in production at your own risk.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- **Abstract User model** — extend `AbstractUser` to get email-based
|
|
25
|
+
authentication, password hashing, `is_active` / `is_verified` flags, and
|
|
26
|
+
timestamp tracking out of the box.
|
|
27
|
+
- **AuthService** — high-level async API for `login`, `authenticate`,
|
|
28
|
+
`refresh`, `logout`, and `logout_all`.
|
|
29
|
+
- **Pluggable token backends** — choose between stateless **JWT** tokens or
|
|
30
|
+
server-side **database** tokens, swappable with a single config flag.
|
|
31
|
+
- **Multi-algorithm password hashing** — Argon2id (primary), Bcrypt, and
|
|
32
|
+
PBKDF2-SHA256 with transparent auto-migration to the strongest hasher.
|
|
33
|
+
- **Password validation** — four built-in validators (minimum length, common
|
|
34
|
+
password list, numeric-only, user-attribute similarity) plus custom validators
|
|
35
|
+
via the `PasswordValidator` Protocol.
|
|
36
|
+
- **HMAC signing** — `Signer`, `TimestampSigner`, and convenience helpers
|
|
37
|
+
`make_token` / `verify_token` for email-confirmation links, password-reset
|
|
38
|
+
URLs, and other signed payloads.
|
|
39
|
+
- **Event system** — subscribe to `user_login`, `user_login_failed`,
|
|
40
|
+
`user_logout`, and `password_changed` events with async handlers.
|
|
41
|
+
- **Fully async** — every I/O operation uses `await`; no hidden synchronous
|
|
42
|
+
calls.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install tortoise-auth
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
or with [uv](https://docs.astral.sh/uv/):
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
uv add tortoise-auth
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Quick Start
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from tortoise_auth import AbstractUser, AuthConfig, AuthService, configure
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class User(AbstractUser):
|
|
63
|
+
"""Application user model."""
|
|
64
|
+
|
|
65
|
+
class Meta:
|
|
66
|
+
table = "users"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Configure the library
|
|
70
|
+
configure(AuthConfig(
|
|
71
|
+
user_model="models.User",
|
|
72
|
+
jwt_secret="your-secret-key",
|
|
73
|
+
))
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
# Usage (inside an async context)
|
|
77
|
+
auth = AuthService()
|
|
78
|
+
result = await auth.login("user@example.com", "password123")
|
|
79
|
+
user = await auth.authenticate(result.access_token)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
> [!CAUTION]
|
|
83
|
+
> The snippet above uses a literal `jwt_secret` for brevity. In production,
|
|
84
|
+
> always load secrets from environment variables or a dedicated secrets manager.
|
|
85
|
+
|
|
86
|
+
## Requirements
|
|
87
|
+
|
|
88
|
+
- Python 3.12+
|
|
89
|
+
- Tortoise ORM 0.21+
|
|
90
|
+
|
|
91
|
+
## License
|
|
92
|
+
|
|
93
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
## Requirements
|
|
4
|
+
|
|
5
|
+
Before installing `tortoise-auth`, make sure your environment meets the following minimum
|
|
6
|
+
requirements:
|
|
7
|
+
|
|
8
|
+
| Dependency | Minimum version |
|
|
9
|
+
|-----------------|-----------------|
|
|
10
|
+
| Python | 3.12+ |
|
|
11
|
+
| Tortoise ORM | 0.21+ |
|
|
12
|
+
|
|
13
|
+
!!! note
|
|
14
|
+
`tortoise-auth` uses modern Python features such as type aliases, `type` statements,
|
|
15
|
+
and generic built-in types that require **Python 3.12 or later**.
|
|
16
|
+
|
|
17
|
+
## Install tortoise-auth
|
|
18
|
+
|
|
19
|
+
=== "pip"
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
pip install tortoise-auth
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
=== "uv"
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
uv add tortoise-auth
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Transitive dependencies
|
|
32
|
+
|
|
33
|
+
When you install `tortoise-auth`, the following packages are pulled in automatically.
|
|
34
|
+
You do **not** need to install them separately.
|
|
35
|
+
|
|
36
|
+
| Package | Purpose |
|
|
37
|
+
|---------------------------|------------------------------------------------------------------------------------------------------|
|
|
38
|
+
| `tortoise-orm` >=0.21 | Async ORM built on top of `asyncio`. Provides the model layer that `tortoise-auth` extends. |
|
|
39
|
+
| `pwdlib[argon2,bcrypt]` >=0.2 | Password hashing library. Includes the **Argon2** and **bcrypt** backends out of the box. |
|
|
40
|
+
| `pyotp` >=2.9 | One-time password generation and verification for TOTP-based two-factor authentication. |
|
|
41
|
+
| `qrcode[pil]` >=7.4 | QR code generation used when setting up TOTP with authenticator apps. |
|
|
42
|
+
|
|
43
|
+
## Database driver
|
|
44
|
+
|
|
45
|
+
Tortoise ORM requires an async database driver. `tortoise-auth` does not bundle one because the
|
|
46
|
+
choice depends on which database you use in your project.
|
|
47
|
+
|
|
48
|
+
Install the driver that matches your database:
|
|
49
|
+
|
|
50
|
+
=== "SQLite (development)"
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
pip install aiosqlite
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
=== "PostgreSQL"
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install asyncpg
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
=== "MySQL / MariaDB"
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install asyncmy
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
!!! warning
|
|
69
|
+
SQLite is convenient for local development and testing, but it is **not recommended for
|
|
70
|
+
production**. Use PostgreSQL or MySQL for production deployments.
|
|
71
|
+
|
|
72
|
+
## Verify the installation
|
|
73
|
+
|
|
74
|
+
Open a Python shell and confirm that the package is importable and reports the expected version:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
import tortoise_auth
|
|
78
|
+
|
|
79
|
+
print(tortoise_auth.__version__)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
You should see output similar to:
|
|
83
|
+
|
|
84
|
+
```text
|
|
85
|
+
0.1.0
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
!!! tip
|
|
89
|
+
If the import fails with a `ModuleNotFoundError`, make sure you are running the Python
|
|
90
|
+
interpreter from the same virtual environment where you installed the package.
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
Next step: head over to the [Quick Start](quickstart.md) guide to configure `tortoise-auth` and
|
|
95
|
+
create your first user.
|