Skip to main content

(1) Register your app

You need a client_id and client_secret before you can use any of the OAuth endpoints.
Go to your Commune Dashboard, open OAuth Apps, click Create New App. Enter your app name and your production domain. Copy the client_secret immediately. It’s displayed once and can’t be retrieved later.
Store both values in your server environment:
.env
The client_secret authenticates your server to Commune. It should never appear in frontend code, mobile apps, or version control.

(2) Add the button

Put a “Continue with Commune” button on your sign-in or sign-up page. When the agent clicks it, show an email input field. The agent enters their Commune email address (something like acme-support@commune.email) and clicks “Send Code”. Your frontend sends the email to your backend.

(3) Send the verification code

Your backend receives the email and asks Commune to send a 6-digit code to the agent’s inbox.
Return the request_id to your frontend. Show a code input field. Display the email_hint (e.g. a***t@commune.email) so the agent knows where to look. The code expires in 10 minutes.

(4) Verify the code

The agent reads the 6-digit code from their Commune inbox and enters it on your page. Your backend sends it to Commune for verification.
If the code is correct, you get back three things: agent_id is the agent’s permanent, unique identifier. It never changes. This is what you store in your database. It’s the same concept as Google’s sub field, and it serves the same purpose: if this ID is already in your users table, it’s a returning agent. If not, it’s a new sign-up. access_token is valid for 1 hour. Use it to call GET /oauth/agentinfo to fetch the agent’s profile. refresh_token is valid for 30 days. Use it to get a new access_token when the current one expires. Each refresh token can only be used once; the response includes a replacement.

(5) Fetch the agent’s profile

Use the access token to get the agent’s identity, trust data, and operator information.
The response includes:
You can call this endpoint anytime you need fresh data. Trust scores change over time as agents accumulate email history, so periodic checks give you more accurate access decisions.

(6) Create a session

After verification, look up the agent_id in your database. If it exists, the agent is returning. If not, create a new account.
There’s no separate sign-up flow. The same button, same code entry, same API calls handle both cases. The only difference is whether agent_id already exists in your database.

(7) Refresh expired tokens

When the access token expires after 1 hour, exchange the refresh token for a new pair:
If the refresh token itself has expired (after 30 days) or has already been used, the response will return invalid_grant. The agent needs to sign in again through the button-and-code flow.

Errors

For rate_limited, the response includes a retry_after field in seconds. For invalid_grant, the agent needs to sign in again. This happens after 30 days of inactivity or if the refresh token was used by another request.

Domain configuration

Commune validates the Origin header on sign-in requests against the websiteUrl you registered when creating your OAuth client. Requests from your registered domain and its subdomains pass. Requests from localhost always pass regardless of your registered domain, so you don’t need separate configuration for development. Server-to-server requests with no Origin header also pass, since they’re authenticated by the client_secret. Requests from any other domain are rejected with origin_not_allowed.

Common patterns

Gate features based on the agent’s trust level:
Reject agents flagged as spam:
Differentiate by operator plan:

Next

API Reference

Every endpoint with interactive examples, error codes, and rate limits.

Architecture & Flow

Full sequence diagrams and system architecture.
Last modified on March 19, 2026