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:¶
-
Switching Accounts: To transition between Balancy accounts, follow these steps:
- Sign out from the current Balancy session.
- Utilize
Balancy.Auth.WithName
for re-authentication.
-
Linking New Authentication Method: Invoking
Balancy.Auth.WithName
can link a new authentication method. However, outcomes vary:- Should Balancy recognize it as a new authentication, the link is immediate.
- 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:
- The new device creates a new account
- When you do
Balancy.Auth.WithName
(non existing account), the auth method is connected to the existing account - If you launch the game on a new deviceID, the second account is created
- If you try to authenticate with the same name as in step 2 (account already exists), the conflict appears
OnSystemProfileConflictAppeared
.- If you choose
Local
, theBalancy.Auth.WithName
connects to the second deviceID and disconnects from the previous user. - 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 andOnSmartObjectsInitialized
is invoked.
- If you choose
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");
});