Skip to main content

Authentication API

Manage user authentication, password resets, passkey (WebAuthn) login, wallet sign-in, Farcaster identity, and token gating.

Auth middleware

The backend uses two authentication patterns depending on the endpoint.

API key authentication (backend core endpoints)

Endpoints such as /api/deployments, /api/openclaw/instances, and per-agent lifecycle routes require a shared API key passed as a bearer token. The key is compared against the configured INTERNAL_API_KEY using a timing-safe comparison.

Standalone auth middleware (requireAuth)

Routes that are not mounted through the main API key middleware can use the standalone requireAuth middleware. This performs the same timing-safe Bearer token verification against INTERNAL_API_KEY and can be applied to individual route handlers. See Security — Auth middleware for an overview of both middleware functions.

Header-based authentication (backend user context)

Backend endpoints that accept user context from the frontend proxy read the following headers. When HMAC_SECRET (or INTERNAL_API_KEY as fallback) is configured, the backend requires a valid HMAC-SHA256 signature to trust these headers. The signature is computed over the string {userId}:{userEmail}:{userRole} using the HMAC_SECRET environment variable (falls back to INTERNAL_API_KEY). The frontend proxy signs these headers before forwarding requests to the backend.
The AI route middleware (/api/ai/chat) reads user context from headers separately from this middleware. Access control on AI routes is enforced by the plan middleware, which validates x-user-plan and x-stripe-subscription-id against the user’s database record. When the database is available, the subscription ID header is cross-referenced against the stored subscription to prevent forgery — a mismatch returns 402 with code SUBSCRIPTION_MISMATCH. If the database is unavailable, the middleware falls back to header-based validation.

Admin middleware

Endpoints that require admin access check the x-user-email header against the ADMIN_EMAILS environment variable. The comparison is case-insensitive — both the configured emails and the request email are normalized to lowercase before matching.

Session authentication (web API)

Most web API endpoints use cookie-based session authentication. The platform issues an agentbot-session cookie upon sign-in that persists for 30 days. After successful authentication, the middleware sets the database-level user context for RLS. All subsequent queries in that request are automatically scoped to the authenticated user’s data. See Security for details. You can retrieve the current session at any time using the Get session endpoint and end it using the Sign out endpoint.

Admin session fallback

The POST /api/provision endpoint supports an admin fallback when the session user ID is missing. The endpoint checks the session email against ADMIN_EMAILS — if it matches, a synthetic session is created and the request proceeds. The body email field is not used for admin detection. This fallback only applies to admin users on the provisioning endpoint — all other session-authenticated endpoints still require a valid session.

Dual authentication

Some endpoints support both session cookies and Bearer API keys, allowing both browser users and programmatic agents to call the same route. The server resolves the caller’s identity in order:
  1. Cookie session / NextAuth JWT — used by browser and dashboard users.
  2. Bearer API key — used by programmatic agent access. The key is hashed with SHA-256 and looked up in the database.
If neither method produces a valid session, the endpoint returns 401 Unauthorized. API keys are created via the keys API and use the ab_ prefix. Include the key in the Authorization header:
Endpoints that support dual authentication are marked with a note in their documentation. Currently supported:

Sign up

Protected by bot detection. Automated or non-browser requests may be rejected.
Registration does not create a session. After a successful sign-up, the client must call POST /api/auth/login to authenticate.
New accounts automatically receive a 7-day free trial. You can check trial status using the trial API.

Request body

Response

The response does not include trial information. Use GET /api/trial to retrieve the trial status after registration.

Errors

Sign in

Authenticates a user with email and password. On success, creates a database-backed session and sets the agentbot-session cookie. This endpoint requires a valid CSRF token in the x-csrf-token or x-xsrf-token request header. Requests without a valid CSRF token are rejected with a 403 error. Rate-limited to 5 attempts per 15 minutes per IP address. After 5 failed attempts, subsequent requests are rejected with a 429 error until the 15-minute window resets.

Request headers

Request body

Response

A Set-Cookie header is included with the agentbot-session token. The cookie is HttpOnly, SameSite=Lax, scoped to /, and expires after 30 days.

Errors

This endpoint replaced the previous NextAuth credentials callback (/api/auth/callback/credentials). If you are migrating from an older integration, update your sign-in requests to use /api/auth/login.

Passkey authentication

Passkey (WebAuthn) endpoints let users register hardware or platform authenticators and sign in without a password. Registration requires an active session; authentication does not. Challenges are hex-encoded strings (prefixed with 0x) and expire after 5 minutes by default. The TTL is configurable via the PASSKEY_CHALLENGE_TTL_MS environment variable.

Register a passkey — get options

Requires session authentication. Returns WebAuthn registration options that the client passes to navigator.credentials.create().

Response

Errors

Register a passkey — verify

Requires session authentication. Verifies the WebAuthn attestation response and stores the new passkey credential.

