Multi-Strategy Auth for Django SDK
๐ฃ Wristband Django Auth SDK 1.0.0 Release ๐
Release v1.0.0
Breaking Changes
Migration Guide: https://github.com/wristband-dev/django-auth/blob/main/migration/v1/README.md
๐ CallbackResult Structure Changes
The CallbackResult model now uses a discriminated union pattern with explicit variant types.
Migration:
- Use
isinstance()checks instead of comparingcallback_result.type - Import new result types:
CompletedCallbackResult,RedirectRequiredCallbackResult - No more
assertstatements needed - type narrowing is automatic - New
reasonfield added toRedirectRequiredCallbackResult
๐ Query Parameter and URL Placeholder Standardization
Query Parameters:
tenant_domainโtenant_name
URL Placeholders:
{tenant_domain}โ{tenant_name}({tenant_domain}is deprecated but still supported for backward compatibility)
๐๏ธ Session Management Changes
Session Engine:
- New encrypted cookie-based session engine:
wristband.django_auth.sessions.backends.encrypted_cookies - Session fields now stored directly in
request.sessioninstead of nested underrequest.session['wristband'] - New
session_from_callback()helper function for populating sessions
Session Configuration:
WRISTBAND_SESSION_SECRETrequired for encrypted cookie sessions- Session fields include
is_authenticatedflag for authentication validation
๐ก๏ธ Authentication Protection Changes
Removed:
@wristband_auth_requireddecorator removedWristbandAuthRequiredMixinmixin removed
New Factory Methods:
create_auth_decorator()- Create configurable authentication decoratorscreate_auth_mixin()- Create configurable authentication mixinscreate_drf_session_auth()- Create Django REST Framework session authentication classescreate_drf_jwt_auth()- Create Django REST Framework JWT authentication classes
Migration:
- Authentication logic now embedded in decorators/mixins instead of custom middleware
- Must explicitly create decorator/mixin instances with desired strategy and behavior
- No need to write or maintain custom authentication middleware
๐ค Django User Synchronization Changes
New Authentication Backend:
WristbandAuthBackendhandles automatic User creation and synchronization- Adapter pattern for customizing user field mapping and role synchronization
Migration:
- Add
wristband.django_auth.WristbandAuthBackendtoAUTHENTICATION_BACKENDS - Use
authenticate()andlogin()instead of manual User object creation - Create custom adapter class for role mapping instead of inline logic
- Must include
profileandrolesscopes for full User synchronization
New Features
๐ JWT Authentication Support
New JWT bearer token authentication powered by @wristband/python-jwt.
Features:
- Stateless JWT validation with JWKS
- Configurable JWK cache size and TTL
- Decoded JWT payload available in
request.auth.payload - Raw JWT string available in
request.auth.jwt - Full type safety with TypedDict models
โจ Multi-Strategy Authentication
Support multiple authentication strategies with fallback behavior.
Supported Strategies:
SESSION- Django session authentication with automatic token refreshJWT- Bearer token authentication with JWKS validation
Features:
- Try multiple strategies in order until one succeeds
- Automatic access token refresh for expired tokens (SESSION strategy)
- Automatic CSRF token refresh for rolling sessions (SESSION strategy)
- Rolling session windows (SESSION strategy)
- Configurable JWKS caching (JWT strategy)
๐ Callback Failure Reasons
CallbackResult now includes a reason field when isinstance(callback_result, RedirectRequiredCallbackResult):
MISSING_LOGIN_STATE- Login state cookie not foundINVALID_LOGIN_STATE- Login state validation failedLOGIN_REQUIRED- Wristband returned login_required errorINVALID_GRANT- Authorization code was invalid or expired
๐ Django REST Framework Support
New DRF Authentication Classes:
create_drf_session_auth()- Session-based authentication for DRFcreate_drf_jwt_auth()- JWT-based authentication for DRF
Features:
- Native DRF
authentication_classessupport - Combine multiple authentication strategies in single view
- Works with DRF's
IsAuthenticatedpermission - Requires
djangorestframework>=3.15.0
๐ฆ Enhanced Session Management
New Helper Functions:
session_from_callback()- Populate session from callback dataget_session_response()- Create session response for frontend SDKsget_token_response()- Create token response for frontend SDKs
New Session Engine:
- Encrypted cookie-based sessions with AES-256-GCM
- Stateless session storage with no database required
- Configurable session expiration and cookie security
๐ฏ Authentication Backend and Adapters
New Components:
WristbandAuthBackend- Django authentication backend for WristbandDefaultWristbandAuthBackendAdapter- Default user field mapping- Custom adapter pattern for role mapping and permissions
Features:
- Automatic Django User creation and synchronization
- Customizable user field mapping via adapters
- Role-based group and permission assignment
- Support for passing custom data to adapters via
**kwargs
For full documentation, see the README.