Skip to main content

Android

This article guides you through setting up Discord as an identity provider, enabling your Android game to access Player Network authentication services.

note

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
note

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.

  1. 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.

  2. On the top right corner of the Applications page, click New Application.

    Image: Create an app

  3. In the app creation popup, enter the application name and click Create.

  4. On the General Information page, view the APPLICATION ID.
    Users must configure the app ID in the INTLConfig.ini file.

    Image: Get the ID

2. Configure the app

caution

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.

  1. Go to the Discord Developer Platform.

  2. On the Applications page, click the app to configure.

  3. Click OAuth2 in the left side navigation bar and go to OAuth2 > General.

  4. 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:

    Image: Configure Redirect

    note

    To 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

    note

    For 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 in INTLConfig.ini and register multiple Discord apps on Player Network.

  5. Click Rich Presence in the left side navigation bar and go to the Rich Presence Art Assets page.

  6. 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.

    Image: Configure assets

  1. Create an account for Player Network Console.
  2. Create a new project for your game, or join an existing one.
  3. Download the SDK.
  4. Integrate the SDK.
  5. Add Discord as an authentication method for your project on Player Network Console.

Step 1: Configure the SDK for Discord login

caution

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.

  1. 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"/>
  2. 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.
  3. Complete Gradle configurations.

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}"
]
}
}
  • 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.
note

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.

  1. Add an observer to handle authentication callbacks.

    // 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";
    }
    }
  2. Call the AutoLogin method.

    INTLAPI.AutoLogin();
  3. Call the Login method to ask for user input if auto-login fails.

    INTLAPI.Login(INTLChannel.Discord, "identify", "");
    INTLAPI.Login(INTLChannel.Discord, "identify,relationships.read,activities.write", ""); //Friend functions
  4. Sync 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.