Request body

Response

Errors

Authenticate with a passkey — get options

Returns WebAuthn authentication options for an existing user. No session is required — the user is identified by email.

Request body

Response

Errors

Authenticate with a passkey — verify

Verifies a WebAuthn assertion and creates a session. On success, sets the agentbot-session cookie.

Request body

Response

A Set-Cookie header is included with the agentbot-session token. The cookie is HttpOnly, SameSite=Lax, scoped to /, and expires after 30 days.

Errors

Get session

Returns the current authenticated user based on the agentbot-session cookie. No request body is required — the session token is read from the cookie automatically.

Response (authenticated)

Response (unauthenticated or expired)

This endpoint always returns 200. Check whether user is null to determine authentication status.

Sign out

Ends the current session by deleting the session record from the database and clearing the agentbot-session cookie. No request body is required.

Response

This endpoint always returns 200 even if no active session exists.

Get CSRF token

Returns a fresh CSRF token for use in requests that require CSRF protection, such as POST /api/auth/login. No authentication required.

Response

Use the header value directly in the x-csrf-token or x-xsrf-token request header when calling endpoints that require CSRF protection.

OAuth sign in

OAuth providers support automatic account linking. If a user with the same email address already exists, the OAuth account is linked to the existing user on first sign-in. This lets users who originally signed up with email and password add an OAuth login without creating a duplicate account.

Google

Redirects to the Google account selector. Requires GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET to be configured. The flow requests the openid, email, and profile scopes with offline access and uses the select_account prompt, which lets the user pick a Google account without forcing re-consent. After the user selects an account, Google redirects back to the callback endpoint below. If GOOGLE_CLIENT_ID is not set, the endpoint redirects to /login?error=GoogleNotConfigured.

Callback

Handles the OAuth authorization code exchange. This endpoint is called by Google after the user selects an account — you do not call it directly. If Google returns an error query parameter (for example, when the user cancels the sign-in), the callback redirects to /login with an appropriate error code without attempting a token exchange. On success the endpoint:
  1. Exchanges the authorization code for an access token.
  2. Fetches the user’s email and name from the Google userinfo API.
  3. Creates a new user if no account with that email exists (automatic account linking applies when a matching email is found).
  4. Links a Google Account record to the user for dual-auth compatibility. If the user already has a linked Google account, this step is skipped. The Account record stores the OAuth access token, refresh token, and token metadata so the user can sign in with either email/password or Google.
  5. Creates a session and sets the agentbot-session cookie.
  6. Redirects to /dashboard.

Errors

The callback redirects to /login with an error query parameter instead of returning JSON:

Cross-Account Protection receiver

Receives security event tokens from Google via the Cross-Account Protection (RISC) protocol. This is the primary receiver for Google security events. It validates the SET JWT, deduplicates events, and takes targeted action depending on the event type.
This endpoint is intended to be called by Google’s RISC infrastructure, not by application clients. You do not need to call it directly.

Request body

The request body is a raw SET (Security Event Token) JWT string. The JWT payload contains:

Token validation

The endpoint validates the incoming JWT before processing:
  1. Checks the issuer is https://accounts.google.com/
  2. Checks the audience matches one of the configured Google client IDs
  3. Fetches Google’s signing keys from the JWKS endpoint discovered via https://accounts.google.com/.well-known/risc-configuration (keys are cached for 24 hours)
  4. Matches the signing key by the kid header claim
  5. Verifies the RS256 signature using the Web Crypto API (crypto.subtle) with the matched RSA public key
If validation fails, the endpoint returns 400.

Event deduplication

Events are deduplicated using the jti claim. Each processed event is stored in the risc_events table. If an event with the same jti has already been processed, it is acknowledged but not acted on again.

Supported event types

Users are matched by Google subject ID (sub) or email address.

Response

Returns 202 Accepted with an empty body on success. Event processing continues asynchronously after the response is sent.

Errors

Health check

Returns the endpoint status and list of supported event types.
For details on how RISC fits into the platform security model and how to configure it in Google Cloud Console, see Security — Google RISC Protocol.

Google RISC webhook (deprecated)

This endpoint is deprecated and returns 410 Gone. Use POST /api/security/risc instead.
This legacy endpoint previously received security event notifications from Google via the RISC protocol. It has been replaced by the POST /api/security/risc endpoint, which adds JWT signature validation, event deduplication, and more granular event handling.

Response

Wallet sign in

Sign in using an Ethereum-compatible wallet. This endpoint supports two wallet types:
  • Base (Coinbase Smart Wallet) — uses Sign-In with Ethereum (SIWE) on Base Mainnet (chain ID 8453). Supports ERC-6492 signature verification for pre-deployed smart wallets.
  • Tempo — uses personal_sign on the Tempo network (chain ID 4217). Users can connect via an injected provider or through wallet.tempo.xyz.
