The Connections module (sdk.link.connections) provides methods to manage active OnlyFans connections established through OFAuth Link. These connections represent authenticated relationships between your application and OnlyFans accounts.
Link vs Access: OFAuth Link handles the OAuth-style authentication flow where users securely connect their accounts. Once connected, you use OFAuth Access with these connection IDs to make API calls to OnlyFans endpoints.
Connection Lifecycle: Connections are created when users complete the OFAuth Link authentication flow and can be managed through these SDK methods.
const { data: result, error } = await sdk.link.connections.delete( "conn_123456789")if (error) { if (error.type === "not_found") { console.log("Connection was already deleted or doesn't exist") } else { console.error("Failed to delete connection:", error.message) }} else { console.log("Connection deleted:", result.message) // Remove connection from your local storage/database await removeStoredConnection("conn_123456789")}
Copy
{ "data": { "success": true, "message": "Connection conn_123456789 has been successfully deleted" }, "error": undefined}
Permanent Action: Deleting a connection permanently revokes access to the OnlyFans account. The user would need to re-authenticate through the Link flow to restore access.
Invalidate a connection, marking it as expired while preserving the connection record. Use this when you need users to reconnect with updated permissions.
Preserves Connection Record: Unlike delete(), invalidating a connection keeps the connection record intact. The user can reconnect using the same connection ID, and their profile data will be preserved.
When your platform’s required permissions change, use invalidate to prompt users to reconnect:
Copy
async function updateUserPermissions(connectionId: string) { // 1. Invalidate the existing connection const { error: invalidateError } = await sdk.link.connections.invalidate( connectionId ) if (invalidateError) { console.error("Failed to invalidate:", invalidateError.message) return } // 2. Initialize a new Link session with the same connectionId const { data: linkSession, error: linkError } = await sdk.link.init({ connectionId: connectionId, redirectUrl: "https://yourapp.com/callback" }) if (linkSession) { // 3. Redirect user to reconnect with new permissions console.log("Redirect user to:", linkSession.url) }}
Connections can have different statuses that affect their usability:
Active
Expired
Awaiting 2FA
Status: activeConnection is valid and can be used for API calls.
Copy
if (connection.status === "active") { // Safe to use for API calls const { data } = await sdk.self.getMe({ authentication: { connectionId: connection.id } })}
Status: expiredConnection has expired and cannot be used for API calls.
Copy
if (connection.status === "expired") { console.log("Connection expired, user needs to re-authenticate") // Redirect user to re-authentication flow await initiateReAuthentication(connection.platformUserId)}
Status: awaiting_2faConnection is waiting for two-factor authentication to complete.
Copy
if (connection.status === "awaiting_2fa") { console.log("Connection awaiting 2FA, user needs to complete verification") // Prompt user to complete 2FA verification await promptUser2FA(connection.id)}
const { data, error } = await sdk.link.connections.delete("conn_123456789")if (error && error.type === "forbidden") { console.log("You don't have permission to delete this connection") // This connection might belong to another application}