# Go SDK

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

## Install

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

## Configure

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

## First call

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](/sso/working-with-existing-auth/) for a Go example.

## Errors

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

## Webhooks

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

## Reference

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