Interface IAuthenticationStateProvider
An interface that manages the application authentication state.
Namespace: Unity.Cloud.Identity
Assembly: Unity.Cloud.Identity.dll
Syntax
public interface IAuthenticationStateProvider
Properties
AuthenticationState
Holds the current AuthenticationState
.
Declaration
AuthenticationState AuthenticationState { get; }
Property Value
Type | Description |
---|---|
AuthenticationState |
Events
AuthenticationStateChanged
Triggers when the AuthenticationState of the current user changes.
Declaration
event Action<AuthenticationState> AuthenticationStateChanged
Event Type
Type | Description |
---|---|
Action<AuthenticationState> |
Remarks
Subscribers of this event should restrict or allow access to available resources and features based on the returned value.
Examples
public class AuthenticationStateProviderExample : MonoBehaviour
{
IAuthenticationStateProvider m_AuthenticationStateProvider => m_CompositeAuthenticator;
CompositeAuthenticator m_CompositeAuthenticator;
void Awake()
{
var playerSettings = UnityCloudPlayerSettings.Instance;
var httpClient = new UnityHttpClient();
var serviceHostResolver = UnityRuntimeServiceHostResolverFactory.Create();
var compositeAuthenticatorSettings = new CompositeAuthenticatorSettingsBuilder(httpClient, PlatformSupportFactory.GetAuthenticationPlatformSupport(), serviceHostResolver, playerSettings)
.AddDefaultBrowserAuthenticatedAccessTokenProvider(playerSettings)
.AddDefaultPkceAuthenticator(playerSettings)
.Build();
m_CompositeAuthenticator = new CompositeAuthenticator(compositeAuthenticatorSettings);
m_AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
}
async Task Start()
{
await m_CompositeAuthenticator.InitializeAsync();
// After initialize, Update UI with current state
ApplyAuthenticationState(m_AuthenticationStateProvider.AuthenticationState);
}
void OnDisable()
{
m_AuthenticationStateProvider.AuthenticationStateChanged -= OnAuthenticationStateChanged;
}
void OnAuthenticationStateChanged(AuthenticationState state)
{
ApplyAuthenticationState(state);
}
void ApplyAuthenticationState(AuthenticationState newAuthenticationState)
{
switch (newAuthenticationState)
{
case AuthenticationState.AwaitingInitialization:
break;
case AuthenticationState.AwaitingLogin:
break;
case AuthenticationState.LoggedIn:
break;
case AuthenticationState.AwaitingLogout:
break;
case AuthenticationState.LoggedOut:
break;
}
}
}