authWithUserSignature:completion:
User Authentication
This method authenticates the SDK using a user signature (User Signature) obtained from the developer's server. Only after authentication succeeds can the SDK securely access game resources, sync user data, and perform sensitive operations related to the user identity.
Method Declaration
objectivec
/**
Authenticate the SDK with a user signature.
@param userSignature The signature used to authenticate the user.
@param completion Called when authentication finishes.
*/
+ (void)authWithUserSignature:(NSString *)userSignature
completion:(nullable SUDOPCompletionBlock)completion;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| userSignature | NSString * | Yes | The encrypted signature string generated by the server, used to verify the user's legitimacy. |
| completion | SUDOPCompletionBlock | No | Callback invoked when authentication finishes. If the signature is expired or malformed, error carries the specific error information. |
Runtime Behavior
- Permission Activation: After authentication succeeds, the SDK's internal state machine transitions to
Authenticated, allowing calls to core interfaces such as starting a game. - Token Management: After success, the SDK saves the user token and starts user ping. setAuthInvalidatedListener: notifies the host when authentication becomes invalid so it can obtain a fresh signature and authenticate again. The SDK does not fetch host signatures or retry authentication.
- Prerequisite: Must be called after the success callback of
initializeWithConfiguration:completion:. - Failure Semantics: Explicit authentication failure preserves the existing authentication and only returns an error through that call's completion, without an invalidation notification. Each call completes at most once. Old request results cannot overwrite or clear a new authentication.
Example Code
objectivec
// 1. Obtain userSignature from your business server
NSString *myUserSignature = @"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...";
// 2. Call SDK authentication
[SUDOP authWithUserSignature:myUserSignature completion:^(NSError * _Nullable error) {
if (error) {
NSLog(@"User authentication failed: %@", error.localizedDescription);
} else {
NSLog(@"User authentication succeeded, you can now start the game");
}
}];Notes
- Signature Retrieval:
userSignaturemust be generated by the developer's server. Never compute the signature directly on the client to prevent leaking the key (AppKey). - Time Sensitivity: Signatures usually have a validity period. If the SDK returns a signature-expired error, request a new signature from the server and call this interface again.
- Account Switching: Stop the old account's recovery flow and call uninitialize to end the old SDK session. Then initialize again, register the invalidation listener, and authenticate with the new account's signature. Do not treat the old account's authentication as successful authorization for the new account.
- Concurrent Calls: Coalesce explicit authentication and recovery triggers for the same account and serialize “fetch fresh signature → auth”. An old request superseded by a later authentication cannot write authentication state back, and its completion may report failure.
- Recovery Boundary: Wait for authentication before initially loading a game. Re-authentication during gameplay preserves the existing game and does not reload it or replay payments. See the invalidation listener for host retry intervals and background behavior.
