Models API¶
This page describes the default concrete models shipped with Keysmith and the compatibility requirements when swapping them out.
Token¶
Concrete model: keysmith.models.Token.
The token model stores lifecycle state and metadata while keeping the secret itself hashed.
Key fields:
id(UUID primary key)name,descriptioncreated_by,usertoken_type(userorsystem)scopes(ManyToManytoauth.Permission)key(hashed secret)prefixcreated_at,expires_at,last_used_atrevoked,purged
Key helpers:
is_expiredis_activecan_authenticate()mark_used(commit=True)
TokenAuditLog¶
Concrete model: keysmith.models.TokenAuditLog.
Audit rows capture request metadata and lifecycle operations for observability and investigation.
Key fields:
tokenactionpath,method,status_codeip_address,user_agentextra(JSON)created_at
Action constants:
TokenAuditLog.ACTION_AUTH_SUCCESSTokenAuditLog.ACTION_AUTH_FAILEDTokenAuditLog.ACTION_REVOKEDTokenAuditLog.ACTION_ROTATED
Custom Model Configuration¶
If you need custom tables or additional fields, point settings to your model classes.
Configured models are validated by Django system checks at startup.
Required token fields include:
key,prefix,revoked,purged,expires_at,last_used_at,user
Required audit fields include:
token,action,path,method,status_code,ip_address,user_agent,extra,created_at