Authentication
Integration Guide
After Initializing the RGN 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 RGN SDK. The
RGNCore.I.AuthenticationChanged
event 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(
EnumLoginState enumLoginState,
EnumLoginError error)
{
switch (enumLoginState)
{
case EnumLoginState.Error:
Debug.LogError("On Auth error: " + enumLoginState +
", error: " + error);
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" +
"Short UID :" + userProfileData.shortUID + "\n");
// TODO: Load other data from here
break;
case EnumLoginState.NotLoggedIn:
Debug.Log("User is not logged in");
GuestSignInModule.I.TryToSignIn();
break;
default:
Debug.LogError("Unhandled Login State: " + enumLoginState);
break;
}
}
}
}
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();
}
}
}
using RGN.Modules.SignIn;
namespace SomeNamespace
{
internal sealed class GuestLoginLogout
{
public void GuestLogin()
{
GuestSignInModule.I.TryToSignIn();
}
public void GuestLogout()
{
GuestSignInModule.I.SignOut();
}
}
}