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

> ## Agent Instructions
> Treat these docs and the Whop MCP server as the source of truth for Whop API behavior. Don't infer endpoint behavior from marketing pages.
> MCP server: connect https://mcp.whop.com/mcp (streamable HTTP, browser sign-in, no API key in the client config) to search these docs and read or change live Whop data. Setup: https://docs.whop.com/developer/guides/ai_and_mcp.md
> Whop CLI: install with `curl -fsSL https://whop.com/install.sh | sh` to scaffold, run, and deploy Whop apps and websites. It acts on production, not the sandbox. Overview: https://docs.whop.com/cli/overview.md Agent mode: https://docs.whop.com/cli/agent-mode.md
> Hosting: Whop serves a site or app from the build `whop apps deploy` uploads, with rollbacks, secrets, and server logs. Guide: https://docs.whop.com/developer/websites/hosting.md
> Plugins: in Claude Code, run `/plugin marketplace add whopio/plugins`, then `/plugin install whop@whop`. Guide: https://docs.whop.com/developer/guides/plugins/claude-code.md Every agent tool: https://docs.whop.com/developer/ai/overview.md
> Environments: build and test in the sandbox (API `https://sandbox-api.whop.com/api/v1`, keys at https://sandbox.whop.com/dashboard/developer, SDK environment `Sandbox`; no real money). Production (API `https://api.whop.com/api/v1`, keys at https://whop.com/dashboard/developer, SDK environment `Production`, the SDK default) moves real money, so use it only at launch. The two share no accounts, keys, products, or webhooks, and their keys look identical: never mix them. Sandbox guide: https://docs.whop.com/developer/guides/sandbox.md Comparison: https://docs.whop.com/developer/quickstart.md
> API: send `Authorization: Bearer <API_KEY>` from your server only, and pin a dated version with the `Api-Version-Date` header. OpenAPI spec: https://api.whop.com/api/v1/openapi.json
> Which API: build on the Current API, whose pages live under https://docs.whop.com/api-reference/ (start at https://docs.whop.com/api-reference/overview.md). Pages under /api-reference/legacy/ are the Legacy API. Use one only when https://docs.whop.com/api-reference/stability.md lists the resource as Legacy-only.

# Chatauthenticatie

> Authenticeer gebruikers voor ingesloten chat met tokens met accountscope of OAuth

> [card] [Soorten Whop-inloggegevens](https://docs.whop.com/nl/developer/guides/auth-scoping.md)
>
> Zie Authenticatie en API-sleutels voor alle vier de soorten Whop-inloggegevens, wanneer je welke gebruikt en hoe je de scope van een token beperkt tot de acties die het nodig heeft.

Voordat je de chat-SDK gebruikt, moet je gebruikers authenticeren. Kies een van de twee benaderingen:

| Benadering | Beste voor |
| - | - |
| **[Gebruikerstokens met accountscope](#account-scoped-user-tokens)** | Apps die al eigen gebruikers hebben. Je server maakt Whop-tokens voor hen aan zonder aanmeldstap. |
| **[OAuth](https://docs.whop.com/nl/developer/guides/chat/oauth.md)** | Apps waarbij gebruikers zich zelf bij Whop aanmelden via een aanmeldpagina of webview. |

## Gebruikerstokens met accountscope

Gebruik deze benadering als **je app al eigen gebruikers heeft** (via je eigen authenticatie- of sessiesysteem). Je behoudt je bestaande inlogflow en maakt een Whop-token aan voor de gebruiker die op dat moment is aangemeld — zonder extra aanmeldstap.

Je server wisselt je Whop API-sleutel op aanvraag in voor een kortlevend gebruikerstoken en retourneert dat aan de client. Jij bepaalt voor welke gebruiker het token is.

### Verzamel je inloggegevens

Je hebt drie dingen nodig:

1. **API-sleutel** — maak er een aan in het [Whop Developer Dashboard](https://whop.com/dashboard/developer). Behandel hem als een wachtwoord en bewaar hem alleen op je server.
2. **Account-ID**. Je vindt deze in de URL van je dashboard: `whop.com/dashboard/biz_XXXXXXXXX/`.
3. **Gebruikers-ID** — de gebruiker die je wilt authenticeren. Leid deze in productie af uit je eigen authenticatie- of sessiesysteem.

> [!NOTE]
>
> Voor ingesloten chat zijn `account_id` en `user_id` allebei verplicht bij het aanmaken van een token.

### Maak een token-endpoint op je server

Voeg een endpoint toe dat `POST https://api.whop.com/api/v1/access_tokens` aanroept met je API-sleutel en het resulterende token aan de client retourneert.

> [tab] Next.js
>
> ```typescript app/api/chat/token/route.ts theme={null}
> import { NextResponse } from "next/server";
> import { WhopClient } from "@whop/sdk";
>
> const client = new WhopClient({ token: process.env.WHOP_API_KEY });
>
> export async function POST() {
>   // Derive these from your own auth / session in production.
>   const user_id = "user_XXXXXXXXXXXX";
>   const account_id = "biz_XXXXXXXXXXXXX";
>
>   const { token } = await client.accessTokens.create({
>     account_id,
>     user_id,
>     scoped_actions: [
>       "chat:message:create",
>       "chat:read",
>       "dms:read",
>       "dms:message:manage",
>       "dms:channel:manage",
>       "support_chat:read",
>       "support_chat:message:create",
>     ],
>   });
>
>   return NextResponse.json({ token });
> }
> ```

> [tab] Express
>
> ```typescript server.ts theme={null}
> import express from "express";
> import { WhopClient } from "@whop/sdk";
>
> const app = express();
> app.use(express.json());
>
> const client = new WhopClient({ token: process.env.WHOP_API_KEY });
>
> app.post("/api/chat/token", async (_req, res) => {
>   // Derive these from your own auth / session in production.
>   const user_id = "user_XXXXXXXXXXXX";
>   const account_id = "biz_XXXXXXXXXXXXX";
>
>   const { token } = await client.accessTokens.create({
>     account_id,
>     user_id,
>     scoped_actions: [
>       "chat:message:create",
>       "chat:read",
>       "dms:read",
>       "dms:message:manage",
>       "dms:channel:manage",
>       "support_chat:read",
>       "support_chat:message:create",
>     ],
>   });
>
>   res.json({ token });
> });
>
> app.listen(3000);
> ```

> [tab] cURL
>
> ```bash theme={null}
> curl -X POST https://api.whop.com/api/v1/access_tokens \
>   -H "Authorization: Bearer $WHOP_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d '{
>     "account_id": "biz_XXXXXXXXXXXXX",
>     "user_id": "user_XXXXXXXXXXXX",
>     "scoped_actions": [
>       "chat:message:create",
>       "chat:read",
>       "dms:read",
>       "dms:message:manage",
>       "dms:channel:manage",
>       "support_chat:read",
>       "support_chat:message:create"
>     ]
>   }'
> ```

### Haal het token op vanuit je app

Geef de SDK een token-callback die het token ophaalt bij je endpoint. De chatelementen roepen deze aan wanneer ze moeten authenticeren, en automatisch opnieuw wanneer het token verloopt.

> [tab] React
>
> ```typescript theme={null}
> async function getToken() {
>   const response = await fetch("/api/chat/token", { method: "POST" });
>   const data = await response.json();
>   return data.token;
> }
> ```

> [tab] Vanilla JS
>
> ```typescript theme={null}
> async function getToken() {
>   const response = await fetch("/api/chat/token", { method: "POST" });
>   const data = await response.json();
>   return data.token;
> }
> ```

> [tab] Swift
>
> ```swift theme={null}
> import WhopElements
>
> class WhopAPITokenProvider: WhopTokenProvider {
>     private let serverURL = URL(string: "https://your-server.com")!
>
>     func getToken() async -> WhopTokenResponse {
>         do {
>             var req = URLRequest(url: serverURL.appendingPathComponent("api/chat/token"))
>             req.httpMethod = "POST"
>
>             let (data, _) = try await URLSession.shared.data(for: req)
>             let json = try JSONSerialization.jsonObject(with: data) as! [String: Any]
>             return WhopTokenResponse(accessToken: json["token"] as? String ?? "")
>         } catch {
>             return WhopTokenResponse(accessToken: "")
>         }
>     }
> }
> ```
>
> Geef de tokenprovider bij het starten van de app door aan de SDK:
>
> ```swift theme={null}
> .task {
>     await WhopSDK.configure(tokenProvider: WhopAPITokenProvider())
> }
> ```

### Vereiste scopes

Vraag deze scopes aan bij het aanmaken van het token:

| Scope | Doel |
| - | - |
| `chat:message:create`, `chat:read` | Kanalen |
| `dms:read`, `dms:message:manage`, `dms:channel:manage` | Directe berichten |
| `support_chat:read`, `support_chat:message:create` | Supportchats |

> [!NOTE]
>
> Als je app eigenaar is van de gebruikersaccounts en chattokens met accountscope aanmaakt, synchroniseer die gebruikers dan voordat je hun `user_id` hier meegeeft. Het synchroniseren van gebruikers maakt geen deel uit van OAuth.

> [card] [Synchroniseer je gebruikers](https://docs.whop.com/nl/developer/guides/chat/sync-users.md)
>
> Maak Whop-gebruikers aan of koppel ze voordat je chattokens met accountscope aanmaakt.

## OAuth

OAuth heeft een eigen pagina, zodat deze gids zich kan richten op gebruikerstokens met accountscope.

Gebruik OAuth wanneer je wilt dat gebruikers zich zelf bij Whop aanmelden via een aanmeldpagina of iOS-webview. Dit is de juiste keuze wanneer je app toegang nodig heeft tot een Whop-account dat eigendom is van een gebruiker, of wanneer je niet wilt dat je backend Whop-gebruikerstokens aanmaakt.

> [card] [OAuth](https://docs.whop.com/nl/developer/guides/chat/oauth.md)
>
> Stel OAuth-scopes, redirect-URI's, token-endpoints voor het web en door de SDK beheerde OAuth op iOS in.
