# User Identity

When users log in or log out of the app, make sure to synchronize the status with AIHelp to confirm or reset the user identity.

Note

Please ensure that the userId provided to AIHelp is a unique and valid value.

Using invalid values for userId, such as an empty string (""), "null", 0, or -1, may lead to issues with customer support functionality.

# API

# login()

When users log into the app, synchronize the user ID with AIHelp so that we can generate a identity token for them.

AIHelpSupport::login("THIS IS YOUR USER ID");

Alternatively, you can achieve other capabilities by configuring LoginConfig, such as other user information, enterprise-level identity authorization, login status callback, etc.:



 
 



LoginConfig loginConfig = LoginConfigBuilder()
        .setUserId("THIS IS YOUR USER ID")
        .setUserConfig(...)
        .setEnterpriseAuth(...)
        .build();
AIHelpSupport::login(loginConfig);

# logout

When users log out, call this method to clear the current logged-in user information to ensure the accuracy of the guest identity after logging out.

AIHelpSupport::logout();

# Event

# Logging in

You can register the USER_LOGIN event to keep track of the logging in status for current user:

AIHelpSupport::registerAsyncEventListener(
        EventType::USER_LOGIN,
        [](const char *jsonData, Acknowledge ignored) {
            // `jsonData`: { "code": 1, "message": "Success" }
        }
);

The code field for jsonData can be one of:

  • 1 for success;
  • -1 for invalid user id;
  • -2 for failure, check the message field for more information;

# Authentication

If you intend to authenticate user by your side by configuring setEnterpriseAuth, the ENTERPRISE_AUTH event will be triggered when login API is invoked.

And you should register the event and authenticate the user, and then pass the retrieved user token back to us via the ack callback.

AIHelpSupport::registerAsyncEventListener(
        EventType::LOG_UPLOAD,
        [](const char *ignored, Acknowledge ack) {
            std::async(std::launch::async, [jsonData, ack]() {
                std::this_thread::sleep_for(std::chrono::milliseconds(1000));
                ack(EventType::ENTERPRISE_AUTH, "{\"token\":\"this is your token\"}");
            });
        }
);

For compatibility purposes, the data passed back to AIHelp should be in JSON format. The user token should be stored under the key token.

# Definition

# loginConfig

  • Type: LoginConfig
  • Details: Required. Encapsulation of optional configuration items for login.

# userId

  • Type: String
  • Default: A random number generated by the user's device
  • Details: Required. Unique user identifier, cannot be an empty string, 0, or -1.

# userConfig

  • Type: UserConfig
  • Default: null
  • Details: Optional. User information configuration items, including username, server ID, user tags, and other custom data. Besides logging in, you can also call updateUserInfo API to update user information whenever you need.
  • Code example:
     
     
     
     
     
     



     




    UserConfig userConfig = UserConfigBuilder()
            .setUserName("AIHelper")
            .setServerId("s-101")
            .setUserTags("vip1,suggestion")
            .setCustomData("{'total_recharge': 10000, 'level': 34}")
            .build();
    
    LoginConfig loginConfig = new LoginConfig.Builder()
            .setUserId("THIS IS YOUR USER ID")
            .setUserConfig(userConfig)
            .build();
    
    AIHelpSupport::login(loginConfig);
    

# isEnterpriseAuth

  • Type: boolean
  • Default: false
  • Details: Optional. You need to register the EventType.ENTERPRISE_AUTH event to obtain the user token if you enable this field.
  • Code example:


     




    LoginConfig loginConfig = LoginConfigBuilder()
            .setUserId("THIS IS YOUR USER ID")
            .setEnterpriseAuth(true)
            .build();
    
    AIHelpSupport::login(loginConfig);
    

# Other

# Enterprise Authorization Process

To maximize security, you can opt to handle user authentication logic yourself, known as enterprise authorization.

Enterprise authorization is a type of server-side validation, where the validation process is completely managed on the server, and the SDK and game client do not hold any keys.

The enterprise authentication logic sequence is as follows:

  1. The game client calls the SDK login interface, specifying the userId and enabling enterprise authentication;
  2. The SDK sends an enterprise authentication event. After the client receives the corresponding callback, it requests the game server to authenticate the player;
  3. After receiving the server's response, the game client uses the ack callback in the enterprise authentication event to return the token issued by the server to the SDK;
  4. The SDK uses the received token to request the AIHelp server interface. The server will perform a secondary validation of the token; if the token is not valid, a login failure will be returned.

# Token Generation Rules

During the enterprise authentication process, you need to obtain the secret key from the AIHelp backend and issue a token for the user on the server.

The token generation rules are as follows:

  1. Use the secret key issued by AIHelp, which can be obtained from the backend under Settings - Application Settings - SecretKey;
  2. Use the HS256 signing algorithm, with a recommended validity period of 24 hours;
  3. Generate a JWT in the standard format, as follows:
{
    "exp": 1718868267, // Expiration timestamp (seconds)
    "iat": 1718781867, // Issuance timestamp (seconds)
    "nbf": 1718781867, // Not Before timestamp (seconds)
    "iss": "xxxx", // Custom identifier
    "jti": "947b3086-9aad-40d8-b5cf-752c9294f392" // UUID
}
Last Updated: 11/8/2024, 3:33:32 AM