Models¶
BlockUser¶
blockauth.models.BlockUser is the abstract base model for user accounts. Your user model must inherit from it.
from blockauth.models import BlockUser
class User(BlockUser):
# Add custom fields
organization = models.ForeignKey('Organization', null=True, on_delete=models.SET_NULL)
role = models.CharField(max_length=50, default='user')
BlockUser extends Django's AbstractBaseUser and provides fields required by BlockAuth's authentication flows (email, wallet address, verification status, etc.).
Set your model in settings:
OTP¶
blockauth.models.OTP stores one-time passwords for signup confirmation, passwordless login, password reset, and email change.
Key fields:
email-- recipient emailotp-- the code (generated withsecrets.choice())subject-- OTP purpose (OTPSubjectenum: SIGNUP, LOGIN, PASSWORD_RESET, EMAIL_CHANGE)created_at-- timestamp for expiry calculationis_used-- prevents reuse
OTPs expire based on the OTP_VALIDITY setting (default: 1 minute).
TOTP2FA¶
blockauth.totp.models.TOTP2FA stores encrypted TOTP secrets for two-factor authentication.
Key fields:
user-- foreign key to userencrypted_secret-- TOTP secret (encrypted at rest)is_active-- whether 2FA is enabledcreated_at-- setup timestamp
PasskeyCredential¶
blockauth.passkey.models.Credential stores WebAuthn credentials.
Key fields:
id-- UUID primary keyuser-- foreign key to usercredential_id-- WebAuthn credential identifier (binary)public_key-- credential public key (binary)sign_count-- signature counter (clone detection)aaguid-- authenticator attestation GUIDname-- user-provided credential namecreated_at-- registration timestamplast_used_at-- last authentication timestamp
Migrations¶
Run migrations after installing BlockAuth:
BlockAuth's migrations create the OTP, TOTP2FA, and Credential tables. Your user model migration is managed by your app.