Class PersonalAccessTokenProvider
An IAuthenticator implementation that expects a personal access token (PAT) from a provided -DT_PERSONAL_ACCESS_TOKEN launch argument or a DT_PERSONAL_ACCESS_TOKEN environment variable.
Inherited Members
Namespace: Unity.Cloud.Identity
Syntax
public class PersonalAccessTokenProvider : IAuthenticator, IAccessTokenProvider, IAuthenticatedUserInfoProvider, IAuthenticationStateProvider
Examples
public class PersonalAccessTokenProviderExample : MonoBehaviour
{
IAuthenticationStateProvider m_AuthenticationStateProvider => m_PersonalAccessTokenProvider;
IAuthenticator m_PersonalAccessTokenProvider;
void Awake()
{
var authenticationPlatformSupport = PlatformSupportFactory.GetAuthenticationPlatformSupport();
m_PersonalAccessTokenProvider = new PersonalAccessTokenProvider(authenticationPlatformSupport);
m_AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
}
async Task Start()
{
await m_PersonalAccessTokenProvider.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 personal access token
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
PersonalAccessTokenProvider(IAuthenticationPlatformSupport)
Returns an IAccessTokenProvider implementation that expects a personal access token (PAT) from a provided -UNITY_CLOUD_PERSONAL_ACCESS_TOKEN launch argument or a UNITY_CLOUD_PERSONAL_ACCESS_TOKEN environment variable.
Declaration
public PersonalAccessTokenProvider(IAuthenticationPlatformSupport authenticationPlatformSupport)
Parameters
| Type | Name | Description |
|---|---|---|
| IAuthenticationPlatformSupport | authenticationPlatformSupport | The IAuthenticationPlatformSupport that handles PAT injection. |
Remarks
A Unity user account is required to generate a valid PAT from the Unity Cloud online dashboard.
Fields
s_PersonalAccessTokenKeyName
Returns the expected key name in launch arguments that holds the personal access token value.
Declaration
public static readonly string s_PersonalAccessTokenKeyName
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 PersonalAccessTokenProvider running instance has detected injection of a personal access token.
Declaration
public Task<bool> HasValidPreconditionsAsync()
Returns
| Type | Description |
|---|---|
| Task<Boolean> | If the PersonalAccessTokenProvider running instance has detected injection of a personal access token. |
Implements
InitializeAsync()
A task to initialize the AuthenticationState from either cache or direct injection value.
Declaration
public 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.