# OFAuth
This project uses OFAuth V3 (https://docs.ofauth.com/v3) to connect OnlyFans accounts.
OFAuth is independent of OnlyFans. Never imply an affiliation in code, UI, or docs.
## Environments
| Environment | Client ID env var | Secret env var | Redirect URI |
| --- | --- | --- | --- |
| Sandbox | OFAUTH_SANDBOX_CLIENT_ID | OFAUTH_SANDBOX_CLIENT_SECRET | http://127.0.0.1:3000/oauth/ofauth/callback |
| Test | OFAUTH_TEST_CLIENT_ID | OFAUTH_TEST_CLIENT_SECRET | https://test.example.com/oauth/ofauth/callback |
| Live | OFAUTH_LIVE_CLIENT_ID | OFAUTH_LIVE_CLIENT_SECRET | https://app.example.com/oauth/ofauth/callback |
Approved integration purpose: "Read the selected OnlyFans profile and inbox"
## Scopes we request
profile:read messages:read messages:write
Add a scope here before calling an operation that needs it.
## Where things live
- Authorization start route: src/app/oauth/ofauth/start/route.ts
- Callback route: src/app/oauth/ofauth/callback/route.ts
- Token storage: the ofauth_authorizations table (refresh token encrypted, authorization_id, environment)
- Linked accounts: the ofauth_linked_accounts table (linked account id, authorization_id, status)
- Webhook receiver: src/app/webhooks/ofauth/route.ts (secret in OFAUTH_WEBHOOK_SECRET)
## Rules
- Use the OFAuth version 4 SDK for this app’s language. The API origin is https://api.ofauth.com.
- Keep client secrets, PKCE verifiers, and refresh tokens server-side.
- Use a durable token store with one authorization per key, including client ID and app user ID.
- Bind authorization start and callback to the same trusted user and browser session.
- Persist tokens normally. Use conditional writes when the customer replaces or disconnects a registration.
- Retry transient refresh failures with the same stable token. An invalid refresh grant requires authorization again.
- List shared accounts, save the user’s choice, and verify that account is still shared before use.
- Verify webhook signatures before parsing. Deduplicate on eventId.
- Branch on recovery.action for errors.
- Develop against Sandbox. Do not log in to real Test accounts repeatedly.