Set up your integration
- Create an External Integration in the dashboard.
- Register
http://127.0.0.1:3000/api/ofauth/callbackfor Sandbox. - Open your app at
127.0.0.1so its session cookie uses the same host as the callback. - Store the client ID, secret, and callback URL on your server.
Add start and callback routes
- Read the initiating user and browser session from trusted server authentication.
- Create an authorization URL with
OFAuthLink.createAuthorizationUrl, requesting only required scopes. - Persist its state and PKCE verifier with that user, session, expiry, and registration version before redirecting.
- On return, atomically consume matching state for the same user and session. A foreign callback must not consume a legitimate attempt.
- Validate the issuer, parse the callback, exchange the code, and save tokens only if the registration version still matches.
- Redirect to an explicit account picker.
access_denied as cancellation. Expired sessions, reused state, and mismatched callbacks require a new attempt. The resource SDK does not provide a second Next.js credential manager.
Choose an account and read its profile
List shared accounts withclient.linkedAccounts.iterate() and show connected accounts in a picker. Save the chosen ID in your app, keyed by the same client and user. Check that it is still shared before each use.
Create OFAuthClient with your auth system’s token getter and the selected linkedAccountId, then call client.access.profile.get(). See Choose an account for the code.
Do not choose the first account in a shared list. An authorization can include several creators.