Authentication

Integration Guide

Subscribe Authentication Changed event

After Initializing the READYgg SDK, subscribe to the RGNCore.I.AuthenticationChanged event, to handle authentication and get the user's data.

On SignIn with any Auth Provider, credentials are stored in Keystore(Android) & Keychain(IOS) files.

You can use also the RGNUnityInitilizer component to initialize the READYgg SDK. The RGNCore.I.AuthenticationChangedevent is handled in the RGNUnityInitilizer component. When the user logs out from any provider, he automatically is logged in with Guest provider. It is made to store the user progress and make sure the user can switch to email later and keep the progress.

using RGN;
using RGN.Modules.GameProgress;
using RGN.Modules.SignIn;
using RGN.Modules.UserProfile;
using UnityEngine;

namespace SomeNamespace
{
    internal sealed class SomeMonoBehaviour : MonoBehaviour
    {
        private void OnEnable()
        {
            RGNCore.I.AuthenticationChanged += OnAuthenticationChangedAsync;
        }
        private void OnDisable()
        {
            RGNCore.I.AuthenticationChanged -= OnAuthenticationChangedAsync;
        }

        private async void OnAuthenticationChangedAsync(AuthState authState)
        {
            switch (authState.LoginState)
            {
                case EnumLoginState.Error:
                    Debug.LogError("On Auth error: " + authState.LoginState +
                        ", error: " + authState.LoginResult);
                    break;
                case EnumLoginState.Success:
                    var userProfileData =
                        await UserProfileModule.I.
                            GetFullUserProfileAsync<GameUserFullProfileData>(
                                RGNCore.I.MasterAppUser.UserId);
                    Debug.Log("User logged in \n" +
                             "UserId :" + userProfileData.userId + "\n" +
                             "Display Name :" + userProfileData.displayName + "\n");
                    // TODO: Load other data from here
                    break;
                case EnumLoginState.NotLoggedIn:
                    Debug.Log("User is not logged in");
                    // TODO: uncomment if needed:
                    // GuestSignInModule.I.TryToSignInAsync();
                    break;
                default:
                    Debug.LogError("Unhandled Login State: " + authState.LoginState);
                    break;
            }
        }
    }
}

Email Login/Logout

using RGN.Modules.SignIn;

namespace SomeNamespace
{
    internal sealed class EmailLoginLogout
    {
        public void EmailSignIn()
        {
            // This call will open a web form
            // Handle the result in RGNCore.I.AuthenticationChanged event callback
            EmailSignInModule.I.TryToSignIn();
        }
        public void EmailSignOut()
        {
            EmailSignInModule.I.SignOut();
        }
    }
}

Guest Login/Logout

using RGN.Modules.SignIn;

namespace SomeNamespace
{
    internal sealed class GuestLoginLogout
    {
        public void GuestLogin()
        {
            GuestSignInModule.I.TryToSignInAsync();
        }
        public void GuestLogout()
        {
            GuestSignInModule.I.SignOut();
        }
    }
}

Last updated