Unity Authentication
Show the login screen
AlogameAuth.ShowLoginUI() opens the SDK's login / register / guest screen and completes when
the player is in. For a stored session it completes at once, after the server maintenance
check.
using Alogame.SDK;
using UnityEngine;
public class Bootstrap : MonoBehaviour
{
private async void Start()
{
AlogameSDK.Initialize(53);
// The SDK dashboard can log the player out, or delete the account, on its own,
// then shows its login screen again. Follow it:
AlogameAuth.SessionEnded += _ => ReturnToTitleScreen();
AlogameAuth.LoggedIn += user => EnterGame(user);
try
{
var login = await AlogameAuth.ShowLoginUI();
EnterGame(login.User);
}
catch (AlogameSdkException e)
{
Debug.Log($"Login not completed: [{e.Error.Code}] {e.Message}"); // closed, maintenance, ...
}
}
private void EnterGame(AuthUser user) { /* then report the role: see Game Role */ }
private void ReturnToTitleScreen() { /* ... */ }
}
login.User is an AuthUser (UserId, Username, DisplayName, Email,
IsPlayNow, LoginType, ...). After login, report the player's server and character:
see Game Role.
Session events
The SDK's own UI can change the session without a call from the game.
| Event | When | Game should |
|---|---|---|
AlogameAuth.SessionEnded | logout or account deletion from the SDK dashboard | leave the game, go to the title screen |
AlogameAuth.LoggedIn | the player logged in again through the SDK UI | enter the game as that user |
Both start working after the first ShowLoginUI() call. All events are raised on the main
thread.
Current session
bool loggedIn = await AlogameAuth.IsLoggedIn();
AuthUser user = await AlogameAuth.GetCurrentUser(); // null when logged out
await AlogameAuth.Logout();
AlogameAuth.LinkAloId(username, pass) attaches an Alo ID to a guest or social account without
UI.
Player identity and token
| Field | What it is |
|---|---|
UserId | The Alogame account's numeric id, as a string. Link your game account to this, and only this. It is the same userId Alogame sends your server in Web Payment — Expub. |
Token | The player's session token (JWT), valid for 30 days from login. |
Read them from the login result, the LoggedIn event, or at any time without UI:
AuthUser user = await AlogameAuth.GetCurrentUser();
string userId = user.UserId;
string token = user.Token;
When a stored session is reused after a restart, the SDK keeps the same token. Once it is rejected (expired, logged out, password changed), the SDK shows its login screen again and the new login carries a new token.
If a guest links a social account that already belongs to another Alogame account, the player
continues as that account, with its UserId. Linking a new social account or an Alo ID keeps the
guest's UserId.
Social login (Facebook / TikTok)
Google login needs no switch: Android uses Credential Manager, and iOS needs
GoogleService-Info.plist (see Installation).
Sign in with Apple is available on iOS builds.
Facebook and TikTok are off by default. To enable one, create an AlogameSDKSettings asset
(Assets → Create → Alogame → SDK Settings) under any Resources folder and fill in the
provider's ids. The build hooks then add that provider's AndroidManifest.xml and Info.plist
entries and its dependency together. A game using neither needs no asset.
The same asset holds the NSUserTrackingUsageDescription wording written into every iOS build.
Headless API
For a game that draws its own login UI, AlogameAuth also exposes Login, Register,
PlayNow, SocialLogin, Merge, MergeSocial, ForgotPassword, ChangePassword,
UpdateProfile, FetchUserInfo and the email / phone OTP calls. They map 1:1 onto the native
calls on the Android and iOS pages.