Skip to content
Dashboard
Theme
Theme

Rust SDK

The OhAuthCat server SDK for Rust: async client on tokio and rustls, SSO helpers and webhook verification.

View Markdown

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

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

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.

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.

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. Error::RestartSignIn means the code exchange cannot be retried: start a fresh sign-in.

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.

Every method maps to an operation in the API reference; webhook payloads are in webhook events.