> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiveth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Tokens and claims

> What is inside the ID token, access token and refresh token, and how to add your own claims.

When a person signs in to your app, Aiveth's token endpoint returns an ID token and an access token, and a refresh token if you asked for one. This page explains each one, the claims they carry, and how to add claims of your own with a token template.

## The tokens at a glance

| Token | Format | Lifetime | Use it to |
| - | - | - | - |
| ID token | JWT, signed RS256 | 1 hour | Learn who signed in. Verify it offline. |
| Access token | Opaque string | 1 hour, and only while the sign-in stands | Call `/oauth/userinfo`. |
| Refresh token | Opaque string | Per app; 30 days unused or 90 days at most by default | Get new tokens without a new sign-in. |

The access token is not a JWT and cannot be decoded. It reads `/oauth/userinfo` and nothing else, so it can never be used against Aiveth's own APIs.

## ID token

Verify the ID token with the keys at the `jwks_uri` from the discovery document (`https://accounts.aiveth.com/v1/auth/.well-known/jwks.json`). Check:

* the signature (RS256),
* `iss` is `https://accounts.aiveth.com` (or your [custom domain](https://docs.aiveth.com/brand/custom-domains.md), when the person signed in there),
* `aud` is your client ID,
* `exp` is in the future,
* `nonce` matches the one you sent.

The Node SDK does all of this except the nonce check:

```ts theme={null}
const claims = await aiveth.tokens.verifyIdToken(idToken, { clientId: 'YOUR_CLIENT_ID' });
```

### Standard claims

| Claim | When | Meaning |
| - | - | - |
| `iss`, `aud`, `azp`, `iat`, `exp` | Always | Issuer, your client ID, issue and expiry times. |
| `sub` | Always | The person's ID. Stable; use it as your user ID. |
| `org_id` | Always | The organization's ID. |
| `auth_time` | Always | When the person last proved it's them. |
| `acr` | Browser sign-ins | `urn:aiveth:acr:2fa` if this session proved a second factor, else `urn:aiveth:acr:1fa`. |
| `nonce` | When you sent one | Your `nonce`. |
| `sid` | Always | A fingerprint of the Aiveth session. It matches the `sid` in [back-channel logout](https://docs.aiveth.com/apps/logout.md) notices. |
| `email`, `email_verified` | `email` scope | The person's email address. |
| `name`, `given_name`, `family_name` | `profile` scope | The person's name. |
| `picture` | `profile` scope, if they have a photo | The address of their photo. |
| `role`, `permissions` | `roles` scope | Their role's key, and that role's app permissions. Aiveth's own console powers are never included. |
| `groups` | `groups` scope | The names of their groups. |

### Claims Aiveth adds when they apply

| Claim | When | Meaning |
| - | - | - |
| `consent` | Your organization published a [consent notice](https://docs.aiveth.com/privacy/consent.md) | `{purpose: true/false}` for the current notice. |
| `age_group`, `parental_consent` | Your organization checks age ([children](https://docs.aiveth.com/privacy/children.md)) | `adult` or `child`; for a child, whether a parent agreed. |
| `feature_flags` | Your organization has feature flags (console: **Feature flags**) | The keys of the flags that are on for this person. |
| `act` | Someone is acting for the person | Who is really signed in. Your app decides what they may do. |

Claims from the token template, and from your sign-in check, are added too. See below.

## Access token and userinfo

Send the access token to `/oauth/userinfo` as `Authorization: Bearer <token>` (or `Authorization: DPoP <token>` for a [DPoP-bound](https://docs.aiveth.com/apps/dpop.md) token). The answer has `sub` and the same profile, role, group and template claims as the ID token, for the scopes the app asked for.

An access token stops working when:

* it reaches its 1-hour expiry,
* the person's Aiveth session ends (for a normal sign-in), or
* the sign-in is ended: the person disconnects the app, an admin signs them out everywhere, they are suspended, or the app revokes it.

```ts theme={null}
const user = await aiveth.tokens.userFromAccessToken(accessToken); // null once it has ended
```

If you call it often, keep the answer for a short time.

## Refresh tokens

Ask for the `offline_access` scope to get a refresh token. It keeps the person signed in to your app even after their Aiveth session ends.

```bash theme={null}
curl -X POST https://accounts.aiveth.com/oauth/token \
  -u "YOUR_CLIENT_ID:YOUR_CLIENT_SECRET" \
  -d grant_type=refresh_token \
  -d refresh_token=THE_REFRESH_TOKEN
```

* **Rotation.** Every use returns a new refresh token, and the old one stops. Store the new one each time.
* **Reuse detection.** If an old refresh token is presented again more than 30 seconds after it was swapped, Aiveth treats it as stolen and ends the whole sign-in. The person must sign in again. Within those 30 seconds it works once more, so a lost reply on a bad network doesn't sign anyone out.
* **Narrower scope.** You may pass `scope` to ask for less than the original grant, never more.
* **Lifetime.** By default a refresh token ends after 30 days unused or 90 days at most. You can change both for each app in its panel under **Staying signed in**: 1 to 90 days unused, and 1 to 365 days at most. A change applies to sign-ins already running.
* **Ends early** on a password change or reset, an admin's sign-out of everyone, a suspension or removal, the person disconnecting the app, the app being turned off, or the app revoking it.

A refresh also returns a fresh ID token, and your sign-in check (if any) runs again first.

## Ending a token

Your app can end its own refresh token or access token at `/oauth/revoke` (RFC 7009). The answer is always `200`, whether or not there was anything to end. Revoking a refresh token ends the whole sign-in, and Aiveth sends a [back-channel logout](https://docs.aiveth.com/apps/logout.md) notice if the app registered an address for one.

## Introspection

App access tokens are opaque, and Aiveth answers for them only at `/oauth/userinfo`. A `401` there means the token has ended.

The `/oauth/introspect` endpoint (RFC 7662) answers for **AI agent tokens** only. Your MCP server can use it to learn the moment an agent is stopped. See [Agent tokens](https://docs.aiveth.com/agents/agent-tokens.md).

Machine tokens are JWTs. Verify them offline; see [Machine-to-machine](https://docs.aiveth.com/apps/machine-to-machine.md).

## Add your own claims with a token template

A token template adds details from your organization and its people to every ID token and to the userinfo answer, whatever scope the app asked for. You have one template per organization.

> [!NOTE]
>
> The token template needs the Pro plan or above.

**1. Open Developers**

In the console, open **Developers** and find **What sign-in tokens include**.

**2. Write the template**

Under **Template (JSON)**, write a JSON object whose values use placeholders:

```json theme={null}
{
  "plan": "{{user.public.plan}}",
  "tier": "{{org.public.tier}}",
  "who": "{{user.email}}"
}
```

**3. Preview and save**

Select **Preview for me** to see what it would add for you, then **Save**. Your Owners are emailed about every change.

### Placeholders

You can use only details that may be shown:

* `user.id`, `user.email`, `user.first_name`, `user.last_name`, `user.public.*`
* `org.id`, `org.slug`, `org.name`, `org.public.*`

`user.public.*` and `org.public.*` read **public** [custom fields](https://docs.aiveth.com/access/custom-fields.md). Private fields, and fields a person fills in themselves, can never go in a token.

### How values render

* A value that is exactly one placeholder becomes that value as it is. A number stays a number.
* A placeholder inside other text becomes text.
* A placeholder that finds nothing drops its key.

### Limits

* The template, and what it renders to, may be at most 3 KB.
* Objects nest at most 3 levels deep.
* You can't use a name Aiveth sets itself, such as `sub`, `iss`, `aud`, `exp`, `email`, `name`, `org_id`, `role`, `roles`, `permissions`, `groups`, `scope`, `consent`, `feature_flags` or any other standard JWT or OpenID Connect claim. Aiveth's own claims always win.

### Claims from your sign-in check

If you set up a **Sign-in check** under **Developers**, your server can answer "allow" with extra details for the token. They follow the same rules as the template and go in that sign-in's ID token only.

## Related

* [Login with Aiveth](https://docs.aiveth.com/apps/login-with-aiveth.md)
* [OpenID Connect endpoints](https://docs.aiveth.com/api-reference/oidc-endpoints.md)
* [DPoP](https://docs.aiveth.com/apps/dpop.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.