Install Auth SDK
Learn how to configure the Wristband SDK for your FastAPI application.
After setting up FastAPI, you'll need to install and configure the Wristband FastAPI SDK. We'll be using this SDK throughout the quickstart guide to help facilitate the integration between your application and Wristband.
Installation
Install the Wristband Auth SDK using your preferred package manager CLI:
pip install wristband-fastapi-auth
poetry add wristband-fastapi-auth
pipenv install wristband-fastapi-auth
Configuration
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 The SDK
Create a WristbandAuth
instance in your FastAPI project’s source root (e.g., src/auth/wristband.py
) and configure its AuthConfig
properties with your application’s values. This centralizes authentication setup and provides a shared SDK instance across your application. You’ll also create an auth dependency that verifies requests have a valid session using wristband_auth.create_session_auth_dependency()
.
Secure Cookies in Local Development (Login State)
If you encounter cookie issues on
http://localhost
(some browsers like Safari block secure cookies), temporarily setdangerously_disable_secure_cookies=True
inAuthConfig
. Just remember to remove this setting before deploying to production.
# 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>",
)
)
# Auth dependency that verifies a valid user session for protected routes.
require_session_auth = wristband_auth.create_session_auth_dependency()
# Explicitly define what can be imported in your project
__all__ = ["require_session_auth", "wristband_auth"]
Updated about 8 hours ago
Next, we’ll set up session management to begin handling the user’s authentication state.