> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ofauth.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Better Auth

> Link OFAuth to an existing application user through Generic OAuth.

Use stock Better Auth Generic OAuth with explicit endpoints. Better Auth owns callback validation, ordinary account-token persistence, and refresh. Use its access token when you call the OFAuth API.

## Configure Generic OAuth

Register the exact callback `https://your-app.example/api/auth/callback/ofauth` for your Better Auth base URL and base path. Check the callback URL generated by your pinned Better Auth version.

```typescript theme={null}
import { betterAuth } from "better-auth"
import { genericOAuth } from "better-auth/plugins"

export const auth = betterAuth({
	// Keep your application's existing database and session configuration.
	account: {
		accountLinking: {
			enabled: true,
			allowDifferentEmails: true
		}
	},
	plugins: [genericOAuth({
		config: [{
			providerId: "ofauth",
			clientId: process.env.OFAUTH_CLIENT_ID!,
			clientSecret: process.env.OFAUTH_CLIENT_SECRET!,
			authorizationUrl: "https://link.ofauth.com/v3/authorize",
			tokenUrl: "https://api.ofauth.com/v3/link/token",
			userInfoUrl: "https://api.ofauth.com/v3/link/userinfo",
			tokenEndpointAuth: { method: "client_secret_basic" },
			scopes: ["identity:read", "profile:read"],
			pkce: true,
			disableSignUp: true
		}]
	})]
})
```

`allowDifferentEmails` is an explicit policy for this signed-in linking journey. The provider identity must still satisfy Better Auth’s verified-email policy. Different-email permission does not trust an unverified or absent provider email. Preserve your application’s policy if different-email linking is inappropriate. Do not add blanket `trustedProviders` or automatically replace the user's login identity or profile. Configure token encryption through your supported Better Auth storage settings.

## Link from an existing session

Start linking from your signed-in application session. Generic OAuth providers use the core client's `linkSocial`; no client plugin is needed:

```typescript theme={null}
import { createAuthClient } from "better-auth/client"

const authClient = createAuthClient()

await authClient.linkSocial({
	provider: "ofauth",
	callbackURL: "/settings/accounts"
})
```

OFAuth owner identity, the Better Auth account row, and the selected OnlyFans linked account are separate identifiers. `identity:read` permits owner profile access; it does not grant an account operation.

Userinfo returns matching stable `id` and `sub`. Email is returned only when known and permitted, with truthful verification. Guest API delegation needs no forced signup or fabricated email. A profile-based linking journey must satisfy Better Auth's identity requirements or complete OFAuth's supported identity step explicitly.

## Use the current access token

On your backend, call Better Auth's supported token API for the linked account:

```typescript theme={null}
const accounts = await auth.api.listUserAccounts({ headers: request.headers })
const linked = accounts.filter(account => account.providerId === "ofauth")
if (linked.length !== 1) throw new Error("Select the linked OFAuth identity")
const account = linked[0]
const token = await auth.api.getAccessToken({
	headers: request.headers,
	body: { accountId: account.id }
})
const response = await fetch("https://api.ofauth.com/v3/access/profile", {
	headers: {
		Authorization: `Bearer ${token.accessToken}`,
		"x-linked-account-id": selectedLinkedAccountId
	}
})
```

If your policy allows multiple OFAuth identities, select the Better Auth `accountId` when obtaining the token. [List the shared accounts](https://docs.ofauth.com/v3/api-reference/account/linked-accounts.md) and have the user choose which account to use.

Do not add a custom token exchange, OFAuth refresh table, PostgreSQL advisory lock, or a second SDK credential manager. Concurrent refreshes return independent access tokens and the same client-bound refresh token.

For a revoked refresh grant, offer account linking again. For a provider session error, [reconnect that linked account](https://docs.ofauth.com/v3/guides/reconnect.md). These are separate recovery actions.

## Operator private apps

For private apps, follow the [Operator app guide](https://docs.ofauth.com/v3/guides/operator-apps.md). This Generic OAuth recipe uses the developer app user info endpoint.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.