Players and sign-in
Guest accounts that survive restarts, display names, and linking guests to email or Google.
Guest sign-in#
Call this once at startup. It restores the stored session (refreshing it when needed) or creates a new guest, so the same player keeps their progress.
var signIn = await Majacloud.Auth.SignInAnonymouslyAsync();
if (signIn.Ok)
{
var player = signIn.Value;
Debug.Log(player.PlayerId + " " + player.DisplayName + " guest: " + player.IsGuest);
}var signed_in := await Majacloud.auth.sign_in_anonymously()
if signed_in.ok:
var player: Dictionary = signed_in.value
print(player.player_id, " ", player.display_name, " ", player.auth_type)const signIn = await mc.auth.signInAnonymously();
if (signIn.ok) {
const player = signIn.value;
console.log(player.player_id, player.display_name, player.auth_type);
}curl -X POST https://majacloud.majanite.com/v1/auth/guest -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"device_id": "install-7f2c"}'
# Before the access token expires (1 hour), rotate the session:
curl -X POST https://majacloud.majanite.com/v1/auth/refresh -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"refresh_token": "<refresh_token>"}'Display names#
Guests get a generated name such as Guest 4821. Players can choose their own; leaderboards show it.
var renamed = await Majacloud.Auth.SetDisplayNameAsync("Nova");
if (!renamed.Ok) Debug.Log(renamed.Error.Message); // e.g. Validation: too longvar renamed := await Majacloud.auth.set_display_name("Nova")
if not renamed.ok:
print(renamed.message) # e.g. validation: too longconst renamed = await mc.auth.setDisplayName('Nova');
if (!renamed.ok) console.log(renamed.error.message); // e.g. validation: too longcurl -X PATCH https://majacloud.majanite.com/v1/players/me -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"display_name": "Nova"}'Link to email or Google#
Linking opens a secure web page on your MAJACLOUD server where the player signs in or registers with email and password or Google. The guest's progress (scores, saves, wallet) moves to that account, and the game receives the new session — on any device.
// Opens the sign-in page, waits for the player, then switches the session
var linked = await Majacloud.Auth.LinkAccountAsync(new MajacloudLinkOptions { ReturnUrl = "mygame://auth" });
if (linked.Ok) Debug.Log("Signed in as " + linked.Value.DisplayName);
// WebGL: browsers only open tabs from a click, so start first and open inside the handler
var flow = await Majacloud.Auth.StartLinkAsync(new MajacloudLinkOptions { OpenBrowser = false });
linkButton.onClick.AddListener(() => flow.Value.OpenInBrowser());
var result = await flow.Value.WaitForCompletionAsync();# Opens the sign-in page, waits for the player, then switches the session
var linked := await Majacloud.auth.link_account("mygame://auth")
if linked.ok:
print("Signed in as ", linked.value.display_name)
# Or step by step (e.g. to open the page from a button)
var started := await Majacloud.auth.start_link()
var flow: MajacloudLinkFlow = started.value
flow.open_in_browser()
var result := await flow.wait_for_completion()// Call it from a click handler: the browser only allows the new tab after a user gesture
document.querySelector('#link').addEventListener('click', async () => {
const linked = await mc.auth.linkAccount();
if (linked.ok) console.log('Signed in as ' + linked.value.display_name);
});# 1. Start (send the guest's Bearer token so its progress is merged)
curl -X POST https://majacloud.majanite.com/v1/auth/link/start -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" -d '{"code_challenge": "<base64url(sha256(verifier))>", "code_challenge_method": "S256"}'
# 2. Open auth_url for the player, then poll until status is "completed"
curl "https://majacloud.majanite.com/v1/auth/link/status?flow_id=<flow_id>&flow_token=<flow_token>" -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY"
# 3. Exchange for the new session
curl -X POST https://majacloud.majanite.com/v1/auth/link/exchange -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"flow_id": "<flow_id>", "exchange_code": "<exchange_code>", "code_verifier": "<verifier>"}'How linking works#
- The SDK creates a one-time secret (PKCE) and starts a sign-in flow.
- The player finishes on the web page; the SDK polls until the flow completes.
- The SDK exchanges the flow for a session using the secret, so a stolen link is useless.
- Flows expire after 15 minutes (extended while the page is open).
Returning to the game#
Without a return URL the page tells players to go back to the game. To send them back automatically, add your custom URL scheme (for example mygame) under API keys ▸ Player sign-in return URLs and pass mygame://auth as the return URL.
Events#
React when the player changes, signs out or when the session can no longer be refreshed:
Majacloud.Auth.PlayerChanged += player => nameLabel.text = player?.DisplayName;
Majacloud.Auth.SignedOut += () => ShowTitleScreen();
Majacloud.Auth.SessionExpired += () => ShowSignIn();Majacloud.auth.player_changed.connect(func(player): $NameLabel.text = player.get("display_name", ""))
Majacloud.auth.signed_out.connect(show_title_screen)
Majacloud.auth.session_expired.connect(show_sign_in)mc.auth.on('playerChanged', (player) => render(player));
mc.auth.on('signedOut', () => showTitleScreen());
mc.auth.on('sessionExpired', () => showSignIn());Sign out#
Signing out revokes the session on the server and forgets it on the device. The next sign-in creates a new guest.
await Majacloud.Auth.SignOutAsync(); // revokes the session on the server
Majacloud.Auth.ClearLocalSession(); // or only forget it on this deviceawait Majacloud.auth.sign_out() # revokes the session on the server
Majacloud.auth.clear_local_session() # or only forget it on this deviceawait mc.auth.signOut(); // revokes the session on the server
mc.auth.clearLocalSession(); // or only forget it on this devicecurl -X POST https://majacloud.majanite.com/v1/auth/logout -H "X-Project-ID: $PROJECT_ID" -H "X-Client-Key: $CLIENT_KEY" \
-H "Content-Type: application/json" -d '{"refresh_token": "<refresh_token>"}'Read players from your server#
With the secret key your server can read any player, including email and wallet balances:
// Node.js, created with secretKey
const found = await admin.server.getPlayer('player_3f9c…');
if (found.ok) console.log(found.value.player.email, found.value.player.wallets);curl https://majacloud.majanite.com/v1/players/player_3f9c… \
-H "X-Project-ID: $PROJECT_ID" -H "X-Secret-Key: $SECRET_KEY"In the dashboard#
The Players page lists every player with their sign-in method, scores, saves and wallet. From there you can rename or disable a player, sign them out everywhere, send a password reset link or delete them.