Web
The purpose of this article is to describe how to set up Garena authentication so that your web pages can log in through the Garena channel using the Player Network login authentication service.
Prerequisites
1. Setting up the Garena application
Contact the Garena team at:
- Activate the app and get the app ID and other relevant information.
- Configure the callback URL for Garena login on the Developer Platform:
https://test-common-web.intlgame.com/jssdk/garenalogincallback.htmlhttps://common-web.intlgame.com/jssdk/garenalogincallback.html
- (Optional) Turn on
APP_PLATFORM_BINDto enable platform account binding for Garena.
- Create an account for Player Network Console.
- Create a new project for your game, or join an existing one.
- Add Garena as an authentication method for your project on Player Network Console.
For more information about integrating other third-party Channels with the SDK, see JavaScript SDK.
Step 1: Introduce JavaScript SDK
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
- CDN
$ npm install @intlsdk/account-api
// SDK debug version package
<script src="https://test-common-web.intlgame.com/sdk-cdn/account-api/latest/index.umd.js"></script>
// SDK official version package
<script src="https://common-web.intlgame.com/sdk-cdn/account-api/latest/index.umd.js"></script>
Step 2: Use SDK
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,
});
| Parameters | Type | Description | Remarks |
|---|---|---|---|
| env | string | SDK environment For more information, see Retrieve cluster information. | Required |
| gameID | number | Player Network unique game ID | Required |
Step 3: Implement Web Login
After instantiating the accountApi component, call the thirdAuthorize method to request the access token from Garena.
accountApi.thirdAuthorize({
third_type: 'garena',
}).then(
(res) => {
console.log(res);
});
With the Garena token returned, call the intlAuthorize method to get the Player Network SDK OpenID and token to log in to your website.
accountApi.intlAuthorize({
third_type: 'garena',
channel_info: {
token: "EAAI2lTrXAZBwBAC"
garena_sns_openid: "EAAI2lTrXAZBwBAC"
garena_sns_token: "EAAI2lTrXAZBwBAC"
}
}).then(
(res) => {
console.log(res);
});
Call the intlLogout method to log out from your website.
accountApi.intlLogout({
token: '4567xsdfsd',
openid: 'xxxxxxxx',
channel_id: 10,
}).then(
(res) => {
console.log(res);
});