Documentation Index
Fetch the complete documentation index at: https://docs.dc.heliumnetworks.xyz/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide explains how to authenticate users with their existing Discord accounts via OAuth2, enabling seamless login and access to Discord features.Flexible Account Options
If a player does not have a Discord account, you can use the SDK to create a provisional account instead so that they can still access your game’s features. For the account linking integration flow we recommend — provisional account first, and Discord-linked account second — see Recommended Integration Path below.Prerequisites
Before you begin, make sure you have:- Read the Core Concepts guide to understand:
- OAuth2 authentication flow
- Discord application setup
- SDK initialization
- Set up your development environment with:
- Discord application created in the Developer Portal
- Discord Social SDK downloaded and configured
- Basic SDK integration working (initialization and connection)
This feature requires the Default Presence Scopes (
openid and sdk.social_layer_presence).
Use Client::GetDefaultPresenceScopes when configuring your OAuth2 flow.
See the OAuth2 Scopes guide for details on all available scopes.Our Authentication Flow
OAuth2 is the standard authentication flow that allows users to sign in using their Discord account. The process follows these steps:- Request authorization: Your game sends an authentication request to Discord.
- User Approval: The user approves the request, granting access to your application.
- Receive Authorization Code: After approval, Discord redirects the user to your app with an authorization code.
- Exchange for Tokens: The authorization code is exchanged for:
- Access Token, which is valid for ~7 days
- Refresh Token, used to obtain a new access token
The OAuth2 flow requires a user’s account to be verified
OAuth2 using the Discord Social SDK
- If the Discord client has overlay support (Windows only), the OAuth2 login modal appears in your game instead of opening a browser.
- The SDK automatically handles redirects, simplifying the authentication flow.
- Some security measures, such as CSRF protection, are built-in, but you should always follow best practices to secure your app.
Requesting Access Tokens
Step 0: Configure OAuth2 Redirects
For OAuth2 to work correctly, you must register the correct redirect URIs for your app in the Discord Developer Portal.| Platform | Redirect URI |
|---|---|
| Desktop | http://127.0.0.1/callback |
| Mobile | discord-APP_ID:/authorize/callback (replace APP_ID with your Discord application ID) |
Step 1: Request Authorization
The SDK provides helper methods to simplify OAuth2 login. Use theClient::Authorize method to initiate authorization and allow the user to approve access.
Authorization Scopes
One of the required arguments toClient::Authorize is scopes — the set of permissions your game is requesting from the user. The Discord Social SDK provides two helper methods that cover the most common use cases:
| Helper Method | Scopes Requested | Features Enabled |
|---|---|---|
Client::GetDefaultPresenceScopes | openid sdk.social_layer_presence | Account linking, friends list, rich presence |
Client::GetDefaultCommunicationScopes | openid sdk.social_layer | All of the above, plus lobbies, voice chat, direct messaging, and linked channels |
Client::GetDefaultPresenceScopes unless you know you need the communication features. You can always add more scopes later as your integration expands. See the OAuth2 Scopes guide for full details.
Authorization Code Verifier
If you are usingClient::GetToken in Step 4, you will need to specify a “code challenge” and “code verifier” in your requests. We’ll spare you the boring details of how that works (woo… crypto), as we’ve made a simple function to create these for you, Client::CreateAuthorizationCodeVerifier, which you can use to generate the code challenge and verifier.
Step 2: User Approval
After callingClient::Authorize, the SDK will open a browser window, Discord client, or an in-game overlay to prompt the user to approve the request.
Step 3: Receiving the Authorization Code
Once the user approves the request from Step 2, Discord will redirect the user back to your app with an authorization code that you can use to exchange for an access token.Step 4: Exchanging the Authorization Code for an Access Token
Server-to-Server Get Token Exchange
If your application uses a backend server and does not havePublic Client enabled, you can manually exchange the authorization code for an access token using the Discord API.
Example Response
Token Exchange for Public Clients
If your app does not have a backend server, enablePublic Client in the Discord Developer Portal and use Client::GetToken to automatically exchange the authorization code for a token.
We will also need the code verifier used to generate the code challenge in Step 1.
Working with Tokens
Once you’ve received your access token, you’ll want to set the token in the SDK. You can useClient::UpdateToken to do that. At this point, you’re authorized and ready to go! You’ll want to store the player’s access token and refresh tokens somewhere.
Please note that the access_token values do expire. You’ll need to use the refresh_token to refresh the player’s access token.
Refreshing Access Tokens
Access tokens expire after 7 days, requiring refresh tokens to get a new one.Server-to-Server Token Refresh
If you’re handling authentication on your server, send an API request to refresh the token.Refreshing Access Tokens for Public Clients
The easiest way to refresh tokens is using the SDK’sClient::RefreshToken method.
When Refresh Fails
A stored refresh token can become invalid between sessions for several reasons — the user revoked your application from their User Settings → Authorized Apps page, you called the unmerge or token revocation endpoint, or the user’s Discord account was banned. In every one of these cases the response on/oauth2/token with grant_type=refresh_token is the same:
- HTTP status:
400 - Body:
{ "error": "invalid_grant", "error_description": "Invalid \"refresh_token\" in request" }
invalid_grant on refresh, drop the stored Discord tokens for the user and fall back to the provisional account flow to keep the player in-game even if their Discord link is gone.
Revoking Access Tokens
A user’s authorization for your app can be revoked in several ways — by your own backend, by the user from Discord’s UI, or by Discord itself when an account is banned. Regardless of how the revocation is triggered:- The user’s access and refresh tokens are immediately invalidated. Any subsequent refresh on
/oauth2/tokenreturnsHTTP 400witherror: "invalid_grant"(see When Refresh Fails). - An
APPLICATION_DEAUTHORIZEDwebhook is fired to your app.
For Discord Social SDK-integrated apps, every revocation path in this section is mechanically an unmerge: the merged Discord account reverts to a new provisional account carrying the original
external_auth_token. This holds whether revocation comes from /oauth2/token/revoke, Client::RevokeToken, the user removing your app from Discord’s UI, or a ban. Only ban-driven unmerges create a restricted provisional account — the others create an unrestricted one that can be re-merged freely.Server-to-Server Token Revocation
If your application uses a backend server, you can revoke tokens by making an API request to Discord’s token revocation endpoint.Revoking Access Tokens for Public Clients
The easiest way to revoke tokens is using the SDK’sClient::RevokeToken method. This will invalidate all access and refresh tokens for the user and they cannot be used again.
Out-of-Band Revocation
Two paths sever the user’s Discord link without your code calling any unmerge or revoke endpoint:- The user removes your app from their Discord User Settings → Authorized Apps page (a user-initiated unmerge).
- The user’s Discord account is banned (a ban-driven unmerge, with an additional cross-platform-restricted state on the new provisional account).
APPLICATION_DEAUTHORIZED to be notified when either happens. If you miss the webhook, the next token use will fail and your game should fall back to the provisional account flow.
Recommended Integration Path
The recommended path for integrating the Discord Social SDK is that your game has a primary authentication other than Discord that initially sets up a provisional account, and have the player link their Discord account to this primary authentication. This approach protects your users’ game access and data if they encounter issues with their Discord account, such as a permanent or temporary ban. To implement this recommended path:- Create an account through a non-Discord authentication provider, and create a provisional account attached to it.
- When users later authenticate through Discord to link their account, have your game back end execute the merge their provisional account with their Discord Account.
- The account merging process will internally store the
externalAuthTokenfrom the provisional account against their Discord account. If a ban of the Discord account happens, thatexternalAuthTokenwill be attached to the new provisional account that is created in its stead, with the original Discord account’s in-game friends, and will be available through the authentication provider the account was initially setup with. - As a last step, your game back end should maintain the record of the
externalAuthTokenagainst the user account, even after the account merging process, since it will be needed to authenticate via a provisional account should Discord authentication fails for a ban, or any other reason.
Next Steps
Now that you’ve successfully implemented account linking with Discord, you can integrate more social features into your game.Design: Signing In
Design guidelines for account linking and user authentication
Creating a Unified Friends List
Combine Discord and game friends into a single list for easy management.
Setting Rich Presence
Display game status and information to Discord friends.
#social-sdk-dev-help channel for support from the community.
If you encounter a bug while working with the Social SDK, please report it here: https://dis.gd/social-sdk-bug-report
Change Log
| Date | Changes |
|---|---|
| May 22, 2026 | Add out-of-band revocation and recommended integration path |
| March 17, 2025 | initial release |