Skip to main content

Web

The purpose of this article is to describe how to set up Discord authentication so that your web pages can log in through the Discord channel using the Player Network login authentication service.

Prerequisites

1. Configuring the application on the Discord Developer Platform
1.1. Create an Application
  1. Register and authenticate your account on the Discord official website
  2. Go to the Developer Platform and click New Application

Image: Create Application

  1. Enter your application name and click Create
  2. On the General Information page, obtain the APPLICATION ID

Image: Obtain App ID

  1. Configure the Discord App ID in INTLConfig.ini
1.2. Apply for SDK Access
  1. Go to the Developer Platform
  2. Click Games - Social SDK, fill out the form, and submit

Image: Fill in form 1

Image: Fill in form 2

Important

Before the official launch of your game, notify the Discord team in advance to enable production permissions.

1.3. Configure OAuth2
  1. Click OAuth2 and turn on the PUBLIC CLIENT option

Image: PUBLIC CLIENT

  1. Configure Redirects:
    • Android/iOS: discord-{YOUR_APP_ID}:/authorize/callback
    • PC: http://127.0.0.1/callback
    • Web: https://common-web.intlgame.com/jssdk/discordlogincallback.html,
      https://test-common-web.intlgame.com/jssdk/discordlogincallback.html

Image: Configure Redirects

1.4. Configure Rich Presence Assets
  1. Click Rich Presence
  2. Click Add Image(s) to upload image assets

Image: Upload assets

  1. Obtain Player Network Console login account.
  2. Create a new project for your game, or join an existing one.
  3. Add Discord as the login authentication method for the service in the Player Network Console.
note

For more information about integrating other third-party channels into the SDK, see JavaScript SDK.

Step 1: Introduce JavaScript SDK

caution

During project integration testing, import the debugging SDK package, which is intended only for integration testing.For project launch, the official SDK package must be imported.

Currently, both npm package method and CDN method are supported.

$ npm install @intlsdk/account-api

Step 2: Use SDK

caution

During integration testing, set env to test environment; when the project goes live, set env to the corresponding official environment.

const accountApi = new IntlgameAccountApi({
env: "test", // SDK environment
gameID: 11,
});
ParametersTypeDescriptionNote
envstringSDK environment
For more information, see Obtain deployment cluster information.
Requir ed
gameIDnumberPlayer Network unique game IDMandatory

Step 3: Implement Web Login

After instantiating the accountApi component, call the thirdAuthorize interface to request an access token for the Discord channel.

accountApi.thirdAuthorize({
third_type: 'discord',
}).then(
(res) => {
console.log(res);
});

When Discord returns the access token, call the intlAuthorize interface to get the Player Network SDK OpenID and token to log into the site.

accountApi.intlAuthorize({
third_type: 'discord',
channel_info: {
access_token: "EAAI2lTrXAZBwBAC"
refresh_token: "EAAI2lTrXAZBwBAC"
expires_in: "EAAI2lTrXAZBwBAC"
redirect_uri: "EAAI2lTrXAZBwBAC"
}
}).then(
(res) => {
console.log(res);
});

Call the intlLogout API to log out from the website.

accountApi.intlLogout({
token: '4567xsdfsd',
openid: 'xxxxxxxx',
channel_id: 26,
}).then(
(res) => {
console.log(res);
});