User Authentication

Learn how Wristband SDKs handle user authentication across your backend server and frontend.

User authentication in Wristband follows the Backend Server Integration Pattern, where your backend server handles all authentication with Wristband and your frontend communicates only with your backend server. Wristband provides two types of SDKs for this pattern:

  • Backend server auth SDKs handle the login, callback, and logout flows with Wristband, manage the application session, refresh access tokens, and protect your routes and APIs.
  • Frontend SDKs initialize the user's auth state in the browser by calling your backend server, and redirect users to your backend server's Login and Logout Endpoints.

The pages in this section cover how these SDKs behave at each stage of user authentication.

What the SDKs Handle

The SDKs take care of the protocol-level work so your application only needs to wire up endpoints and decide what happens at a few key points.

AreaHandled by the SDKsHandled by Your Application
ConfigurationFetching missing configuration values from Wristband through auto-configurationProviding the client ID, client secret, and Wristband application vanity domain
LoginResolving the tenant domain, creating the Login State Cookie, and building the redirect to WristbandExposing the Login Endpoint and returning the SDK's redirect
CallbackValidating the Login State Cookie, exchanging the authorization code for tokens, retrieving userinfo, and validating the return URLExposing the Callback Endpoint, creating the session from the callback data, and choosing where to send the user after login
LogoutRevoking the refresh token and building the redirect to Wristband's Logout EndpointExposing the Logout Endpoint and destroying the application session
SessionsStoring the session in an encrypted cookie, and building the Session and Token Endpoint responsesInitializing the session from the callback data, saving and destroying it, and deciding what additional data to store
Token RefreshRefreshing expired access tokens using the refresh tokenHandling failed refreshes, typically by sending the user back to login
Route ProtectionValidating the session or Bearer token on each request through auth middlewareChoosing which routes and APIs require authentication
CSRF ProtectionGenerating CSRF tokens and validating them in the auth middleware, in SDKs that support itEnabling CSRF protection and sending the CSRF token in a request header from the frontend
FrontendLoading the session from the Session Endpoint, caching access tokens from the Token Endpoint, and building login and logout redirectsWrapping the app with the frontend SDK, providing the endpoint URLs, and handling 401 responses from your APIs

The User Authentication Lifecycle

User authentication moves through the following stages, from logging in to logging out:

  1. Login: The frontend redirects the user to your Login Endpoint. The backend server auth SDK resolves the tenant, creates the Login State Cookie, and redirects the user to Wristband to authenticate.
  2. Callback: After authentication, Wristband redirects the user to your Callback Endpoint. The backend server auth SDK completes the login and returns the tokens and user data.
  3. Session: Your Callback Endpoint initializes the application session from the callback data, and the SDK stores it, typically in an encrypted session cookie.
  4. Authenticated Requests: The frontend SDK calls your Session Endpoint to load the user's auth state. The auth middleware validates the session on each protected request, refreshes expired access tokens, and validates CSRF tokens if CSRF protection is enabled.
  5. Logout: The frontend redirects the user to your Logout Endpoint. Your application destroys the session, and the backend server auth SDK revokes the refresh token and redirects the user to Wristband to end the Wristband auth session.

For a protocol-level explanation of this flow, see Login Workflow.

In This Section

  • Backend SDK Configuration: How to configure the backend server auth SDKs, including auto-configuration.
  • Auth Endpoints: The endpoints your backend server exposes and what the SDKs do in each.
  • Session Management: How the SDKs manage encrypted cookie-based sessions.
  • Login: How the SDKs start the login flow and resolve the tenant domain.
  • Callback: How the SDKs complete the login flow, what the callback returns, and how your Callback Endpoint creates the session.
  • Logout: How your Logout Endpoint destroys the session, and how the SDKs revoke refresh tokens and log users out of Wristband.
  • Frontend Integration: How the frontend SDKs work with your backend server's auth endpoints.
  • Protecting Routes and APIs: How the auth middleware protects your routes and APIs.
  • Token Refresh: How the SDKs keep access tokens valid for the life of a session.
  • CSRF Protection: How the SDKs generate and validate CSRF tokens.


Did this page help you?