MultiConnectMultiConnectDocs Website home
MultiConnectSDK › SDK Apps

5. Players and sign-in

How player accounts work

Every player of your game is one player, with a playerId that never changes. A player can have several sign-in methods attached:

Method How the player signs in Good for
Guest Nothing: the device remembers them Playing at once
Email A six-digit code sent to their email address (no password) Any platform
Google Google Sign-In on Android Android players
Apple Sign in with Apple iOS players (the App Store asks for it when you offer other sign-ins)
Custom Your own server vouches for the player Games that keep their own login system

A player usually starts as a guest. Later they link Google, Apple or email, which keeps the same playerId and all their progress, and lets them sign in on another device.

A guest who never links a sign-in method is lost if the game is uninstalled. That's a good reason to suggest linking after the first few games.

Turn sign-in methods on

Open the app on SDK Apps and choose Sign-in and server access. Under How players sign in, turn on the methods you use, fill in what each needs (below), and choose Save. Nothing changes for players until you save: the card shows Unsaved changes until then, and Saved · live after.

Method What it needs
Guest Nothing
Email Email sender name: your game's name. Codes arrive as ": your sign-in code is …"
Google OAuth client ids, below
Sign in with Apple Bundle ids / service ids, and optionally a Sign in with Apple key, below
Custom Nothing here; see "Custom sign-in" below

Server-only save prefix (on the same card) is explained in section 9. The default is server..

Google: OAuth client ids

Why: when a player signs in with Google, Google gives your game an ID token that names the OAuth client it was issued for. MultiConnectCloud accepts the token only if that client is one of yours, so a Google sign-in made in some other app can never sign in as one of your players.

How to get them: in the Google Cloud console, choose the project your game uses for Google (the same one as its Firebase project, if it has one), then APIs & Services → Credentials. Under OAuth 2.0 Client IDs:

Where it goes: each client id, ending in .apps.googleusercontent.com, one per line in OAuth client ids. They aren't secret.

How it's used: only to check the audience of each Google ID token.

Sign in with Apple: bundle ids, and the optional key

Bundle ids / service ids

The Sign in with Apple key (optional, recommended for App Store games)

Sign in with email

Two steps: send the code, then sign in with what the player types.

Script 5.1: Email sign-in

using System.Threading.Tasks;
using MultiConnect.App;
using UnityEngine;

public static class EmailSignIn
{
    public static async Task<bool> SendCode(string email)
    {
        var sent = await McAppAuth.SendEmailCodeAsync(email);
        if (!sent.Ok) Debug.Log("Could not send the code: " + sent.Message);
        return sent.Ok;
    }

    public static async Task<bool> SignIn(string email, string code)
    {
        var result = await McAppAuth.SignInWithEmailCodeAsync(email, code);
        if (!result.Ok)
        {
            // CodeInvalid: wrong or expired code. RateLimited: too many tries.
            Debug.Log("Sign-in failed: " + result.Message);
            return false;
        }
        Debug.Log("Signed in as " + result.Value?.playerId);
        return true;
    }
}

A code is valid for 10 minutes. An address can be sent at most 3 codes in 15 minutes.

Sign in with Google or Apple

MultiConnectSDK doesn't show Google's or Apple's sign-in window. Use the sign-in plugin you already use for that platform:

  1. The plugin returns a token.
  2. Pass the token to MultiConnectSDK.
  3. MultiConnectCloud checks the token with Google or Apple before signing the player in.
Platform Token to pass Call
Google The ID token, requested for the Web client id you entered on the dashboard McAppAuth.SignInWithGoogleAsync(idToken)
Apple The identity token. Also pass the authorization code when you have one, and the name Apple gives on the first sign-in only McAppAuth.SignInWithAppleAsync(identityToken, authorizationCode, displayName)

Linking adds Google, Apple or email to the player who is signed in, usually a guest. The calls are McAppAuth.LinkGoogleAsync(idToken), McAppAuth.LinkAppleAsync(identityToken, authorizationCode), and McAppAuth.LinkEmailAsync(email, code) after SendEmailCodeAsync.

When the account already belongs to someone else. A player may already have used that Google account on another device. The link is then refused:

