Skip to main content
The SDK is a resource client. Your auth framework or application owns OAuth callbacks, token persistence, refresh, and revocation.

Install the release candidate

The next tag tracks the current prerelease.

Read a profile

A supplied token getter can obtain the current access token from your auth system:
currentAccessToken is your application function. If you use Better Auth, obtain it through Better Auth’s token API. Keep one token owner. Constructing the resource client performs no compulsory account preflight.

Choose an account

Create a discovery client with the same token getter and no account selector. Iterate every page, then save the user’s explicit account choice under your customer and client registration:
An account ID selects a resource. It does not grant permission or choose billing authority.

Store customer tokens

For an app without an auth framework, OFAuthLink provides standard URL, PKCE, callback parsing, exchange, refresh, and revocation helpers:
Persist attempt.state and attempt.codeVerifier with the current trusted application user, browser session, expiry, and registration version before redirecting to attempt.url. On return, verify and atomically consume the matching pending record. A foreign session must not consume it. Then parse and exchange:
Save tokens only if the registration version still matches. Calculate access expiry from expires_in. Refresh near expiry with link.refresh({ refreshToken }). The returned refresh token stays the same, so concurrent refresh and retry after a lost response require no distributed lock or attempt journal. Retain conditional writes when the user changes or disconnects a registration. The Express OAuth example shows PostgreSQL persistence, session-bound callbacks, account discovery and selection, targeted provider reconnect, and revocation. Its database stores ordinary application state, not an SDK-specific refresh protocol.

Handle failures

API failures throw OFAuthAPIError. Read code, recoveryAction, and requestId. Follow Handle failed requests. An invalid refresh grant requires authorization again. Transient refresh failures can be retried. A provider reconnect error needs targeted reconnect; OAuth refresh cannot repair it. Never repeat an interrupted message, post, or story automatically.