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

# Token Verification

> Install @agentonboard/sdk or agentonboard-sdk, verify Agent Identity Tokens locally, and normalize domains.

## 1. Install the SDK

> [tab] npm
>
> ```bash theme={null}
> npm install @agentonboard/sdk
> ```

> [tab] pnpm
>
> ```bash theme={null}
> pnpm add @agentonboard/sdk
> ```

> [tab] yarn
>
> ```bash theme={null}
> yarn add @agentonboard/sdk
> ```

> [tab] bun
>
> ```bash theme={null}
> bun add @agentonboard/sdk
> ```

> [tab] Python (pip)
>
> ```bash theme={null}
> pip install "agentonboard-sdk[fastapi]"
> # Also available: agentonboard-sdk[django] and agentonboard-sdk[flask]
> ```

> [tab] Python (uv)
>
> ```bash theme={null}
> uv add "agentonboard-sdk[fastapi]"
> ```

`@agentonboard/sdk` has one runtime dependency (`jose`) and uses no Node.js builtins, so it runs on Node.js, Bun, Deno, and Cloudflare Workers. Source lives at [github.com/agentonboard/js-sdk](https://github.com/agentonboard/js-sdk).

TypeScript entry points:

| Import path | Exports |
| - | - |
| `@agentonboard/sdk` | `verifyAgentToken`, `verifyAgentAccount`, `createAgentAccount`, `normalizeEmail`, `VERIFY_ERROR_DESCRIPTIONS`, and TypeScript types |
| `@agentonboard/sdk/next` | `requireAgentAccount` for Next.js App Router `Request` |
| `@agentonboard/sdk/express` | `requireAgentAccount` for Express `(req, res)` |
| `@agentonboard/sdk/hono` | `requireAgentAccount` for Hono `Context` |

***

## 2. Verify a token directly

`verifyAgentToken` (and `verify_agent_token` in Python) checks the `RS256` signature against public JWKS keys, validates required claims, and returns either the verified email or an error code:

```ts title="src/auth/agent.ts" theme={null}
import { verifyAgentToken } from "@agentonboard/sdk";

const AUDIENCE = "notes.com";

export async function verifyAgentRequest(request: Request) {
  // Pass the Authorization header as-is; the SDK strips a leading `Bearer ` prefix.
  const result = await verifyAgentToken({
    token: request.headers.get("Authorization") ?? "",
    audience: AUDIENCE,
  });

  if (!result.ok) {
    return { ok: false as const, code: result.code, error: result.error };
  }

  return { ok: true as const, email: result.email };
}
```

For production routes, use `requireAgentAccount` or `verifyAgentAccount` so the verified email maps to your internal user ID and unknown users receive `403 ACCOUNT_REQUIRED`. See [Accounts & Agent Signup](https://docs.agentonboard.xyz/accounts.md).

***

## Token anatomy

When an agent calls `get_token(domain: "notes.com")` or `POST /api/v1/token/exchange`, AgentOnboard signs a 5-minute `RS256` JWT:

```json Decoded JWT Header theme={null}
{
  "alg": "RS256",
  "typ": "JWT",
  "kid": "aon_2026_v1"
}
```

```json Decoded JWT Payload theme={null}
{
  "email": "ada@example.com",
  "sub": "ada@example.com",
  "aud": "notes.com",
  "iss": "https://agentonboard.xyz",
  "iat": 1740000000,
  "exp": 1740000300,
  "jti": "f47ac10b-58cc-4372-a567-0e02b2c3d479"
}
```

| Claim / Header | Type | Description |
| - | - | - |
| `alg` | `"RS256"` | RSA-SHA256 signature algorithm. Pinned by the SDK (`alg: none` and `HS256` are rejected). |
| `kid` | `string` | Key ID matching an RSA public key (2048 bits minimum) in `https://agentonboard.xyz/.well-known/jwks.json`. |
| `email` | `string` | Verified email address of the User who owns the API Key. |
| `sub` | `string` | Subject identifier, set to the same verified email address. |
| `aud` | `string` | Target Domain hostname (normalized lowercase, such as `notes.com`). |
| `iss` | `string` | Token issuer URL (`https://agentonboard.xyz` in production). |
| `iat` | `number` | Issued-at Unix timestamp in seconds. |
| `exp` | `number` | Expiration Unix timestamp in seconds (`iat + 300`, 5 minutes). |
| `jti` | `string` | Unique UUID v4 token ID for audit logs. |

***

## What `verifyAgentToken` checks

| Check | Rule | Configurable? |
| - | - | - |
| Algorithm | `RS256` only. The token header never selects the algorithm; `alg: none` and `HS256` return `INVALID_SIGNATURE`. | Fixed |
| Signature | Verified against a public RSA key (2048 bits or larger) from the JWKS. | Fixed |
| `exp` | Must be in the future, with a default clock-skew tolerance of **5 seconds**. | `clockToleranceSeconds` |
| `aud` | Must match your normalized `audience` string by exact equality. | Fixed |
| `iss` | Must equal the configured `issuer` URL. | `issuer` / `AON_ISSUER` |
| Required claims | `exp`, `jti`, `sub`, and `email` must all be present and non-empty. | Fixed |
| Key selection | Header must carry a `kid` matching a key in the JWKS. Missing or unmatched `kid` returns `UNKNOWN_KEY`. | Fixed |

The SDK does not store seen `jti` values, so a valid token presented twice within its 5-minute window verifies both times. Serve endpoints over HTTPS and never log raw tokens.

***

## Options

```ts theme={null}
interface VerifyAgentTokenOptions {
  token: string;                  // required
  audience: string;               // required
  issuer?: string;
  jwksUrl?: string;
  jwks?: JSONWebKeySet;
  fetchJwks?: (url: string) => Promise<unknown>;
  clockToleranceSeconds?: number;
}
```

**token** `string` *required*

Raw JWT string. A leading `Bearer ` prefix is stripped case-insensitively. Empty strings return `MALFORMED_TOKEN`.

**audience** `string` *required*

Your Domain hostname (for example `"notes.com"`). Normalized before comparison against the token's `aud` claim.

**issuer** `string` (default: AON\_ISSUER, else "[https://agentonboard.xyz](https://agentonboard.xyz)")

Expected `iss` claim and base URL for the default JWKS endpoint (`${issuer}/.well-known/jwks.json`).

**jwksUrl** `string` (default: `$\{issuer\}/.well-known/jwks.json`)

Custom URL to fetch the JSON Web Key Set from. Ignored when `jwks` is provided.

**jwks** `JSONWebKeySet`

Pre-parsed JSON Web Key Set object for offline verification, air-gapped environments, or unit tests. Shape-checked before use; invalid key sets return `KEY_SOURCE_UNAVAILABLE`.

**fetchJwks** `(url: string) =\> Promise\<unknown\>`

Custom function to fetch the JWKS instead of global `fetch`. Must resolve to a parsed JSON object (not a `Response`). Ignored if `jwks` is set.

**clockToleranceSeconds** `number` (default: 5)

Seconds of clock skew tolerated when checking `exp`. Must be non-negative; negative or `NaN` values return `CONFIG_ERROR`.

> [!WARNING]
>
> **Option name is `clockToleranceSeconds`**
>
> In plain JavaScript without TypeScript checking, misspelled options such as `clockSkewSeconds` are ignored and default to 5 seconds.

### `AON_ISSUER` environment variable

`AON_ISSUER` is the only environment variable the SDK reads. Set `AON_ISSUER` or pass `issuer` explicitly when verifying tokens from a staging or self-hosted issuer; otherwise tokens fail with `ISSUER_MISMATCH`.

### Custom `fetchJwks` logging

If your custom `fetchJwks` callback throws, the SDK returns `{ ok: false, code: "KEY_SOURCE_UNAVAILABLE", error: "..." }` with a generic message so internal URLs or proxy credentials never leak into HTTP responses. Log errors inside `fetchJwks` before rethrowing:

```ts theme={null}
const result = await verifyAgentToken({
  token,
  audience: "notes.com",
  fetchJwks: async (url) => {
    try {
      const res = await fetch(url, { signal: AbortSignal.timeout(2000) });
      if (!res.ok) throw new Error(`JWKS endpoint responded ${res.status}`);
      return await res.json();
    } catch (err) {
      logger.error({ err, url }, "JWKS retrieval failed");
      throw err;
    }
  },
});
```

***

## Domain normalization

The SDK normalizes your `audience` option to a bare lowercase hostname by stripping any scheme, path, userinfo, and port (except `localhost` and `127.0.0.1`, which keep their port):

| Input `audience` | Normalized value |
| - | - |
| `notes.com` | `notes.com` |
| `https://api.notes.com/v1/` | `api.notes.com` |
| `http://notes.com:8080/data` | `notes.com` |
| `MYSERVICE.XYZ/path` | `myservice.xyz` |
| `https://user:pw@notes.com:8443/x` | `notes.com` |
| `localhost:3000` | `localhost:3000` |
| `notes.com.evil.com` | `notes.com.evil.com` |

After normalization, the SDK compares the token's `aud` claim by **exact string equality**. Suffix spoofing (`notes.com.evil.com` vs `notes.com`) fails with `AUDIENCE_MISMATCH`.

The same normalization runs when an agent mints a token via `get_token` or `POST /api/v1/token/exchange`. Write the bare hostname your API serves on. If your API runs on `api.notes.com`, use `api.notes.com` in both your backend code and your `auth.md`.

Passing an `audience` that cannot normalize to a hostname (such as `""` or `"/"`) returns `CONFIG_ERROR`.

***

## Return value and non-throwing contract

`verifyAgentToken` returns a discriminated union on `ok` and never throws for verification failures:

```ts theme={null}
type VerifyAgentTokenResult =
  | { ok: true;  email: string; sub: string; userId?: string; expiresAt: number; jti: string; audience: string }
  | { ok: false; code: VerifyErrorCode; error: string };
```

| Field | Description |
| - | - |
| `email` | The `email` claim verbatim from the token. Always pass through `normalizeEmail(email)` when querying your database. |
| `sub` | The `sub` claim (set to the verified email). |
| `userId` | Deprecated alias for `sub`. Use `email` or `sub`. |
| `expiresAt` | Expiration time in Unix epoch seconds. |
| `jti` | Unique token UUID for audit logging. |
| `audience` | Normalized Domain hostname verified against. |

***

## Next steps

> [card] [Accounts & Agent Signup](https://docs.agentonboard.xyz/accounts.md)
>
> Map verified emails to App Accounts or enable explicit agent signup.

> [card] [Errors & Status Codes](https://docs.agentonboard.xyz/errors.md)
>
> All 9 verification codes, 2 account codes, and HTTP status mappings.


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