Sign in with Arsel (OAuth)
If your product works with your customers' Arsel accounts (syncing contacts, creating campaigns, sending messages for them), use OAuth instead of asking each customer for an API key. The customer clicks Connect Arsel in your app, signs in to Arsel, picks an organization and clicks Allow. Your app gets a token for that organization, and the customer can disconnect it at any time.
Arsel runs a standard OAuth 2.1 authorization server: authorization code flow with PKCE, rotating refresh tokens, and self-service client registration. The Arsel MCP server uses the same flow.
OAuth or an API key?
| OAuth | API key | |
|---|---|---|
| Use when | Your app acts for other Arsel customers | Your own server calls the API for your own organization |
| Who connects | An admin of the customer's organization, in the browser | Anyone holding the be_ key |
| What you store | A refresh token per connection | One key |
| Lifetime | Access tokens last 15 minutes and refresh; the connection lasts until it is disconnected | One year from creation |
| Revoked from | Integrations > Connected apps, or by your app | Integrations > API keys |
Choose your setup
| Your app | Register with | Redirect URI |
|---|---|---|
| A web app with a backend | A client ID metadata document on your domain | https:// on that domain |
| A desktop app or CLI | A metadata document if you have a website, otherwise dynamic registration | http://127.0.0.1/… (see Desktop apps and CLIs) |
| A mobile app | A metadata document on your domain | A private-use scheme such as com.example.app:/oauth/callback |
| An MCP client | Either; most MCP hosts already do this for you | Whatever the host uses |
Every app follows the same flow below, and none of them gets a client secret.
How it works
Endpoints
The authorization server is https://api.arsel.sa. Its endpoints sit at the root, outside /v1. Clients can read them all from the discovery document.
| Endpoint | URL |
|---|---|
| Authorize | https://api.arsel.sa/oauth/authorize |
| Token | https://api.arsel.sa/oauth/token |
| Register | https://api.arsel.sa/oauth/register |
| Revoke | https://api.arsel.sa/oauth/revoke |
| Discovery | https://api.arsel.sa/.well-known/oauth-authorization-server |
Tokens you get here are used against the normal API at https://api.arsel.sa/v1.
1. Register your app
There is no client ID to request from us. Register your app one of two ways.
Client ID metadata document (recommended)
Host a small JSON document at an HTTPS URL you control. That URL is your client_id, so one identity covers every install of your app, and the consent screen shows your domain.
{
"client_id": "https://app.example.com/oauth/client.json",
"client_name": "Example App",
"redirect_uris": ["https://app.example.com/oauth/callback"]
}
| Field | Required | Description |
|---|---|---|
client_id | Yes | Must equal the document's own URL exactly. |
client_name | No | Shown on the consent screen. Defaults to the URL's host name. Max 255 characters. |
redirect_uris | Yes | Where Arsel may send the user back. See redirect URIs. |
token_endpoint_auth_method | No | If present, must be none. |
The URL must use https, have a path, and have no query string, port, fragment or credentials; its host can't be an IP address. Arsel fetches the document when a user starts signing in, so it must answer 200 with JSON within 3 seconds, be at most 5 KB, and not redirect. Arsel caches it for the max-age in its Cache-Control header (1 hour if there is none, 24 hours at most), so a change to your redirect URIs can take that long to apply.
What your users see
The consent screen shows the Arsel logo at the top, and its headline names your app in one of four ways:
| Your app | Headline | Line under it |
|---|---|---|
| Verified by Arsel | Your client_name | "Verified by Arsel · published by app.example.com" |
| Metadata document | Your domain | "Example App, published by app.example.com" |
| Self-registered, redirecting to a website | Your redirect URI's domain | "Calls itself Example App · not verified by Arsel" |
| Self-registered, redirecting to the user's device (loopback or app scheme) | Your client_name | "Runs on this device" |
To be marked verified, host a metadata document and email support@arsel.sa with its URL. Logos aren't shown yet.
Dynamic client registration
If you can't host a document, register once with POST /oauth/register and store the client_id it returns. Every call creates a new client, so register once per app, not once per user.
Redirect URIs
A redirect URI must be one of:
- an
httpsURL, matched exactly; - an
httploopback URL on127.0.0.1,[::1]orlocalhost, for desktop apps and CLIs. The port may differ from the registered one, so you can listen on any free port; - a private-use scheme for a native app, in reverse-DNS form, such as
com.example.app:/oauth/callback.
Fragments and credentials (user:pass@) are not allowed.
2. Send the user to Arsel
Generate a PKCE pair and a state value for each sign-in, keep them with the user's session, then send the user's browser to the authorize endpoint.
import {createHash, randomBytes} from 'node:crypto';
const codeVerifier = randomBytes(32).toString('base64url');
const codeChallenge = createHash('sha256').update(codeVerifier).digest('base64url');
const state = randomBytes(16).toString('base64url');
const url = new URL('https://api.arsel.sa/oauth/authorize');
url.search = new URLSearchParams({
response_type: 'code',
client_id: 'https://app.example.com/oauth/client.json',
redirect_uri: 'https://app.example.com/oauth/callback',
code_challenge: codeChallenge,
code_challenge_method: 'S256',
state,
}).toString();
// Redirect the browser to url.toString()
The parameters are documented on Authorize. Leave out resource: it exists for the MCP server.
3. The user approves
The user signs in to Arsel, or signs up and comes back, then chooses an organization and clicks Allow or Deny. Only organizations where they are an admin are offered. A user who signs up with an email and password must verify their email before they can approve; the consent screen asks them to and continues once they have. Signing up with Google needs no extra step. The sign-in request expires after 30 minutes.
4. Handle the callback
Arsel redirects to your redirect_uri:
https://app.example.com/oauth/callback?code=…&state=…&iss=https%3A%2F%2Fapi.arsel.sa
Check that state matches the value you stored and that iss is https://api.arsel.sa. If the user clicked Deny, or the request was invalid, you get error and error_description instead of code. See Authorize.
5. Exchange the code for tokens
Within 10 minutes, swap the code for tokens. A code works once.
Send the token endpoint form-encoded (application/x-www-form-urlencoded), as OAuth libraries do by default. JSON is accepted too.
curl -X POST https://api.arsel.sa/oauth/token \
-d grant_type=authorization_code \
-d code="$CODE" \
-d code_verifier="$CODE_VERIFIER" \
-d client_id=https://app.example.com/oauth/client.json \
-d redirect_uri=https://app.example.com/oauth/callback
{
"access_token": "eyJhbGciOiJFUzI1NiIs…",
"token_type": "Bearer",
"expires_in": 900,
"refresh_token": "arsel_rt_…",
"scope": "full_access"
}
Store the refresh token encrypted, keyed by the connection. Treat the access token as opaque: don't rely on what is inside it.
6. Call the API
Send the access token exactly where an API key would go:
curl https://api.arsel.sa/v1/contacts \
-H "Authorization: Bearer $ACCESS_TOKEN"
Every call is scoped to the organization the user picked, under that organization's rate limits. A token that has expired or whose connection has ended gets 401.
7. Refresh tokens
Access tokens last 15 minutes. Before one expires, or when a call returns 401, get a new pair:
curl -X POST https://api.arsel.sa/oauth/token \
-d grant_type=refresh_token \
-d refresh_token="$REFRESH_TOKEN" \
-d client_id=https://app.example.com/oauth/client.json
Every refresh returns a new refresh token, and the old one stops working. To avoid disconnecting your users:
- Save the new refresh token before you use the new access token, in the same write that retires the old one.
- Refresh one connection at a time. If two workers refresh the same connection at once, one of them is holding a used token.
- Never replay a used refresh token. Within 60 seconds of its replacement a replay is refused, which covers a retry after a network error. After that, a replay is treated as a stolen token and disconnects the app.
A refresh token expires after 60 days without use. Each refresh restarts the 60 days, so a connection that is used keeps working indefinitely.
8. Disconnect
When the user disconnects Arsel in your app, revoke the connection so it disappears from their Connected Apps list:
curl -X POST https://api.arsel.sa/oauth/revoke \
-d token="$REFRESH_TOKEN"
When a connection ends
A connection stops working, and refreshing it returns invalid_grant, when:
- an admin disconnects it under Integrations > Connected apps, or your app revokes it;
- the user who approved it is no longer an admin of the organization, or their account is deleted;
- that user changes or resets their Arsel password;
- the same user connects your app to the same organization again, which replaces the earlier connection;
- a used refresh token is replayed, or 60 days pass without a refresh.
When this happens, send the user through the flow again.
What a connection can do
A connection has full access to one organization: everything an API key for that organization can do, including sending. The only scope is full_access, which is also the default. Show your users what your app will do with their account before you send them to Arsel.
Desktop apps and CLIs
A desktop app or CLI can't keep a secret, and doesn't need to: PKCE protects the flow.
- Start an HTTP server on
127.0.0.1on a free port. - Register
http://127.0.0.1/callbackas a redirect URI. Any port is accepted at sign-in. - Open the authorize URL in the user's default browser rather than an embedded web view, so they see the real Arsel page.
- Receive the code on your local server, then exchange it as in step 5.
Limits
- No client secrets. Every client is a public client (
token_endpoint_auth_method: none) and is protected by PKCE. - Admins only. Members can't connect an organization.
- One organization per connection. To work with several organizations, connect each one.
- Rate limits.
POST /oauth/tokenandPOST /oauth/revokeeach allow 600 requests per minute, andPOST /oauth/register10, per IP address.