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:
Admin middleware
Endpoints that require admin access check thex-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 anagentbot-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
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
agentbot-session cookie.
Request body
Response
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
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
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
GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET to be configured.
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
- Exchanges the authorization code for an access token.
- Fetches the user’s email and name from the Google userinfo API.
- Creates a new user if no account with that email exists (automatic account linking applies when a matching email is found).
- Creates a session and sets the
agentbot-sessioncookie. - Redirects to
/dashboard.
Errors
The callback redirects to/login with an error query parameter instead of returning JSON:
Cross-Account Protection receiver
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:- Checks the issuer is
https://accounts.google.com/ - Checks the audience matches one of the configured Google client IDs
- Fetches Google’s signing keys from the RISC well-known configuration endpoint (keys are cached for 24 hours)
- Matches the signing key by the
kidheader claim
400.
Event deduplication
Events are deduplicated using thejti 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
Returns202 Accepted with an empty body on success. Event processing continues asynchronously after the response is sent.
Errors
Health check
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)
POST /api/security/risc instead, which adds token validation, event deduplication, and more granular event handling.
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)
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
- The client requests a nonce from
GET /api/auth/nonce. - The client opens the Base Account SDK popup and requests a SIWE signature on Base Mainnet.
- The wallet address, SIWE message, and signature are sent to
POST /api/wallet-auth. - The server verifies the signature using viem (which handles ERC-6492 for smart wallets).
- If no account exists for the wallet address, a new user is created automatically.
- If an account with the same wallet-derived email already exists, the wallet is linked to the existing account.
Request body
Response
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
GET and POST methods return the same response.
Response
Get current user
Response
Errors
Update profile
You can update your profile using eitherPOST or PATCH.
Request body (POST)
Errors (POST)
Request body (PATCH)
Response (POST and PATCH)
Change password
Request body
Response
Errors
Forgot password
Request body
Response
Errors
Reset password
Request body
Response
Errors
Farcaster authentication
Verify Farcaster identity
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
GET method returns endpoint metadata.
Request body
Response
Errors
Token gating
Verify token access (POST)
$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 thePOST /api/security/risc endpoint when received from Google:
Google RISC events (legacy)
The following inbound events are processed by thePOST /api/auth/google/risc endpoint when received from Google: