Both Login() and Registration() methods perform an authorization call to the UniREST Server application before to proceed with the user login or registration. This special call has the task of verifying that the communication request comes from a Unity project and not from other applications and that the exchange of data through encryption and decryption is working correctly. Basically, this is the operation:
- the UniREST Client calls the UniREST Server;
- the UniREST Server replies with an encrypted message;
- the UniREST Client decrypts the message, modifies it and sends it back encrypted to the UniREST Server;
- the UniREST Server decrypts this last message and checks if it has been modified as expected and if this message has been received within 30 seconds;
- if everything is ok, the UniREST Server replies with a confirmation and the UniREST Client is authorized to communicate.
If something goes wrong and the authorization fails, the Login() and Registration() methods return false. However, the kind of error is tracked by a specific code available in this UniRESTClient class string property:
The ServerError property can have the following codes:
Method | Error code | Description |
Login() Registration() | NO_AUTH | The UniREST Server application has refused the communication request. |
Login() Registration() | NO_COMMUNICATION | The UniREST Server application is not reachable or properly installed. |
Login() | NO_ACCOUNT | The provided username and/or password are wrong or an account with that credentials doesn’t exist. |
Login() | NO_TOKENS | The authorization Tokens are corrupted. This error shouldn’t happen and something in the server-side is not working. |
Registration() | INVALID | The account already exists or the username and password strings don’t respect the Database limits. |
if (UniRESTClient.ServerError == "NO_AUTH")
{
Debug.Log("ERROR: you are not authorized to access to the Database.");
}
else
{
Debug.Log("OK: you can access to the Database!");
}