Links

Login

This login flow is meant for Standalone, iOS and Android builds and will not work with WebGL, because WebGL builds do not support deep linking and launching a loopback service

Setup

In order to implement "Login with Colizeum" functionality, you must have already setup the App ID and OAuth Client ID in Colizeum Settings window.
The process for authenticating users uses different callback types, depending on the platform you're building for.

Deep Linking

With deep linking enabled, the user will be automatically returned back to the game after successful authentication. Within Colizeum settings, you need to provide the custom URL scheme you've chosen for you application. It's best practise to choose a scheme which follows the reverse domain name notion
com.colizeum.royal-aces
More information on deep linking is available in the Unity documentation: https://docs.unity.cn/2021.3/Documentation/Manual/deep-linking.html

Loopback service

With loopback service enabled, the Colizeum SDK will start a small HTTP web server in the background on the port 50100. This will serve as the redirect URI for the OAuth flow and after successful authentication the user will be met with a page instructing to manually switch back to the game.

Redirect

With the redirect callback enabled, the user will be redirected to the URI you provided in Colizeum Settings with the authentication code provided in the query parameters.

Implementation

In order to start the login flow, you must simply call the Colizeum.Auth.Login() method and pass a callback which will be called after the user successfully authenticates.
public TMP_Text userText;
public TMP_Text energyText;
public void Login()
{
Colizeum.Auth.Login(user =>
{
userText.text = $"Hello {user.username}";
energyText.text = $"Energy: {user.energy.current}";
});
}
After a successful login, the a user model will be created which is accessible using Colizeum.User
private void Start()
{
var username = Colizeum.User.username;
Debug.Log(username)
}

Checking if user is logged in

In simple uses cases, you don't have to manually check if the user is logged in as you can simply call the Colizeum.Auth.Login() method every time you start the game, and it will fetch the latest user information right away if the user has already completed the authentication flow.
If you do need a more advanced solution, like for example you don't want to launch the full authentication flow at the start of the game in case the user is not logged in, but at the same time you want to fetch the latest information in case he is logged in, then you can simply check if Colizeum.IsLoggedIn is set to true
// Called when the game launches
private void Awake()
{
// If the user is not logged in, don't do nothing
if (!Colizeum.IsLoggedIn) {
return;
}
// If he is logged in, fetch the latest information about him
Colizeum.Auth.Login();
}
// Called on a button press
private void Login()
{
Colizeum.Auth.Login();
}

Logging out

In order to log out the user and revoke all his tokens, you must simply call the Colizeum.Auth.Logout() method

Session Expired

Sessions can expire when it's not possible to refresh the access token anymore. Checkout out Tokens to see how to deal with that