Ana içeriğe geç

XenForo REST API & OAuth2: External Apps, SSO & Discord Bots

XenForo REST API & OAuth2: External Apps, SSO & Discord Bots

Administrator
XenForo REST API & OAuth2: External Apps, SSO & Discord Bots
Connecting your XenForo forum to external web applications, mobile clients, or community Discord bots eliminates duplicate user accounts and automates cross-platform workflows. By combining XenForo's scoped REST API with XenForo 2.3's native OAuth2 provider, you can authenticate third-party apps securely without exposing database credentials or member passwords.



Generating Scoped REST API Keys for Bots and Automation
For server-to-server integrations—such as a Discord bot posting automated announcements or fetching member rank data—generate a restricted API key rather than granting unrestricted super-user access:
  1. Navigate to AdminCP > Setup > API keys and click Add API key.
  2. Select the key type: Guest key for public read-only endpoints, User key to act on behalf of a dedicated bot account, or Super user key if the integration must pass different user IDs dynamically.
  3. Under Allowed scopes, check only the exact permissions required (for example, thread:write and user:read) so a leaked token cannot alter administrative settings.

External scripts authenticate requests against https://yourdomain.com/api/ by passing the generated token in the XF-Api-Key HTTP header (alongside XF-Api-User when using a super-user key):
Kod:
curl -X GET "https://yourdomain.com/api/users/1/" \ -H "XF-Api-Key: YOUR_GENERATED_API_KEY" \ -H "XF-Api-User: 1"


Configuring XenForo 2.3 as an OAuth2 SSO Identity Provider
XenForo 2.3 natively functions as an OAuth2 authorization server, allowing external sites, game launchers, or custom dashboards to implement a "Log in with Forum Account" single sign-on (SSO) flow:
  1. Open AdminCP > Setup > OAuth2 clients and click Add OAuth2 client.
  2. Enter your application's title, define the exact HTTPS Redirect URIs permitted to receive authorization codes, and select Confidential client type for backend web apps.
  3. Enable the user:read scope so the connected service can retrieve the authenticated member's username, avatar URL, email address, and user group memberships after consent.
  4. Copy the generated Client ID and Client Secret into your external application's OAuth2 client configuration.



Syncing Discord Roles and Securing API Endpoints
When linking a Discord bot to verify forum subscribers, store the member's Discord ID in a custom user field or connect via OAuth2, then query /api/users/{id}/ to inspect the returned user_group_id and secondary_group_ids arrays. Whenever a member purchases a paid upgrade or earns a promotion on XenForo, your bot can automatically assign the matching Discord role.

Always serve API endpoints strictly over HTTPS, configure your web server or Cloudflare WAF to rate-limit /api/* requests against brute-force enumeration, and immediately revoke compromised keys inside AdminCP > Setup > API keys.
İşin Doğrusu Youtube Kanalı

Konu ile Alakalı Benzer Konular

Zamanlanmış görev