KvStateStore
@atiproto/kv-oauth-state-store
Implements the StateStore interface from @atproto/oauth-client using a Cloudflare KV namespace. Stores transient OAuth state between the authorization request and the callback, including the DPoP key in JWK format.
Constructor
typescript
new KvStateStore(kv: KVNamespace, options?: KvStateStoreOptions)
| Parameter | Type | Description |
|---|---|---|
| kv | KVNamespace | The Cloudflare KV namespace binding. Bind this in wrangler.jsonc as OAUTH_STATE_KV. |
| options | KvStateStoreOptions | See options table below. |
Options
| Option | Type | Default | Description |
|---|---|---|---|
| prefix | string | "oauth_state:" | Key prefix for all KV entries. Change this if you share a KV namespace with other data. |
| ttlSeconds | number | 600 | Time-to-live in seconds for each state entry. State is only needed during the login flow, so the default 10-minute TTL is sufficient for most cases. |
Example
typescript
import { KvStateStore } from "@atiproto/kv-oauth-state-store";new KvStateStore(env.OAUTH_STATE_KV, {prefix: "oauth_state:", // defaultttlSeconds: 600, // default: 10 minutes});