Install Auth SDK
Discover how to configure the Wristband SDK for your FastAPI application.
Installation
Install the Wristband Auth SDK via your package manager CLI:
pip install wristband-fastapi-authpoetry add wristband-fastapi-authpipenv install wristband-fastapi-authConfiguration
Prerequisites
Ensure you have the following values ready before configuring the SDK:
- WRISTBAND_APPLICATION_VANITY_DOMAIN
- WRISTBAND_CLIENT_ID
- WRISTBAND_CLIENT_SECRET
These three credentials are shown right after application provisioning in the Wristband Application Setup flow. If you need to find them again, check the steps in our retrieval guide.
Configure the SDK
Instantiate WristbandAuth in your project's source root (e.g., src/auth/wristband.py) and map your application values to the AuthConfig properties.
Disabling Secure Cookies in Local DevelopmentTo ensure secure state tracking,
WristbandAuthusesHTTPS-only cookies. While most modern browsers accommodatehttp://localhostexceptions, Safari always blocks secure cookies overHTTP, even in local development environments.Set
dangerously_disable_secure_cookies=Truein yourAuthConfigto allow local HTTP testing. Important: Remember to turn secure cookies back on for production environments.
# src/auth/wristband.py
from wristband_fastapi_auth import WristbandAuth, AuthConfig
# Initialize Wristband FastAPI Auth SDK
wristband_auth: WristbandAuth = WristbandAuth(
AuthConfig(
client_id="<WRISTBAND_CLIENT_ID>",
client_secret="<WRISTBAND_CLIENT_SECRET>",
wristband_application_vanity_domain="<WRISTBAND_APPLICATION_VANITY_DOMAIN>",
)
)# src/auth/wristband.py
from wristband_fastapi_auth import WristbandAuth, AuthConfig
# Initialize Wristband FastAPI Auth SDK
wristband_auth: WristbandAuth = WristbandAuth(
AuthConfig(
client_id="<WRISTBAND_CLIENT_ID>",
client_secret="<WRISTBAND_CLIENT_SECRET>",
wristband_application_vanity_domain="<WRISTBAND_APPLICATION_VANITY_DOMAIN>",
dangerously_disable_secure_cookies=True,
)
)Add Session Auth Dependency
Generate an authentication dependency using wristband_auth.create_session_auth_dependency() to check for valid sessions. This dependency will be used later to enforce route protection.
Here is how your file should look after adding the session dependency:
# src/auth/wristband.py
from wristband_fastapi_auth import WristbandAuth, AuthConfig
wristband_auth = WristbandAuth(
AuthConfig(
client_id="<WRISTBAND_CLIENT_ID>",
client_secret="<WRISTBAND_CLIENT_SECRET>",
wristband_application_vanity_domain="<WRISTBAND_APPLICATION_VANITY_DOMAIN>",
)
)
# NEW: Create an auth dependency that verifies a request has a valid session.
require_session_auth = wristband_auth.create_session_auth_dependency()
# NEW: Explicitly define what can be imported in your project
__all__ = ["require_session_auth", "wristband_auth"]Updated 11 days ago
What’s Next
Next, we’ll add session middleware to manage authenticated user sessions.