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-auth
poetry add wristband-fastapi-auth
pipenv install wristband-fastapi-auth

Configuration

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 Development

To ensure secure state tracking, WristbandAuth uses HTTPS-only cookies. While most modern browsers accommodate http://localhost exceptions, Safari always blocks secure cookies over HTTP, even in local development environments.

Set dangerously_disable_secure_cookies=True in your AuthConfig to 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"]

What’s Next

Next, we’ll add session middleware to manage authenticated user sessions.

Did this page help you?