# 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(...)
        .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:

FAIHelpForUEModule::Get().GetAIHelp()->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

When Enterprise Authentication is enabled in the AIHelp admin panel, 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.

FAIHelpForUEModule::Get().GetAIHelp()->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);
    

# Other

# Enterprise Authentication Flow

To maximize security, you can handle user identity authentication logic on your own server — known as Enterprise Authentication.

Enterprise authentication is a server-side verification process; the SDK and game client do not hold any secret keys.

The sequence of enterprise authentication is as follows:

  1. Enable enterprise authentication and obtain the secret key from the AIHelp admin panel:

  2. The client calls the SDK login API;

  3. The SDK triggers the Enterprise Authentication event, and the client receives a callback. Then it sends a request to the game server to verify the player's identity;

  4. The client receives the server's response and returns the token issued by the server to the SDK via the ack callback inside the enterprise authentication event;

  5. The SDK uses the received token to request the AIHelp server. The server will verify the token:

    • For verified users, AIHelp will mark them as authenticated in the backend and allow normal login;
    • For unverified users, depending on whether Force Authentication is enabled, AIHelp will:
      • Block the login request and return a failure response to prevent further unauthorized requests;
      • Mark the user as unauthenticated in the backend without affecting their ability to submit support tickets.

# Token Generation Rules

During the enterprise authentication process, you need to obtain the secret key from AIHelp and issue a token for the user on your server, based on the following rules:

  1. Use the secret key provided by AIHelp, available in Backend Settings - App Settings - Auth Secret Key;
  2. Use the HS256 signing algorithm; a recommended token validity period is 24 hours;
  3. Generate a standard-format JWT, with the following claims:
{
    "exp": 1718868267, // Expiration timestamp (in seconds)
    "iat": 1718781867, // Issued-at timestamp (in seconds)
    "nbf": 1718781867, // Not-before timestamp (in seconds)
    "iss": "xxxx", // Custom issuer
    "jti": "947b3086-9aad-40d8-b5cf-752c9294f392" // UUID
}
  • sub (required): Unique user identifier, same as the userId used in the login API
  • iss (required): Recommended to use your company's English name or abbreviation
  • jti (required): Recommended to use a UUID
  • exp (required): Expiration timestamp (in seconds), recommended to set to current time + 24 hours
  • iat (optional): Issued-at timestamp (in seconds), set to current time
  • nbf (optional): Not-before timestamp (in seconds), recommended to set to current time

You can refer to the sample code we provide (opens new window) for token generation and validation.

Last Updated: 6/22/2025, 9:15:27 AM