#
If the app server is implemented by using Java, Go, or Node.js, you can directly use the server SDK provided by Sud to implement authentication. Refer to the demo for the specific process.
If the app server is implemented by using other languages or you want to implement authentication by yourself, comply with the following rules:
1. Implement the following four API operations by yourself: login, GetSSToken, UpdateSSToken, and GetUserInfo
Login
- Call method: GET or POST
- Caller: app client
- Description: The app client can call this operation to obtain a short-term token (Code). The short-term token (Code) must be bound to the user login state. If the game server uses the short-term token (Code) as a parameter to call the GetSSToken operation implemented by the app server, the app server needs to identify the user ID corresponding to the short-term token (Code). Then, the app server needs to generate a long-term token (SSToken) based on the user ID and return the long-term token (SSToken) to the game server.
Obtain a long-term token (GetSSToken)
- Call method: POST
- Caller: game server
- Description: The game server can call this operation by using the short-term token (Code) generated by the login operation as a parameter to obtain a long-term token (SSToken) for server-to-server interactions. The app server needs to identify the user ID corresponding to the short-term token (Code), generate a long-term token (SSToken) based on the user ID, and return the long-term token (SSToken) to the game server. If the short-term token (Code) used by the game server has expired, the app server needs to set the value of the sdk_error_code field in the response to 1005. For more information, see the usage notes.
- Reference: get_sstoken
Update a long-term token (UpdateSSToken)
- Call method: POST
- Caller: game server
- Description: The game server can call this operation by using the long-term token (SSToken) generated by the GetSSToken operation as a parameter to obtain a new long-term token (SSToken).
- Reference: update_sstoken
Obtain user information (GetUserInfo)
- Call method: POST
- Caller: game server
- Description: The game server can call this operation by using the long-term token (SSToken) generated by the GetSSToken or UpdateSSToken operation as a parameter to obtain the user information corresponding to the long-term token (SSToken).
- Reference: get_user_info
2. Usage notes
- All tokens, including short-term tokens (Code) and long-term tokens (SSToken), must be bound to user IDs. The app server needs to identify the user ID corresponding to a token for subsequent logic processing.
- The response bodies of the GetSSToken, UpdateSSToken, and GetUserInfo operations must be in the underscore delimited format (snake case).
- If the app server detects that a token has expired, the app server must set the sdk_error_code field in the response to 1005. Example:
{ "ret_code": 1, // The error code. "ret_msg": "", "sdk_error_code":1005, // The SDK error code indicating that the token has expired. "data": {} }