> ## 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.

# Chat-OAuth

> Authenticeer gebruikers van ingesloten chat met Whop OAuth en door de SDK beheerd aanmelden.

Met OAuth melden gebruikers zich zelf bij Whop aan via een aanmeldpagina of een iOS-webview. Je app ontvangt Whop-gebruikerstokens waarmee ingesloten chat kan worden geauthenticeerd en namens de aangemelde gebruiker kan worden gehandeld.

Gebruik OAuth wanneer je app toegang nodig heeft tot het Whop-account van de gebruiker, of wanneer je geen gebruikerstokens met accountscope vanuit je eigen backend wilt aanmaken.

> [card] [Volledige OAuth-gids](https://docs.whop.com/nl/developer/guides/oauth.md)
>
> Zie de algemene OAuth-gids voor de volledige OAuth 2.1- en PKCE-flow en details over het uitwisselen, vernieuwen en intrekken van tokens.

## Setup

> [!WARNING]
>
> Het `App`-object dat `apps.create` in de huidige `@whop/sdk` retourneert, bevat geen veld `client_secret`. Kopieer het client secret in plaats daarvan via het tabblad Dashboard.

> [tab] API
>
> Gebruik het endpoint [Create App](https://docs.whop.com/nl/api-reference/apps/create-app.md) om programmatisch een OAuth-app aan te maken:
>
> ```typescript theme={null}
> import { WhopClient } from "@whop/sdk";
>
> const client = new WhopClient({ token: process.env.WHOP_API_KEY });
>
> const app = await client.apps.create({
>   name: "My App",
>   redirect_uris: [
>     "http://localhost:3000/api/auth/callback/whop",
>     "https://myapp.com/api/auth/callback/whop"
>   ],
> });
>
> console.log(app.id);            // App ID
> console.log(app.client_secret); // Client Secret
> ```
>
> Werk redirect-URI's later bij met het endpoint [Update App](https://docs.whop.com/nl/api-reference/apps/update-app.md).

> [tab] Dashboard
>
> **1. Maak je app aan of selecteer hem**
>
> Registreer je app in het [Whop Dashboard](https://whop.com/dashboard/) > Developer om een app-ID te krijgen.
>
> **2. Voeg een redirect-URL toe**
>
> Open OAuth in de app die je hebt aangemaakt en voeg een redirect-URL toe.
>
> * Gebruik voor React- of vanilla JavaScript-apps de callback-URL van je app, zoals `https://yourapp.com/oauth/callback`.
> * Gebruik voor Swift-apps je bundle-ID, zoals `com.yourapp.bundle://oauth/callback`, of configureer een aangepaste redirect-URI.
>
> **3. Selecteer scopes**
>
> Kopieer op dezelfde pagina de vereiste scopes via **View available scopes**.

## Vereiste scopes

Je OAuth-configuratie moet deze scopes bevatten:

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

## Token-endpoint voor het web

Je server moet een token-endpoint aanbieden dat een geldig OAuth-token met de vereiste scopes retourneert. De chatelementen voor React en vanilla JavaScript roepen deze functie aan wanneer ze moeten authenticeren.

```typescript theme={null}
async function getToken() {
  const response = await fetch("/api/token");
  const data = await response.json();
  return data.token;
}
```

Zie de [OAuth-gids](https://docs.whop.com/nl/developer/guides/oauth.md) voor het implementeren van de server-side tokenuitwisseling.

## Door de SDK beheerde OAuth op iOS

Roep `configureWithOAuth` aan bij het starten van de app. De SDK handelt de hele flow af: een aanmeldwebview tonen, tokens ophalen en ze automatisch vernieuwen.

```swift theme={null}
.task {
    await WhopSDK.configureWithOAuth(
        appId: "app_XXXXXXXXXXXXXX",
        scopes: [
            "openid", "profile", "email",
            "chat:message:create", "chat:read",
            "dms:read", "dms:message:manage", "dms:channel:manage",
            "support_chat:read", "support_chat:message:create",
        ]
    )
}
```

Standaard gebruikt de SDK je bundle-identifier voor de redirect-URI (`com.yourapp.bundle://oauth/callback`). Je kunt dit aanpassen:

```swift theme={null}
await WhopSDK.configureWithOAuth(
    appId: "app_XXXXXXXXXXXXXX",
    redirectUri: "myapp://auth/callback",
    scopes: [
        "openid", "profile", "email",
        "chat:message:create", "chat:read",
        "dms:read", "dms:message:manage", "dms:channel:manage",
        "support_chat:read", "support_chat:message:create",
    ]
)
```

Zorg ervoor dat de redirect-URI overeenkomt met wat je hebt geconfigureerd in het [Whop Dashboard](https://whop.com/dashboard/) > Developer > App > OAuth.

Wanneer een gebruiker naar een chatweergave navigeert, start de SDK automatisch de OAuth-flow als de gebruiker nog niet is geauthenticeerd. Je kunt aan- en afmelden ook handmatig starten:

```swift theme={null}
// Sign in
try await WhopSDK.signIn()

// Sign out
WhopSDK.signOut()
```

### Authenticatiestatus bijhouden

Gebruik de modifier `.whopAuthState` om reactief bij te houden of de gebruiker is aangemeld:

```swift theme={null}
struct ChatView: View {
    @State private var isAuthenticated = false

    var body: some View {
        VStack {
            if isAuthenticated {
                Text("Signed In")
            } else {
                Text("Not Signed In")
            }
        }
        .whopAuthState($isAuthenticated)
    }
}
```

### Tokens vooraf invullen

Heb je de Whop-tokens van de gebruiker al uit een andere bron, dan kun je ze vooraf invullen om de aanmeldwebview bij de eerste start over te slaan. Bronnen zijn bijvoorbeeld een OAuth-flow op het web of tokens die vanuit je backend zijn gesynchroniseerd. Dit is optioneel en alleen relevant als je gebruikers zich al elders bij Whop hebben geauthenticeerd.

```swift theme={null}
let tokens = await myBackend.getWhopTokens(for: currentUser)

try await WhopSDK.preSignIn(
    accessToken: tokens.accessToken,
    refreshToken: tokens.refreshToken
)
```

De SDK haalt de vervaldatum van het token uit de JSON Web Token (JWT) en vernieuwt automatisch. Als de SDK verlopen, vooraf ingevulde tokens niet kan vernieuwen, start de normale OAuth-flow.

## Volgende stappen

> [card] [Authenticatie](https://docs.whop.com/nl/developer/guides/chat/authentication.md)
>
> Vergelijk OAuth met tokens met accountscope voor ingesloten chat.

> [card] [Algemene OAuth-gids](https://docs.whop.com/nl/developer/guides/oauth.md)
>
> Implementeer de volledige OAuth-flow en het uitwisselen, vernieuwen en intrekken van tokens.

> [card] [Chat-element](https://docs.whop.com/nl/developer/guides/chat/chat-element.md)
>
> Leer de props, events, stijlen en deeplinkopties voor de chat-UI kennen.

> [card] [Quickstart voor ingesloten chat](https://docs.whop.com/nl/developer/guides/chat/quickstart.md)
>
> Geef je eerste ingesloten chat weer.
