Skip to main content

New Player Authentication on Client

This page describes Player Authentication on clients.

In Player Authentication on clients, game clients can proceed player authentication and linking an application user to an player ID through client API.

warning
  • Please be sure to read overview before implementations.
  • InAppUserId only accepts ascii characters. Use Extras if non-ascii characters are required.
  • Now player authentication can be even after the initial launch (from 2017/03/15).
warning

Please confirm the implementation confirmation of player authentication and send the excel sheet to DeNA as soon as player authentication is implemented.

Client API​

After an initialization of AndApp SDK, use AndApp::UserSession::GetCurrent() method to get AndApp::UserSession. Then use the following API.

info

The APIs called like the following:

AndApp::UserSession session = AndApp::UserSession::GetCurrent();

session.SetInAppUserId().

session->SetInAppUserId(inAppUserId, extras, [](const AndApp::Error &error) {}) {#DevelopmentCpp_AboutPlayer_OnClient_AndApp-session->SetInAppUserIdinAppUserId,extras,[]constAndApp::Error&error{}.1}​

  • Set the application user to be linked to the player ID.
  • inAppUserId represents the application user ID.
  • extras represents additional information to the application user in form of key/value pairs.
  • GetInAppUserId() API can get values stored by SetInAppUserId().
  • inAppUserId can be set even if the given inAppUserId is linked to another player with some exception. The existing link to the player will be lost.
  • inAppUserId cannot be set if the given inAppUserId is linked to another player and the player is linked to an IdP account. SetInAppUserId() returns -21061.
  • inAppUserId cannot be set if the given inAppUserId had been linked to another player before and the player is linked to an IdP account. SetInAppUserId() returns -21063 as error code.
CodeDescription
-21061Given inAppUserId is associated with another player and the player is linked to an IdP account
-21063

Given inAppUserId had been associated with another player before and the player is linked to IdP account

(AndApp Client 1.1.1 or below, returns -21061 error)

session->GetInAppUserId([](const AndApp::Error &error, const std::string &inAppUserId, std::shared_ptrAndApp::JsonObject extras) {} ) {#DevelopmentCpp_AboutPlayer_OnClient_AndApp-session->GetInAppUserId[]constAndApp::Error&error,conststd::string&inAppUserId,std::shared_ptrAndApp::JsonObjectextras{}.1}​

  • Get inAppUserId and extras set by SetInAppUserId().
  • GetInAppUserId() returns -21062 error If inAppUserId is not linked to any player ID.
CodeDescription
-21062inAppUserId is not linked to any player

Use case​

We assume the following implementation of smartphone application.

The following marked as red needs to be implemented.

Only change for the game is to use our client API (AndApp::UserSession::SetInAppUserId() or AndApp::User::Session::GetInAppUserId) to store application user id instead of application specific storage (like local storage on client apps). Player authentication process does not need further changes in most cases.

The game requires to implement error handling for AndApp::UserSession::SetInAppUserId(). The game client needs to display a user friendly error message. For example, "The application user is already linked to another player. Please login with Mobage user to play with the application user".

Reference Implementation​

warning

The following code needs to be after the AndApp SDK initialization processing.

保存処理

std::string inAppUserId = "test_inappuserid";
std::shared_ptr<AndApp::JsonObject> extras;
AndApp::UserSession* session = AndApp::UserSession::GetCurrent();

session->SetInAppUserId(inAppUserId, extras, [=](const AndApp::Error &error) {
if (error.GetCode() != 0) {
if (error.GetCode() == -21061) {
// Processing when linking with a player ID already linked with IdP
} else if ( error.Code == -21063 ) {

// Processing when the InAppUserId that has been linked with the player ID already linked with IdP in the past is specified
} else {
// Processing on error
}
}
else {
// Continue the application
}
});

取得処理

AndApp::UserSession* session = AndApp::UserSession::GetCurrent();
session->GetInAppUserId([=](const AndApp::Error &error, const std::string &inAppUserId, std::shared_ptr<AndApp::JsonObject> extras) {
if (error.GetCode() != 0) {
if (error.GetCode() == -21062) {
// Process when the InAppUserId associated with the player ID is not set
}
else {
// Processing on error
}
}
else {
// Continue the application using inAppUserId
}
});

Change log​

  • 2017/04/17
    • Add description about implementation confirmation of player authentication
  • 2017/03/15
    • Alleviating various restrictions and adding error codes with the behavior change of AndApp SDK (SetInAppUserId (), GetInAppUserId ()).
  • 2017/01/30
    • Added to inAppUserId that it can not be set except ASCII string
  • 2016/11/02
    • Create New