Android
This article guides you through setting up VNG as an identity provider, enabling your Android game to access Player Network authentication services.
Prerequisites
1. Set up the VNG app
Contact VNG to apply the following app configuration parameters.
- VNG GameID
- appsFlyerDevKey (if you have applied for AppsFlyer from VNG)
- 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 VNG as an authentication method for your project on Player Network Console.
Step 1: Configure the SDK
Set the following values in the
GTSDK.json
file underAssets/Plugins/Android/INTLVNG.androidlib/assets
.{
"gameID": "VNG_GameId",
"appsFlyerDevKey": "VNG_appsFlyerDevKey",
"gameVersion": "1.0.0",
"modules": [
{
"name": "GGID",
"clientId": "{VNG_GG_APP_ID}",
"clientToken": "{VNG_GG_CLIENT_TOKEN}"
}
]
}Place
GTSDK.json
in theassets
directory.
Do not change the location and file name ofGTSDK.json
as the VNG SDK internally reads the content namedGTSDK.json
in the specified directory.Define
manifestPlaceholders
in the gradle file by replacing{INTL_VNG_GG_APP_ID}
and{INTL_VNG_GG_CLIENT_TOKEN}
with the VNG App ID and Client Token.- Unity
- Unreal Engine
mainTemplate.gradleandroid {
defaultConfig {
manifestPlaceholders = [
'VNG_GG_APP_ID' : '{INTL_VNG_GG_APP_ID}',
'VNG_GG_CLIENT_TOKEN' : '{INTL_VNG_GG_CLIENT_TOKEN}',
]
}
}noteFor Player Network SDK V1.17 and later, edit INTLConfig_APL.xml.
For Player Network SDK V1.16.04 and earlier, edit INTLCore_UPL.xml.
INTLCore_UPL.xml<buildGradleAdditions>
<insert>
<![CDATA[
android{
defaultConfig {
manifestPlaceholders = [
'VNG_GG_APP_ID' : '{INTL_VNG_GG_APP_ID}',
'VNG_GG_CLIENT_TOKEN' : '{INTL_VNG_GG_CLIENT_TOKEN}',
]
}
}]]>
</insert>
</buildGradleAdditions>[Optional] If
minSdkVersion
does not match, add the following code to the project's manifest.<uses-sdk tools:overrideLibrary="vng.com.gtsdk,vng.com.gtsdk.gtloginkit,vng.com.gtstk.gtzingkit,vng.com.gtsdk.gtextension,vn.com.vng.gg.ggsigninsdk,com.intlgame.vng" />
[Optional] For Unity, refer to the
mainTemplate.gradle
provided in SDK, and add the corresponding field such asandroidDependenciesAdapter
,intlChannelDespendencies
,androidXDependencies
,commonVersions
,thirdChannel
./*Intlvng_start*/
Implementation rootproject.extRoidDePendenCiesadapter.appCompat
Implementation rootproject.Ext.intlChanneneLDESPENDENCIES.ROFIT2GSON
Implementation rootproject.Ext.intlChanneldespendenCies.FirebaseMessage
Implementation rootproject.Ext.intlChanneldespendenCies.googlegcm
Implementation rootproject.Ext.intlChannelDespendenCies.appsFlyer
Implementation rootproject.Ext.intlChanneldespendenCies.installreferrerrrrrr
Implementation rootproject.ext.androidXDependenCies.lifecycle
/*Intlvng_end*/
Step 2: Add VNG login
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.When a user has logged in before, the game backend can achieve automatic login by calling the auto-login interface. If the token is still effective within the validity period, login will be successful. If the token fails, an error prompt will appear, and the game needs to call the manual login interface to log in again.
- 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.VNG, "", "");
UINTLSDKAPI::Login(EINTLLoginChannel::kChannelVNG);
After calling the API, the following window will appear:
The parameters returned after logging in is:
{
"extraJson":"
{
}",
"methodID":102,
"retCode":0,
"retMsg":"Success",
"ret":0,
"msg":"success",
"bind_list":"",
"birthday":"",
"channel":"VNG",
"channel_info":"
{
\"email\":\"null\",
\"expire_ts\":1660373805,
\"session_id\":\"MTSVN_23195b047d99a2b164296ab85cb956fa76e631657781803922\",
\"social_id\":\"646605735\",
\"update_in\":1657781803520,
\"user_id\":\"2213855217680687104\",
\"user_name\":\"mtschecking02\"
}",
"channelid":38,
"confirm_code":"",
"confirm_code_expireTime":0,
"del_account_status":-10,
"first_login":0,
"gender":0,
"legal_doc":"",
"openid":"824624458301451",
"pf":"unknown_uk-00000000-android-00000000-uk-MTSVN-824624458301451",
"pf_key":"4c5a49c1407cfe7ab09fba44e343810e",
"picture_url":"",
"need_name_auth":false,
"token":"bd13b7147297a5c58c27f414ea21ae00f67f2208",
"token_expire_time":1660373805,
"user_name":"mtschecking02"
}cautionThe user_id is the only identification of the current user, use it on the customer service interface.
Sync client authentication state with the game's backend and wait for the final authentication result.
Logout
Users can log out of the current login channel. The game backend need to call the interface Logout
and pass the relevant parameters.
- Unity
- Unreal Engine
INTLAPI.Logout();
UINTLSDKAPI::Logout();
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.
Other Functions
Link
Users can link VNG and channels that have been logged in, such as operations such as synchronous data. Users can call the Bind
interface and pass the relevant parameters.
Taking Facebook as an example:
- Unity
- Unreal Engine
INTLAPI.Bind(INTLChannel.Facebook);
UINTLSDKAPI::Bind(EINTLLoginChannel::kChannelFacebook);
For more information, see the Bind
API for Unity SDK or Unreal Engine SDK.
VNG Customer Service
VNG provides customer service, and supports it through extend in Player Network SDK. The callback is:
- Unity
- Unreal Engine
string json="{\"user_id\":\"xxx\",\"login_type\":\"ZM\"}";;
INTLAPI.ExtendInvoke(INTLChannel.VNG, "showCustomerSupport",json);
FString json="{ \"user_id\":\"xxx\",\"login_type\":\"ZM\"}";;
UINTLSDKAPI::ExtendInvoke(EINTLLoginChannel::kChannelVNG, "showCustomerSupport",json);
The content in JSON includes the following fields, that users can fill in as needed:
Name | Field | Description | Remarks |
---|---|---|---|
user_id | string | Log in the user ID | Required |
login_type | string | User login type | Required (zing corresponds: "zm") |
role_name | string | Character Name | Optional |
level | string | Character level | Optional |
guild | string | Groups of character belonging | Optional |
content | string | Is the character ID | Optional |
server_id | string | Server ID | Optional |
The corresponding value of login_type is:
Login channel | Logintype |
---|---|
Guest | GU |
FB | |
GG | |
ZingID | ZM |
LINE | LINE |
AppleID | AP |
EM | |
Zalo | ZL |
VNG ID | CM |
The following interface will appear after calling:
The following parameter will be returned when the page is closed:
{
"extraJson":"
{
}",
"methodID":1301,
"retCode":0,
"retMsg":"Success",
"ret":0,
"msg":"",
"channel":"VNG",
"extend_method_name":"showCustomerSupport"
}