Native async auth for Quart
Project description
quart-security
quart-security is a native async authentication extension for Quart.
It is designed as a practical replacement path for Flask-Security style session auth in Quart applications, without Flask shims and without Flask-Login.
What You Get
Core auth
- Session-based login and logout
- Email/password registration
- Password change flow (including OAuth-style users that don’t know an initial random password)
current_userproxy@auth_required("session")and@roles_required(...)
MFA
- TOTP setup and verification
- Recovery code generation and one-time consumption
WebAuthn (passkeys / security keys)
- Credential registration
- Passwordless sign-in (first factor)
- Authenticated verification flow (step-up / second factor)
- Credential deletion
Extension and compatibility surface
- Quart extension pattern (
Security(app, datastore)) - Flask-Security-style endpoint naming through
url_for_security() - Signals for auth lifecycle events
- Overridable templates under
templates/security/ - Datastore hooks can be implemented as async methods or simple sync methods
Non-Goals (Current Scope)
This project intentionally focuses on session auth and MFA currently in active use:
- No token-based API auth
- No SMS/email OTP
- No account locking workflow
- No remember-me token system
Installation
Install from repository
uv add git+https://github.com/level09/quart-security.git
Local development
uv sync --group dev
uv run pytest -q
Package build backend: flit.
Quick Integration
from quart import Quart
from quart_security import Security, SQLAlchemyUserDatastore
# your models should include fields used by auth, roles, and MFA/WebAuthn
from myapp.models import db, User, Role, WebAuthnCredential
def create_app():
app = Quart(__name__)
app.config.update(
SECRET_KEY="change-me",
SECURITY_PASSWORD_SALT="change-me-too",
SECURITY_POST_LOGIN_VIEW="/dashboard",
SECURITY_POST_REGISTER_VIEW="/login",
)
db.init_app(app)
datastore = SQLAlchemyUserDatastore(
db,
User,
Role,
webauthn_model=WebAuthnCredential,
)
Security(app, datastore)
return app
Required Model Surface
Your user/role models are expected to provide the fields used by active features.
Minimum practical user fields:
fs_uniquifieremailpasswordactiveroles
For tracking / MFA / WebAuthn features:
last_login_at,current_login_at,last_login_ip,current_login_ip,login_counttf_primary_method,tf_totp_secret,mf_recovery_codesfs_webauthn_user_handle- relationship/association for stored WebAuthn credentials
Optional for lockout support:
failed_login_countlocked_until
Key Configuration
The extension uses SECURITY_* keys for migration-friendly configuration.
Core:
SECURITY_PASSWORD_HASH(default:pbkdf2_sha512)SECURITY_PASSWORD_SALT(recommended)SECURITY_PASSWORD_LENGTH_MIN(default:12)SECURITY_LOGIN_MAX_ATTEMPTS(default:5)SECURITY_LOCKOUT_MINUTES(default:15)SECURITY_REGISTERABLESECURITY_CHANGEABLESECURITY_TRACKABLESECURITY_CSRF_PROTECT(default:True)
2FA:
SECURITY_TWO_FACTORSECURITY_TOTP_ISSUERSECURITY_MULTI_FACTOR_RECOVERY_CODESSECURITY_MULTI_FACTOR_RECOVERY_CODES_N
WebAuthn:
SECURITY_WEBAUTHNSECURITY_WAN_ALLOW_AS_FIRST_FACTORSECURITY_WAN_ALLOW_AS_MULTI_FACTORSECURITY_WAN_RP_ID(optional override)SECURITY_WAN_RP_NAME(optional override)SECURITY_WAN_EXPECTED_ORIGIN(optional override)SECURITY_WAN_REQUIRE_USER_VERIFICATION(default:True)
Routing:
SECURITY_POST_LOGIN_VIEWSECURITY_POST_REGISTER_VIEW
Route Map
Core:
/login/register/logout/change
2FA:
/tf-setup/tf-validate/tf-select/mf-recovery-codes/mf-recovery
WebAuthn:
/wan-register/wan-register-response/wan-signin/wan-signin-response/wan-verify/wan-verify-response/wan-delete
Template Overrides
Default templates are intentionally simple and framework-neutral.
Override by placing templates with the same names under your app’s
templates/security/ directory.
Public API
from quart_security import (
Security,
SQLAlchemyUserDatastore,
current_user,
auth_required,
roles_required,
UserMixin,
RoleMixin,
hash_password,
verify_password,
user_authenticated,
user_logged_out,
password_changed,
tf_profile_changed,
user_registered,
url_for_security,
)
Testing
Project tests cover:
- password hashing/validation
- auth and role decorators
- register/login/logout/change-password
- TOTP and recovery code flows
- WebAuthn register/sign-in/verify/delete route behavior
Run:
uv run pytest -q
WebAuthn staging validation (recommended before release tags)
Run this in a HTTPS staging environment with production-like hostnames and real browser prompts:
- Register a passkey from
/wan-registerand verify it is persisted with expectedname,usage, andsign_count. - Complete passwordless sign-in from
/wan-signinwith the same credential. - Complete authenticated verify flow from
/wan-verifywhile already signed in. - Delete credential from
/wan-deleteand confirm subsequent passkey auth fails for that credential. - Repeat step 1 and step 2 with a second authenticator type (for example platform passkey + hardware key) to validate device portability assumptions.
Notes for Production
- Run behind HTTPS for WebAuthn in non-local environments.
- Set explicit WebAuthn RP values (
SECURITY_WAN_RP_ID,SECURITY_WAN_EXPECTED_ORIGIN) when behind proxies or multiple domains. - Keep CSRF protection enabled unless you have a deliberate replacement.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quart_security-1.2.1.tar.gz.
File metadata
- Download URL: quart_security-1.2.1.tar.gz
- Upload date:
- Size: 23.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06a66a912e8d52bc5ed7976f8f7268471e05dd56cc8e3a5879dcfdf13f34c667
|
|
| MD5 |
4f392c200149d79f08f15eef8098f1f3
|
|
| BLAKE2b-256 |
a807a9ae6c1218066b75a4c8a67c56c388990d81a5223b19512b2631253089f0
|
Provenance
The following attestation bundles were made for quart_security-1.2.1.tar.gz:
Publisher:
publish.yml on level09/quart-security
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quart_security-1.2.1.tar.gz -
Subject digest:
06a66a912e8d52bc5ed7976f8f7268471e05dd56cc8e3a5879dcfdf13f34c667 - Sigstore transparency entry: 1179759934
- Sigstore integration time:
-
Permalink:
level09/quart-security@bb70bb2251fb5df071f04e6c7aff8eab93c8d42a -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/level09
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bb70bb2251fb5df071f04e6c7aff8eab93c8d42a -
Trigger Event:
release
-
Statement type:
File details
Details for the file quart_security-1.2.1-py3-none-any.whl.
File metadata
- Download URL: quart_security-1.2.1-py3-none-any.whl
- Upload date:
- Size: 31.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2979844e1b6d8aa17a2166edbc0e75c372ef80f1f7902c6f4e6b5f7dfc673c3
|
|
| MD5 |
6aabf6afc815f55cf3ab213a65c78226
|
|
| BLAKE2b-256 |
39e8451b0238b32a2cb95a6fcfe49ee10a6056c4a9ce3cf2c49e9bd82bd85382
|
Provenance
The following attestation bundles were made for quart_security-1.2.1-py3-none-any.whl:
Publisher:
publish.yml on level09/quart-security
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
quart_security-1.2.1-py3-none-any.whl -
Subject digest:
d2979844e1b6d8aa17a2166edbc0e75c372ef80f1f7902c6f4e6b5f7dfc673c3 - Sigstore transparency entry: 1179759968
- Sigstore integration time:
-
Permalink:
level09/quart-security@bb70bb2251fb5df071f04e6c7aff8eab93c8d42a -
Branch / Tag:
refs/tags/v1.2.1 - Owner: https://github.com/level09
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@bb70bb2251fb5df071f04e6c7aff8eab93c8d42a -
Trigger Event:
release
-
Statement type: