# Authentication

> Sign in with an email code or a social provider, use and refresh tokens, sign out, and handle every auth error.

URL: https://renzo-digital.com/docs/authentication

The REST API has one credential: the **customer access token**. It is a JWT that you send as a bearer token. You get it by signing in. Renzo does not issue API keys.

```bash tab="curl"
curl "$BASE/api/v1/users/me" -H "Authorization: Bearer $TOKEN"
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
TOKEN = os.environ["TOKEN"]

answer = requests.get(
    f"{BASE}/api/v1/users/me",
    headers={"Authorization": f"Bearer {TOKEN}"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;

const answer = await fetch(`${BASE}/api/v1/users/me`, {
  headers: { Authorization: `Bearer ${TOKEN}` },
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

Calls marked "Token" in these docs need it. Public reads work without it. A few public reads take it when you have one. For example, `GET /api/v1/articles/{slug}` returns more of a gated article.

## Ways to sign in

| Method | Who can use it | Endpoints |
| --- | --- | --- |
| Email code (OTP) | Everyone. This is the method for API clients. | `POST /api/v1/auth/otp/request`<br />`POST /api/v1/auth/otp/verify` |
| Social sign-in | Readers on the Renzo website and apps. | `/api/v1/auth/social/...` |
| Password | Only review accounts that Renzo gives to app-store and directory reviewers. | `POST /api/v1/auth/password/login` |

All three return the same answer: a token pair, the profile, and `created`.

## Email code (OTP)

**1. Request a code.**

```bash tab="curl"
curl -X POST "$BASE/api/v1/auth/otp/request" \
  -H "Content-Type: application/json" \
  -d '{"email": "you@example.com"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]

answer = requests.post(
    f"{BASE}/api/v1/auth/otp/request",
    json={"email": "you@example.com"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE } = process.env;

const answer = await fetch(`${BASE}/api/v1/auth/otp/request`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ email: "you@example.com" }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

The answer is `202`:

```json title="Response"
{
  "challenge_token": "ch_7Hq2mXz9Kp4TnV1b",
  "expires_at": "2026-11-04T13:45:00Z",
  "code_expires_at": "2026-11-04T13:40:00Z",
  "attempts_remaining": 5
}
```

- The answer is the same whether or not the address has an account. This stops anyone from learning who has one.
- The email holds a six-digit code and a link. The link signs in on the Renzo website. API clients use the code.
- The code works for 10 minutes (`code_expires_at`). The challenge works for 15 minutes (`expires_at`).
- Each request opens an independent challenge with its own code and attempt budget. Other live challenges remain usable until consumed or expired. Use the code from the email matching your sign-in request.
- One email address gets at most one code a minute and 5 an hour. Requests are also limited per IP address: 10 in 15 minutes, shared with email-change codes. Over a limit, the answer is `429` [`rate_limited`](https://renzo-digital.com/docs/error-codes#rate_limited) with `Retry-After`. See [Rate limits](https://renzo-digital.com/docs/concepts/rate-limits).

**2. Verify the code.**

```bash tab="curl"
curl -X POST "$BASE/api/v1/auth/otp/verify" \
  -H "Content-Type: application/json" \
  -d '{"challenge_token": "ch_7Hq2mXz9Kp4TnV1b", "code": "482913", "timezone": "Europe/London"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]

answer = requests.post(
    f"{BASE}/api/v1/auth/otp/verify",
    json={
        "challenge_token": "ch_7Hq2mXz9Kp4TnV1b",
        "code": "482913",
        "timezone": "Europe/London",
    },
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE } = process.env;

const answer = await fetch(`${BASE}/api/v1/auth/otp/verify`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    challenge_token: "ch_7Hq2mXz9Kp4TnV1b",
    code: "482913",
    timezone: "Europe/London",
  }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

Optional fields: `timezone` (an IANA name, saved on a new account), `referral_code` and `referral_source` (see [Referrals](https://renzo-digital.com/docs/resources/referrals)).

The answer is `200`:

```json title="Response"
{
  "tokens": {
    "access_token": "eyJhbGciOiJIUzI1NiIs...example",
    "refresh_token": "eyJhbGciOiJIUzI1NiIs...refresh-example",
    "token_type": "Bearer",
    "expires_in": 900,
    "expires_at": "2026-11-04T13:45:00Z",
    "refresh_expires_at": "2026-12-04T13:30:00Z"
  },
  "profile": {
    "id": "eca8506d-1dfa-56a2-8765-96305e99f89c",
    "email": "you@example.com",
    "username": "marketwatcher",
    "status": "active",
    "country": "GB",
    "ui_language": "en",
    "article_language": "en",
    "timezone": "Europe/London",
    "currency": "USD",
    "mobile": null,
    "created_at": "2026-10-01T09:12:00Z",
    "last_login_at": "2026-11-04T13:30:00Z"
  },
  "created": false
}
```

- The first sign-in creates the account. `created` is `true` and `profile.status` is `pending_profile`. Set a username with `PATCH /api/v1/users/me` to make it `active`. Until then, most writes answer `409` [`profile_incomplete`](https://renzo-digital.com/docs/error-codes#profile_incomplete).
- A new account with a disposable email address is refused: `422` [`email_domain_not_allowed`](https://renzo-digital.com/docs/error-codes#email_domain_not_allowed).
- Asking for another code does not invalidate an existing challenge or spend its verification attempts. Each request receives its own code and challenge token.
- Each wrong code lowers `attempts_remaining`. After 5 wrong codes the challenge is dead: [`otp_too_many_attempts`](https://renzo-digital.com/docs/error-codes#otp_too_many_attempts).
- Signing in to an account that is waiting for deletion cancels the deletion.

## Password sign-in (review accounts only)

`POST /api/v1/auth/password/login` takes `{"email": "...", "password": "..."}`. It works only for review accounts that Renzo makes for app-store and directory reviewers. Every other address answers `401` [`invalid_credentials`](https://renzo-digital.com/docs/error-codes#invalid_credentials), even with a right password. It allows 20 tries per IP address and 5 per email address in 15 minutes.

## Social sign-in

Readers can sign in with Google, Apple, Facebook, X or GitHub. `GET /api/v1/auth/social/providers` lists the providers that are switched on:

```json
{ "providers": ["google", "apple", "github"] }
```

The provider sends the browser back to the Renzo website, not to your app. So this flow serves Renzo's own website and apps. A third-party integration should use the email code.

The flow:

1. `POST /api/v1/auth/social/{provider}/start` with `{"intent": "login"}` returns an `authorization_url`. Send the browser there. The attempt lives 10 minutes and works once.
2. The provider returns the browser with `code` and `state`. The Renzo website posts both to `POST /api/v1/auth/social/{provider}/callback`.
3. The callback answers `200` with a `status`:

| `status` | Meaning | Next step |
| --- | --- | --- |
| `signed_in` | Done. The body holds `tokens`, `profile` and `created`. | None. |
| `verify_email` | A six-digit code went to the provider's email address. The body holds `challenge_token` and `masked_email`. | `POST /api/v1/auth/social/verify` with `challenge_token` and `code`. |
| `email_required` | The provider gave no email address. The body holds `pending_token`. | `POST /api/v1/auth/social/email` with `pending_token` and `email`. A code goes there; then verify as above. |
| `linked` | A link finished (see below). The body holds `identity`. | None. |

Renzo signs in without a code only when it trusts the provider's address: a Google `gmail.com` or `googlemail.com` address, or an Apple address that is not a private relay address. Every other address gets `verify_email` first. `POST /api/v1/auth/social/verify` links the provider to the account on that address, or creates an account.

### Linking a provider to an account

A signed-in customer can add a provider as a second way to sign in:

1. `POST /api/v1/auth/social/{provider}/start` with `{"intent": "link"}` and the customer's token.
2. The callback must carry the same customer's token. Then it answers `status: "linked"`. Renzo emails the account a notice.

A provider account belongs to at most one Renzo account and never moves. Linking one that is on another account answers `409` [`identity_in_use`](https://renzo-digital.com/docs/error-codes#identity_in_use). Linking a second account of the same provider answers `409` [`identity_already_linked`](https://renzo-digital.com/docs/error-codes#identity_already_linked).

`GET /api/v1/users/me/identities` lists the linked providers. `DELETE /api/v1/users/me/identities/{provider}` removes one and answers `204`. It is always allowed, because the email code still works. See [Account](https://renzo-digital.com/docs/resources/account).

## The token pair

| Field | Meaning |
| --- | --- |
| `access_token` | Send as `Authorization: Bearer <access_token>`. |
| `token_type` | Always `Bearer`. |
| `expires_in` | Seconds until the access token ends. Today 900 (15 minutes). |
| `expires_at` | When the access token ends, in UTC. |
| `refresh_token` | Swap it for a new pair before the session ends. |
| `refresh_expires_at` | When the refresh token ends. Today 30 days after it was issued. |

> **Warning:** Treat both tokens as secrets. Answers that carry tokens are sent with `Cache-Control: no-store`. The lifetimes may change, so read `expires_in` and `refresh_expires_at` rather than hard-coding them.

## Refresh the token pair

When the access token ends, calls answer `401` [`token_expired`](https://renzo-digital.com/docs/error-codes#token_expired). Swap the refresh token for a new pair. No access token is needed:

```bash tab="curl"
curl -X POST "$BASE/api/v1/auth/refresh" \
  -H "Content-Type: application/json" \
  -d '{"refresh_token": "eyJhbGciOiJIUzI1NiIs...refresh-example"}'
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]

answer = requests.post(
    f"{BASE}/api/v1/auth/refresh",
    json={"refresh_token": "eyJhbGciOiJIUzI1NiIs...refresh-example"},
)
answer.raise_for_status()
print(answer.json())
```

```js tab="Node.js"
const { BASE } = process.env;

const answer = await fetch(`${BASE}/api/v1/auth/refresh`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ refresh_token: "eyJhbGciOiJIUzI1NiIs...refresh-example" }),
});
if (!answer.ok) throw new Error(`HTTP ${answer.status}`);
console.log(await answer.json());
```

```json title="Response"
{
  "access_token": "eyJhbGciOiJIUzI1NiIs...example",
  "refresh_token": "eyJhbGciOiJIUzI1NiIs...refresh-example-2",
  "token_type": "Bearer",
  "expires_in": 900,
  "expires_at": "2026-11-04T14:00:00Z",
  "refresh_expires_at": "2026-12-04T13:45:00Z"
}
```

- **A refresh token works once.** Store the new pair every time. Sending a used refresh token again ends the whole session: [`session_revoked`](https://renzo-digital.com/docs/error-codes#session_revoked). This guards against a stolen token. Run one refresh at a time, so two parallel calls do not spend the same token.
- **The session slides.** Each refresh gives a refresh token with a fresh 30-day life. A session ends after 30 days without a refresh.
- A failed refresh means the user must sign in again.

## Sign out

```bash tab="curl"
# This session only
curl -X POST "$BASE/api/v1/auth/logout" -H "Authorization: Bearer $TOKEN"

# Every session of the account
curl -X POST "$BASE/api/v1/auth/logout-all" -H "Authorization: Bearer $TOKEN"
```

```python tab="Python"
import os

import requests

BASE = os.environ["BASE"]
headers = {"Authorization": f"Bearer {os.environ['TOKEN']}"}

# This session only
requests.post(f"{BASE}/api/v1/auth/logout", headers=headers).raise_for_status()

# Every session of the account
requests.post(f"{BASE}/api/v1/auth/logout-all", headers=headers).raise_for_status()
```

```js tab="Node.js"
const { BASE, TOKEN } = process.env;
const headers = { Authorization: `Bearer ${TOKEN}` };

// This session only
await fetch(`${BASE}/api/v1/auth/logout`, { method: "POST", headers });

// Every session of the account
await fetch(`${BASE}/api/v1/auth/logout-all`, { method: "POST", headers });
```

Both answer `204`. The access token stops working at once, and the session's refresh token dies.

## Auth errors

Every auth failure is a `problem+json` body with a stable `code`. See [Errors](https://renzo-digital.com/docs/concepts/errors).

| Code | Status | When | What to do |
| --- | --- | --- | --- |
| [`missing_credentials`](https://renzo-digital.com/docs/error-codes#missing_credentials) | 401 | No `Authorization` header on a call that needs one. | Send the access token. |
| [`invalid_token`](https://renzo-digital.com/docs/error-codes#invalid_token) | 401 | The token is malformed, wrongly signed or already used. | Sign in again. |
| [`token_expired`](https://renzo-digital.com/docs/error-codes#token_expired) | 401 | The access or refresh token has ended. | Refresh; if the refresh token ended, sign in again. |
| [`session_revoked`](https://renzo-digital.com/docs/error-codes#session_revoked) | 401 | The session ended: sign-out, a reused refresh token, or account deletion. | Sign in again. |
| [`wrong_token_audience`](https://renzo-digital.com/docs/error-codes#wrong_token_audience) | 401 | A token of another kind, such as an MCP token, was sent to the REST API. | Use a customer access token. |
| [`invalid_credentials`](https://renzo-digital.com/docs/error-codes#invalid_credentials) | 401 | Password sign-in failed, or the account is not a review account. | Use the email code. |
| [`otp_code_incorrect`](https://renzo-digital.com/docs/error-codes#otp_code_incorrect) | 401 | The code is wrong. | Try again while `attempts_remaining` is above 0. |
| [`otp_code_expired`](https://renzo-digital.com/docs/error-codes#otp_code_expired) | 401 | The code is older than 10 minutes. | Request a new code. |
| [`otp_challenge_expired`](https://renzo-digital.com/docs/error-codes#otp_challenge_expired) | 401 | The challenge is older than 15 minutes. | Request a new code. |
| [`otp_challenge_invalid`](https://renzo-digital.com/docs/error-codes#otp_challenge_invalid) | 401 | The `challenge_token` is unknown or already used. | Request a new code. |
| [`otp_too_many_attempts`](https://renzo-digital.com/docs/error-codes#otp_too_many_attempts) | 401 | 5 wrong codes on this challenge. | Request a new code. |
| [`invalid_state`](https://renzo-digital.com/docs/error-codes#invalid_state) | 401 | The social sign-in attempt expired or was used, or a link callback came without the same token. | Start again. |
| [`social_login_failed`](https://renzo-digital.com/docs/error-codes#social_login_failed) | 401 | The provider refused the `code`. | Start again. |
| [`social_pending_invalid`](https://renzo-digital.com/docs/error-codes#social_pending_invalid) | 401 | The `pending_token` expired or is unknown. | Start again. |
| [`provider_not_enabled`](https://renzo-digital.com/docs/error-codes#provider_not_enabled) | 404 | The provider is switched off. | Use a provider from the list. |
| [`identity_in_use`](https://renzo-digital.com/docs/error-codes#identity_in_use) | 409 | The provider account is on another Renzo account. | Sign in to that account instead. |
| [`identity_already_linked`](https://renzo-digital.com/docs/error-codes#identity_already_linked) | 409 | The account already has an account of this provider. | Unlink the old one first. |
| [`customer_account_deactivated`](https://renzo-digital.com/docs/error-codes#customer_account_deactivated) | 403 | Staff deactivated the account. | Contact support. |
| [`customer_account_deleted`](https://renzo-digital.com/docs/error-codes#customer_account_deleted) | 403 | The account was deleted. | Sign up again. |
| [`email_domain_not_allowed`](https://renzo-digital.com/docs/error-codes#email_domain_not_allowed) | 422 | A new account with a disposable address. | Use a lasting address. |
| [`rate_limited`](https://renzo-digital.com/docs/error-codes#rate_limited) | 429 | Too many sign-in calls from this IP address. | Wait `Retry-After` seconds. |
| [`auth_temporarily_unavailable`](https://renzo-digital.com/docs/error-codes#auth_temporarily_unavailable) | 503 | The sign-in limiter is down, so sign-in is paused. | Retry after `Retry-After` seconds. |
| [`dependency_unavailable`](https://renzo-digital.com/docs/error-codes#dependency_unavailable) | 503 | The email or social provider did not answer. | Retry after `Retry-After` seconds. |

## Next steps

- [Quickstart](https://renzo-digital.com/docs/quickstart): the whole flow in curl, Python and JavaScript.
- [MCP](https://renzo-digital.com/docs/mcp): how AI apps get their own, separate tokens.
- [Rate limits](https://renzo-digital.com/docs/concepts/rate-limits): the limits on every sign-in call.
