# Rust SDK

Rust 1.88 or later. An async (`tokio`) client on `reqwest` with rustls.

## Install

```sh
cargo add ohauthcat
cargo add tokio --features macros,rt-multi-thread
```

## Configure

`Client::builder("sk_...").client_id("pk_...").build()?` creates the client (`use ohauthcat::Client;`). The client keeps no global state; timeouts are configurable on the builder.

## First call

Typed resources cover the core objects: `client.organizations().get("org_...").await?`, `client.organizations().list(&Default::default())` (an auto-paginating stream: `while let Some(org) = orgs.next().await`), and `client.directories().list_users("dir_...", None)`. Every other pinned operation is under `client.operations()`, for example `client.operations().events().list_events(CallOptions::default())`.

SSO: `client.sso().get_authorization_url(&AuthorizationOptions { redirect_uri, state, organization, ..Default::default() })?` returns the URL and a `code_verifier` to keep on your server; on the callback, `client.sso().get_profile_and_token(&ProfileAndTokenOptions { code, code_verifier, redirect_uri }).await` exchanges the code once.

## Errors

Every call returns `Result<T, ohauthcat::Error>`. `Error::Api` carries an `ApiError` with the stable `code`, `status`, `message`, `doc_url` and `request_id` (`error.code()` reads it); see the [error codes](/errors/). `Error::RestartSignIn` means the code exchange cannot be retried: start a fresh sign-in.

## Webhooks

`ohauthcat::webhooks::verify(raw_body, header, &["whsec_new", "whsec_old"], Default::default())?` checks the `OhAuthCat-Signature` header against the exact raw body bytes and returns the event (`event.event_type`). Pass both secrets during a rotation. A refusal is a `WebhookError`.

## Reference

Every method maps to an operation in the [API reference](/reference/api/); webhook payloads are in [webhook events](/reference/webhook-events/).
