Class CommandLineAccessTokenProvider
An IAuthenticator implementation that expects an access token value from a provided -UNITY_CLOUD_ACCESS_TOKEN launch argument.
Inherited Members
Namespace: Unity.Cloud.Identity
Syntax
public class CommandLineAccessTokenProvider : IAuthenticator, IAccessTokenProvider, IAuthenticatedUserInfoProvider, IAuthenticationStateProvider
Examples
public class CommandLineAccessTokenProviderExample : MonoBehaviour
{
IAuthenticationStateProvider m_AuthenticationStateProvider => m_CommandLineAccessTokenProvider;
IAuthenticator m_CommandLineAccessTokenProvider;
void Awake()
{
var httpClient = new UnityHttpClient();
var playerSettings = UnityCloudPlayerSettings.Instance;
var platformSupport = PlatformSupportFactory.GetAuthenticationPlatformSupport();
var serviceHostResolver = UnityRuntimeServiceHostResolverFactory.Create();
var pkceAuthenticatorSettingsBuilder = new PkceAuthenticatorSettingsBuilder(platformSupport, serviceHostResolver);
pkceAuthenticatorSettingsBuilder.AddDefaultConfigurationProviderAndRequestHandler(httpClient, playerSettings)
.AddDefaultAccessTokenExchanger(httpClient);
m_CommandLineAccessTokenProvider = new CommandLineAccessTokenProvider(pkceAuthenticatorSettingsBuilder.Build());
m_AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
}
async Task Start()
{
await m_CommandLineAccessTokenProvider.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:
// Initial await time to retrieve the injected access token from command line
break;
case AuthenticationState.AwaitingLogin:
break;
case AuthenticationState.LoggedIn:
// The access token provided is ready to use
break;
case AuthenticationState.AwaitingLogout:
break;
case AuthenticationState.LoggedOut:
break;
}
}
}
Constructors
CommandLineAccessTokenProvider(PkceAuthenticatorSettings)
Returns an IAccessTokenProvider implementation that expects an access token value from a provided -UNITY_CLOUD_ACCESS_TOKEN launch argument.
Declaration
public CommandLineAccessTokenProvider(PkceAuthenticatorSettings pkceAuthenticatorSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| PkceAuthenticatorSettings | pkceAuthenticatorSettings | The PkceAuthenticatorSettings that handles user information and token. |
Fields
s_AccessTokenKeyName
Returns the expected key name in launch arguments that holds the access token value.
Declaration
public static readonly string s_AccessTokenKeyName
Field Value
| Type | Description |
|---|---|
| String |
Properties
AuthenticationState
Holds the current AuthenticationState.
Declaration
public AuthenticationState AuthenticationState { get; }
Property Value
| Type | Description |
|---|---|
| AuthenticationState |
Implements
Methods
GetAccessTokenAsync()
Declaration
public Task<string> GetAccessTokenAsync()
Returns
| Type | Description |
|---|---|
| Task<String> |
Implements
GetUserInfo(String)
Declaration
public string GetUserInfo(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| String | key |
Returns
| Type | Description |
|---|---|
| String |
Implements
HasValidPreconditionsAsync()
Indicates if the CommandLineAccessTokenProvider running instance has detected command line injection of an access token.
Declaration
public Task<bool> HasValidPreconditionsAsync()
Returns
| Type | Description |
|---|---|
| Task<Boolean> | If the CommandLineAccessTokenProvider running instance has detected command line injection of an access token. |
Implements
InitializeAsync()
A task to initialize the AuthenticationState from either cache or direct injection value.
Declaration
public async Task InitializeAsync()
Returns
| Type | Description |
|---|---|
| Task |
Implements
Events
AuthenticationStateChanged
Triggers when the AuthenticationState of the current user changes.
Declaration
public event Action<AuthenticationState> AuthenticationStateChanged
Event Type
| Type | Description |
|---|---|
| Action<AuthenticationState> |
Implements
Remarks
Subscribers of this event should restrict or allow access to available resources and features based on the returned value.