Skip to content
Dashboard
Theme
Theme

Go SDK

The OhAuthCat server SDK for Go 1.26: management API, SSO helpers and webhook verification, standard library only.

View Markdown

Go 1.26 or later. Its runtime imports only the standard library. Import it as ohauthcat "ohauthcat.com/sdk-go".

go get ohauthcat.com/sdk-go@v0.0.2

ohauthcat.NewClient(ohauthcat.ClientConfig{APIKey: "sk_..."}) returns the client and an error; defer client.Close(). For sign-in also set ClientID (pk_...) and EnvironmentID (env_...). Optional: Timeout, MaxRetries, and APIBaseURL / AuthBaseURL for any deployment other than production.

Generated methods sit on each resource and take a context and an arguments value: client.Organizations.GetOrganization(ctx, ohauthcat.GetOrganizationArgs{Path: ohauthcat.GetOrganizationPath{Org: "org_..."}}). Every list operation also has an iterator whose name ends in All, for example for org, err := range client.Organizations.ListOrganizationsAll(ctx, ohauthcat.ListOrganizationsArgs{}); client.Events.List is the same for events.

SSO: client.SSO.GetAuthorizationURL, GetProfileAndToken and VerifyAccessToken. See working with existing auth for a Go example.

API errors are *ohauthcat.APIError with Code, Status, Type, Param, DocURL and RequestID; check them with errors.As. See the error codes. *ohauthcat.RestartSignIn means the code exchange cannot be retried: start a fresh sign-in. Error strings never contain response messages, URLs or credentials.

ohauthcat.VerifyWebhook(body, r.Header.Get("OhAuthCat-Signature"), secrets, ohauthcat.VerifyOptions{}) checks the exact raw body bytes and returns the event. Pass every secret you hold during a rotation. A refusal is a *ohauthcat.WebhookVerificationError with a Code. The default freshness tolerance is 300 seconds.

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