Android
This article guides you through setting up Discord as an identity provider, enabling your Android game to access Player Network authentication services.
As authentication through the Discord App has been deprecated in the Discord SDK, using Discord App for authentication may encounter problems in the future. To ensure that Discord authentication remains reliable, we recommend using WebView instead for web authentication for Discord. For more details, see the configuration DISCORD_LOGIN_USING_WEB.
Prerequisites
1. Set up the Discord app on the Discord Developer Platform
For multi-store packages, a separate REDIRECT_URL_SCHEME
is required. One app ID supports 10 Redirect URLs (about 4 multi-store packages). Apply for more app IDs if games require more than 4 multi-store packages. To use multiple app IDs, games need to configure multiple app IDs in INTLConfig.ini
and register multiple Discord apps on the Player Network Console.
1. Create a Discord app
Before creating the Discord app, register an account on the Discord official website and complete the account authentication (by email) according to the prompts.
Go to the Discord Developer Platform.
On the first login, users might have to verify that they are not bots, which may be done after email verification.On the top right corner of the Applications page, click New Application.
In the app creation popup, enter the application name and click Create.
On the General Information page, view the APPLICATION ID.
Users must configure the app ID in the INTLConfig.ini file.
2. Configure the app
The authentication feature on Player Network for Discord requires the identify
scope from Discord. The social feature on Player Network requires the relationships.read
and activities.write
scope from Discord. The For more information, see OAuth2 Scopes.
Go to the Discord Developer Platform.
On the Applications page, click the app to configure.
Click OAuth2 in the left side navigation bar and go to OAuth2 > General.
Under Redirects, fill in the below redirect URLs, which are used to receive callbacks after Discord web authorization. Click Add Another to add more empty fields if required:
- https://common-web.intlgame.com/jssdk/discordlogincallback.html
- https://test-common-web.intlgame.com/jssdk/discordlogincallback.html
noteTo use the Discord app instead of Discord web for authorization on mobile devices, a redirect URL for the Discord app is required for callback after authorization. Redirect URL rules:
- Use all lowercase.
- The scheme should start with "intl".
- The URL should include the host and path.
Example: intlmoba://auth/callback
noteFor multi-store packages:
A separate
REDIRECT_URL_SCHEME
is required to support multi-store packages. One app ID supports 10 Redirect URLs (about 4 multi-store packages). Apply for more app IDs if games require more than 4 multi-store packages. To use multiple app IDs, games need to configure multiple app IDs inINTLConfig.ini
and register multiple Discord apps on Player Network.Click Rich Presence in the left side navigation bar and go to the Rich Presence Art Assets page.
Click Add Image(s) to configure the image resources of the app.
All image resources used in the app must be configured on this page, including cover photos for friend invitations.
- Create an account for Player Network Console.
- Create a new project for your game, or join an existing one.
- Download the SDK.
- Integrate the SDK.
- Add Discord as an authentication method for your project on Player Network Console.
Step 1: Configure the SDK for Discord login
Because the Discord SDK is only compatible with minSdkVersion
>=23 or later, it may have problems running on Android 6.0 or earlier. Set minSdkVersion
>= 23 for games.
In the
AndroidManifest
file, make sure the required permissions have been added. Discord requires access to the network.<uses-permission android:name="android.permission.INTERNET"/>
Open the project's INTLConfig.ini:
[Android LifeCycle]
LIFECYCLE = Discord
[Discord]
DISCORD_APP_ID = {INTL_DISCORD_APP_ID}
DISCORD_REDIRECT_URL = {INTL_DISCORD_REDIRECT_URL}- Add Discord in
LIFECYCLE
. For more information, see SDK Environment. - Replace
{INTL_DISCORD_APP_ID}
with the Discord APPLICATION ID of the game. - Replace
{INTL_DISCORD_REDIRECT_URL}
with the Redirect URL configured on the platform.
- Add Discord in
Complete Gradle configurations.
- Unity
- Unreal Engine
In mainTemplate.gradle
, add DISCORD_APP_ID
, DISCORD_REDIRECT_SCHEME
, DISCORD_REDIRECT_HOST
, DISCORD_REDIRECT_PATH
.
android {
defaultConfig {
manifestPlaceholders = [
"DISCORD_APP_ID":"{INTL_DISCORD_APP_ID}",
"DISCORD_REDIRECT_SCHEME":"{INTL_DISCORD_REDIRECT_SCHEME}",
"DISCORD_REDIRECT_HOST":"{INTL_DISCORD_REDIRECT_HOST}",
"DISCORD_REDIRECT_PATH":"{INTL_DISCORD_REDIRECT_PATH}"
]
}
}
Because Discord requires apps to have a minSdkVersion
of at least 23, UE projects must update the minSdkVersion
configuration to at least 23 during packaging.
In INTLCore_UPL.xml
, add DISCORD_APP_ID
, DISCORD_REDIRECT_SCHEME
, DISCORD_REDIRECT_HOST
, and DISCORD_REDIRECT_PATH
.
<buildGradleAdditions>
<insert>
<![CDATA[
android{
defaultConfig {
manifestPlaceholders = [
"DISCORD_APP_ID":"{INTL_DISCORD_APP_ID}",
"DISCORD_REDIRECT_SCHEME":"{INTL_DISCORD_REDIRECT_SCHEME}",
"DISCORD_REDIRECT_HOST":"{INTL_DISCORD_REDIRECT_HOST}",
"DISCORD_REDIRECT_PATH":"{INTL_DISCORD_REDIRECT_PATH}"
]
}
}
]]>
</insert>
</buildGradleAdditions>
- Replace
{INTL_DISCORD_APP_ID}
with the Discord App ID of the game. - Replace
{INTL_DISCORD_REDIRECT_SCHEME}
with the scheme configured in the Redirect URL. - Replace
{INTL_DISCORD_REDIRECT_HOST}
with the host of the Redirect URL configured for the game. - Replace
{INTL_DISCORD_REDIRECT_PATH}
with the path of the Redirect URL configured for the game.
For example, if the Redirect URL configured on the Discord Developer Platform is intlsample://auth/callback
:
{INTL_DISCORD_REDIRECT_SCHEME}
= intlsample{INTL_DISCORD_REDIRECT_HOST}
= auth{INTL_DISCORD_REDIRECT_PATH}
= callback
Step 2: Add Discord login
Discord does not require an app installation before login. If the app has already been installed, open the app to log in. Otherwise, the web login interface will open. When the Discord is installed, if a player tries to log in with Discord and then cancelled the login, they will still be redirected to the game as the system cannot immediately call back "Cancelled". The player needs to wait until the login times out, and the system will then call back "Timeout".
Discord login permission
requires identify
to be added. If the Discord sharing function is required, relationships.read,activities.write
should be added.
Add an observer to handle authentication callbacks.
- Unity
- Unreal Engine
// Add callbacks
public void AddAuthObserver()
{
INTLAPI.AddAuthResultObserver(OnAuthResultEvent);
}
// Remove callbacks
public void RemoveAuthObserver()
{
INTLAPI.RemoveAuthResultObserver(OnAuthResultEvent);
}
// Process the INTLAuthResult callback
public void OnAuthResultEvent(INTLAuthResult ret)
{
Debug.Log($"MethodID: {ret.MethodId}");
string methodTag = "";
if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_LOGIN)
{
methodTag = "Login";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_BIND)
{
methodTag = "Bind";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_AUTOLOGIN)
{
methodTag = "AutoLogin";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_QUERY_USER_INFO)
{
methodTag = "QueryUserInfo";
}
else if (authRet.MethodId == (int)INTLMethodID.INTL_AUTH_GET_AUTH_RESULT)
{
methodTag = "GetAuthResult";
}
}C++ Event Handling (above v1.15)
//configure callback
FINTLAuthEvent authEvent;
authEvent.AddUObject(this, &OnAuthResult_Implementation);
UINTLSDKAPI::SetAuthResultObserver(authEvent);
// Remove callbacks
UINTLSDKAPI::GetAuthResultObserver().Clear();void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Unreal Event Handling
void OnAuthResult_Implementation(FINTLAuthResult ret)
{
UE_LOG(LogTemp, Warning, TEXT("MethodID: %d"), ret.MethodId);
}Call the
AutoLogin
method.- Unity
- Unreal Engine
INTLAPI.AutoLogin();
UINTLSDKAPI::AutoLogin();
Call the
Login
method to ask for user input if auto-login fails.- Unity
- Unreal Engine
INTLAPI.Login(INTLChannel.Discord, "identify", "");
INTLAPI.Login(INTLChannel.Discord, "identify,relationships.read,activities.write", ""); //Friend functionsUINTLSDKAPI::Login(EINTLLoginChannel::Discord, "identify", "");
UINTLSDKAPI::Login(EINTLLoginChannel::Discord, "identify,relationships.read,activities.write", ""); //Friend functionsSync client authentication state with the game's backend and wait for the final authentication result.
Step 3: Test the login function
Search for the keyword "AuthResult" in the Player Network SDK logs to verify if the correct channel name and OpenID are returned. If they are, it indicates a successful configuration and the login function has been added successfully.