Ask the player whether to continue as that player. If they say yes, call McAppAuth.SwitchAccountAsync(conflict) within 10 minutes. This device then signs in as the other player. The guest's progress stays on the guest account; it isn't merged.

Script 5.2: Link Google, and offer to switch on a conflict

using System.Threading.Tasks;
using MultiConnect.App;
using UnityEngine;

public static class AccountLinking
{
    /// <param name="googleIdToken">The ID token from your Google Sign-In plugin.</param>
    public static async Task LinkGoogle(string googleIdToken)
    {
        var link = await McAppAuth.LinkGoogleAsync(googleIdToken);
        if (link.Ok)
        {
            Debug.Log("Google is linked. Progress is safe on any device.");
            return;
        }

        if (link.Error == McAppError.IdentityInUse && link.Conflict != null)
        {
            // Show "This Google account belongs to <name>. Continue as <name>?"
            bool playerSaidYes = await AskPlayer("Continue as " + link.Conflict.displayName + "?");
            if (playerSaidYes)
            {
                var switched = await McAppAuth.SwitchAccountAsync(link.Conflict);
                Debug.Log(switched.Ok ? "Now playing as " + switched.Value?.displayName : switched.Message);
            }
            return;
        }

        Debug.Log("Could not link: " + link.Message);
    }

    // Replace with your own dialog.
    private static Task<bool> AskPlayer(string question)
    {
        Debug.Log(question);
        return Task.FromResult(true);
    }
}

After a successful switch, reload anything your game shows about the player: their wallet, save and name.

Remove a method: McAppAuth.UnlinkAsync("google") (or "apple", "email"). It is refused when it would leave the player with no way to sign in.

Profile, sign-out and account deletion

Call What it does
McAppAuth.UpdateProfileAsync(displayName, avatarId) Sets the name (up to 32 characters) and your game's own avatar id
McAppAuth.GetPlayerAsync() Reads the player again, for example after a dashboard change
McAppAuth.SignOutAsync(allDevices) Signs out on this device, or on every device. A guest without a linked method can still return on this device, because it keeps its guest identity
McAppAuth.DeleteAccountAsync() Deletes the player: sign-in methods, saves, scores, wallet, inbox and push tokens. The next start on this device is a new player. The App Store and Google Play require games with accounts to offer this

McApp.Player.identities lists the linked methods. McApp.Player.HasProvider("google") tells you whether one is linked, so you can hide a "Link Google" button.

Custom sign-in

Who it's for: games that keep their own login system. Your game API checks the player in its own way, then tells MultiConnectCloud who they are.

Flow:

  1. Your game API calls McAppServer.SignInCustomAsync(subject, displayName, platform, email):
    • subject is your own user id for the player. The same subject is always the same player, and the dashboard shows it as the player's Game id.
    • displayName is the name your game shows. Pass it every time: MultiConnectCloud keeps the player's name in step with it, so the dashboard and leaderboards show the current one.
    • email is optional: the player's email in your own login, so the dashboard can show and find it.
  2. It sends the returned session token to the client.
  3. The client calls McAppAuth.UseSessionTokenAsync(token).

Between sign-ins, when a player renames or links an account in your game, your server can send the change at once with McAppServer.UpdatePlayerAsync(playerId, displayName, avatarId, email). Values left empty are not changed. When the player unlinks the account the email came from, remove it with clearEmail: true.

This needs Custom turned on and a server credential (section 6).

The Players page

On the app page, Players lists every player. Search by name, email, MultiConnectCloud player id, or, if your game uses custom sign-in, your game's own id for the player (an exact match: 2 finds only player 2). Games with custom sign-in also get a Game id column.

Opening a player shows:

It also has Ban (with a reason shown to the player, and an optional end), Sign out everywhere and Delete.

The Activity tab on a player's page is for when a player reports a problem and you need to see what happened on their device.

Part What it shows
Devices Each install the player has used: platform, app version and country, with when it was first and last seen. A device is recorded at the player's next sign-in or game launch
Activity The player's analytics events and errors together, newest first. Narrow it to events or to errors, or pick one Event. An error opens to show its Stack and the Log before the error, with Open this error to go to its group on the Errors page

Three things to know when reading it:

The same information is available from the MultiConnect CLI: multiconnect app players activity <player-id>.