Install Auth SDK
Learn how to configure the Wristband SDK for your Django application.
Installation
Install Wristband's Django Auth SDK using your preferred package manager:
pip install wristband-django-authpoetry add wristband-django-authpipenv install wristband-django-authConfiguration
Prerequisites
Before you can configure the SDK, you'll need to make sure you have the following values:
- WRISTBAND_APPLICATION_VANITY_DOMAIN
- WRISTBAND_CLIENT_ID
- WRISTBAND_CLIENT_SECRET
If you went through the Set Up a Wristband Application guide, you should have been presented with these three values after the application was provisioned. If you don't have the above values on hand, you can retrieve them from the Wristband dashboard by following the steps in this guide.
Configure Wristband Settings
Add your Wristband auth configuration to your Django settings file (src/your_project/settings.py):
Disabling Secure Cookies in Local DevelopmentBy default, the SDK creates secure cookies (for tracking login state), meaning they are only sent over HTTPS connections. Most browsers make an exception for
localhostand allow secure cookies to be sent over HTTP (e.g.,http://localhost). However, some browsers, such as Safari, enforce stricter rules and never send secure cookies over HTTP, even forlocalhost.If you need to disable the secure cookies for local development, set
"dangerously_disable_secure_cookies": True. However, be sure to re-enable secure cookies before deploying to production.
# your_project/settings.py
# ...your other settings...
WRISTBAND_AUTH = {
"client_id": "<WRISTBAND_CLIENT_ID>",
"client_secret": "<WRISTBAND_CLIENT_SECRET>",
"wristband_application_vanity_domain": "<WRISTBAND_APPLICATION_VANITY_DOMAIN>"
}# your_project/settings.py
# ...your other settings...
WRISTBAND_AUTH = {
"client_id": "<WRISTBAND_CLIENT_ID>",
"client_secret": "<WRISTBAND_CLIENT_SECRET>",
"wristband_application_vanity_domain": "<WRISTBAND_APPLICATION_VANITY_DOMAIN>",
"dangerously_disable_secure_cookies": True
}Initialize The SDK
Create an instance of WristbandAuth in a dedicated module within your Django app (e.g., src/your_app/wristband.py). Update the AuthConfig properties with the values from your settings:
# your_app/wristband.py
from django.conf import settings
from wristband.django_auth import AuthConfig, WristbandAuth
# Initialize Wristband SDK
wristband_auth = WristbandAuth(AuthConfig(**settings.WRISTBAND_AUTH))
__all__ = ['wristband_auth']Add Session Auth Decorator
You'll also need to create an auth decorator to verify that incoming requests have a valid authenticated session. You can do this using the wristband_auth.create_auth_decorator() factory method. Later, you'll use this decorator to protect views that require authentication.
After adding the auth decorator, the file should look like the following:
# your_app/wristband.py
from django.conf import settings
from wristband.django_auth import (
AuthConfig,
AuthStrategy,
UnauthenticatedBehavior,
WristbandAuth,
)
wristband_auth = WristbandAuth(AuthConfig(**settings.WRISTBAND_AUTH))
# NEW: Create require_session auth decorator
require_session = wristband_auth.create_auth_decorator(
strategies=[AuthStrategy.SESSION],
on_unauthenticated=UnauthenticatedBehavior.REDIRECT,
)
__all__ = ['wristband_auth', 'require_session'] # <-- UPDATE: Add 'require_session'Updated about 3 hours ago
Now that the SDK is installed and configured, you'll need to set up session management.