This endpoint replaced the previous NextAuth wallet callback (/api/auth/callback/wallet). If you are migrating from an older integration, update your wallet sign-in requests to use /api/wallet-auth.

How it works (Base)

  1. The client requests a nonce from GET /api/auth/nonce.
  2. The client opens the Base Account SDK popup and requests a SIWE signature on Base Mainnet.
  3. The wallet address, SIWE message, and signature are sent to POST /api/wallet-auth.
  4. The server verifies the signature using viem (which handles ERC-6492 for smart wallets).
  5. If no account exists for the wallet address, a new user is created automatically.
  6. If an account with the same wallet-derived email already exists, the wallet is linked to the existing account.

How it works (Tempo)

  1. The client requests a nonce from GET /api/auth/nonce.
  2. The client connects to the Tempo network (chain ID 0x1079 / 4217) via an injected Ethereum provider or wallet.tempo.xyz. If the chain is not present in the wallet, it is added automatically with RPC URL https://rpc.tempo.xyz.
  3. The client constructs a plaintext message containing the nonce, chain identifier, and timestamp, then signs it with personal_sign.
  4. The wallet address, signed message, signature, and chain: "tempo" are sent to POST /api/wallet-auth.
  5. The server verifies the signature and nonce, then creates or links the user account.

Request body

Tempo message format

When using Tempo wallet sign-in, the signed message follows this format:

Tempo chain parameters

If the user’s wallet does not have the Tempo network configured, the client adds it using:

Response

A Set-Cookie header is included with the agentbot-session token. The cookie is HttpOnly, SameSite=Lax, scoped to /, and expires after 30 days.

Account linking

When a wallet signs in, the system checks for an existing user by the wallet-derived email address (<address>@wallet.agentbot). If a matching user is found, the wallet is linked to that existing account. This prevents duplicate accounts and lets users access the same data regardless of which sign-in method they use. This applies to both Base and Tempo wallet sign-ins.

Errors

Get nonce

Generates a random nonce for use in wallet sign-in message construction (SIWE for Base, plaintext for Tempo). Both GET and POST methods return the same response.

Response

Get current user

Requires session authentication. Returns the current user profile.

Response

Errors

Update profile

You can update your profile using either POST or PATCH.

Request body (POST)

Errors (POST)

Request body (PATCH)

Response (POST and PATCH)

Change password

Request body

Response

Errors

Forgot password

Protected by bot detection. Rate-limited per IP address. Always returns the same response regardless of whether the email exists, to prevent user enumeration.

Request body

Response

Errors

Reset password

Rate-limited per IP address.

Request body

Response

Errors

Farcaster authentication

Verify Farcaster identity

The GET method returns endpoint metadata. The POST method verifies a Farcaster ID token and optionally checks $RAVE token gating on Base.

Request body

Response

The sessionToken is an HMAC-SHA256 signed token in the format {base64url-data}.{base64url-signature}. The data payload contains the following claims: The token is signed using the FARCASTER_SESSION_SECRET environment variable. If not set, the signing key falls back to NEXTAUTH_SECRET. In production, one of these environment variables must be configured — the endpoint returns a 500 error if neither is set. In non-production environments, a build-time placeholder is used when both are missing.
Session tokens are no longer plain base64-encoded JSON. Tokens issued before this change are not compatible with the new HMAC verification and must be refreshed.
In production, the Farcaster verification endpoint now requires FARCASTER_SESSION_SECRET or NEXTAUTH_SECRET to be configured. Requests fail with a 500 error if neither secret is available. This is a breaking change from the previous behavior which used a hardcoded fallback secret in all environments.

Errors

Refresh Farcaster token

The GET method returns endpoint metadata.

Request body

Response

Errors

Token gating

The token gating endpoints check whether a wallet holds sufficient $RAVE tokens on Base mainnet. The following parameters are configurable via environment variables:
These environment variables allow you to change the token address, minimum balance threshold, and RPC endpoint without redeploying. The minBalance, contractAddress, and rpcEndpoint fields in the API responses reflect the currently configured values.

Verify token access (POST)

Checks whether a wallet holds sufficient $RAVE tokens on Base mainnet.

Request body

Response

Errors

Verify token access (GET)

Query parameters

Response

Webhook events

Automatic welcome email on signup

When a new user signs up through an OAuth provider (Google, wallet, or Farcaster), a welcome email is automatically sent to their registered email address. This is triggered by the signIn event when isNewUser is true. The welcome email uses a branded template with example use cases. See transactional email templates for details on the email content and configuration.

Google RISC events (Cross-Account Protection)

The following inbound events are processed by the POST /api/security/risc endpoint when received from Google:

Google RISC events (legacy — deprecated)

The legacy POST /api/auth/google/risc endpoint is deprecated and returns 410 Gone. Migrate to POST /api/security/risc for event handling.