1. Home
  2. Docs
  3. UniREST Solution 3.5
  4. UniREST Client
  5. Token Manager
  6. Tokens Check

Tokens Check

The Update*() methods just change the Tokens and these new Tokens have no real effect on the UniREST System. Using the Check*() methods, you can confront the Token stored in the UniRESTClient class and the Token stored in the database users table, so as to check if they’re equal or different.


Example scenario

A user is using two mobile devices to play the same Unity game, with the same credentials.
When the user logins the game with device A, a set of Tokens are generated.
Then, when the user logins the game with device B, a new set of Tokens is generated again.
However, Tokens have no effect in the UniREST System, so there’s nothing that can block the user from login into the 2 devices.

Now, instead, we place a Login Token check in various, strategic points of the Unity game. This check has the aim to control when needed that the client Login Token and the server Login Token are the same. If they’re different, the user is logged out with an alert of a security violation.

What happens now?

The user logins the game with device A. Then, the user logins with device B. The login with device B changes the Token previously generated by device A. Now, the user does something in device A, the Login Token check is performed and the security violation happens. This is because the Login Token stored in device A is different from the Login Token of the database, which now belongs to device B.


CheckLogin(), CheckRead(), CheckWrite()

The Check*() methods check if the Token into the UniRESTClient class is equal to the Token saved into the database users table. These methods allow you to perform various security checks and implement a custom security system based on Tokens.

_ = #UniRESTClient#.#Async#.#TokenManager#.$CheckLogin$(%callBack%);

_ = #UniRESTClient#.#Async#.#TokenManager#.$CheckRead$(%callBack%);

_ = #UniRESTClient#.#Async#.#TokenManager#.$CheckWrite$(%callBack%);

doneCallback|function(bool)
The function to call when the operation will be completed.

It must have a bool parameter, that will be true if the client and server Tokens match, or false otherwise.

_ = UniRESTClient.Async.TokenManager.CheckLogin(
    (bool ok) => 
    {
          if (ok)
          {
              Debug.Log("This login session is valid!");  
          } else {
              Debug.LogError("This login session is not valid!");
          }
    });