Skip to main content

Authentication API

Manage user authentication, password resets, 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 (AI routes)

The AI chat endpoint (/api/ai/chat) reads user context from request headers rather than verifying a token. The following headers are used:
The AI route middleware does not reject unauthenticated requests. It reads the headers and always passes the request through. Access control is enforced by the plan middleware, which checks x-user-plan and x-stripe-subscription-id.

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.

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.

Request body

Response

Errors

Sign in

Authenticates a user with email and password. On success, creates a database-backed session and 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

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.

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.

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.

GitHub

Redirects to GitHub OAuth flow. Requires GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET to be configured.

Google

Redirects to Google OAuth consent screen. Requires GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET to be configured. The flow requests the openid, email, and profile scopes with offline access. After the user grants consent, 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 grants consent — you do not call it directly. 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. Creates a session and sets the agentbot-session cookie.
  5. 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 RISC well-known configuration endpoint (keys are cached for 24 hours)
  4. Matches the signing key by the kid header claim
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 (legacy)

Receives security event notifications from Google via the RISC (Risk Incident Sharing and Collaboration) protocol. This is the legacy endpoint — new integrations should use POST /api/security/risc instead, which adds token validation, event deduplication, and more granular event handling.
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:

Supported event types

Users are matched by email address.

Response

Errors

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.

Wallet sign in (SIWE)

Sign in using an Ethereum wallet via Sign-In with Ethereum (SIWE). This flow is designed for Base smart wallets and supports ERC-6492 signature verification for pre-deployed wallets.
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

  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.

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.

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.

Errors

Get nonce

Generates a random nonce for use in SIWE message construction. 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

Errors

Refresh Farcaster token

The GET method returns endpoint metadata.

Request body

Response

Errors

Token gating

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

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)

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