Skip to content

Authorization

Balancy's authentication methods are subject to updates to enhance versatility and, for certain platforms, processes may be automated for convenience.

Understanding Authentication

Balancy initializes with automatic user authentication via the device's unique ID, associating it with a guest account. This mechanism ensures persistent user progress, even across reinstallations, provided the device ID remains consistent.

Users have the option for further authentication methods, such as email or social media platforms, typically managed through FireBase. Post-authentication, these accounts can synchronize with Balancy using Balancy.Auth.WithName.

Authentication Scenarios:

  1. Switching Accounts: To transition between Balancy accounts, follow these steps:

    1. Sign out from the current Balancy session.
    2. Utilize Balancy.Auth.WithName for re-authentication.
  2. Linking New Authentication Method: Invoking Balancy.Auth.WithName can link a new authentication method. However, outcomes vary:

    1. Should Balancy recognize it as a new authentication, the link is immediate.
    2. If another user is already linked to this authentication, a conflict arises. You must then choose between the local profile or the one on Balancy's servers. Selection dictates whether the new method replaces the current link or if the local account updates to match the server's data.

An example of the flow if the same account is playing on two devices:

  1. The new device creates a new account
  2. When you do Balancy.Auth.WithName (non existing account), the auth method is connected to the existing account
  3. If you launch the game on a new deviceID, the second account is created
  4. If you try to authenticate with the same name as in step 2 (account already exists), the conflict appears OnSystemProfileConflictAppeared.
    1. If you choose Local, the Balancy.Auth.WithName connects to the second deviceID and disconnects from the previous user.
    2. If you choose Cloud, this deviceID connects to the first account and disconnects from the second account (the second account will be lost, if there is no other authentication). The game is reloaded with the first account and OnSmartObjectsInitialized is invoked.

Authorization Methods:

Name and Password

Balancy.Auth.WithName(<username>, <password>, authResponse =>
{
    Debug.Log("Authorized " + authResponse.Success);
    if (authResponse.Success)
        Debug.Log("User id: " + authResponse.UserId);
});

As a Guest using the Device ID

Balancy.Auth.AsGuest(authResponse =>
{
    Debug.Log("Authorized " + authResponse.Success);
    if (authResponse.Success)
        Debug.Log("User id: " + authResponse.UserId);
});

Additional Methods

var balancyUserId = Balancy.Auth.GetUserId();
var isAuthorized = Balancy.Auth.IsAuthorized();

Balancy.Auth.SignOut(<game_id>, <environment>, () => {
    Debug.Log("Signed Out");
});