Class ServiceAccountAuthenticator
An IAuthenticator implementation that supports service account.
Implements
Inherited Members
Namespace: Unity.Cloud.Identity
Assembly: Unity.Cloud.Identity.dll
Syntax
public class ServiceAccountAuthenticator : IAuthenticator, IServiceAuthorizer, IAuthenticationStateProvider, IUserInfoProvider, IOrganizationRepository
Constructors
ServiceAccountAuthenticator(ServiceAccountAuthenticatorSettings)
Provides a ServiceAccountAuthenticator that accepts a ServiceAccountAuthenticatorSettings to handle authentication with service account credentials.
Declaration
public ServiceAccountAuthenticator(ServiceAccountAuthenticatorSettings serviceAccountAuthenticatorSettings)
Parameters
| Type | Name | Description |
|---|---|---|
| ServiceAccountAuthenticatorSettings | serviceAccountAuthenticatorSettings | A ServiceAccountAuthenticatorSettings that contains the parameters required for constructing the authenticator. |
Properties
AuthenticationState
Holds the current AuthenticationState.
Declaration
public AuthenticationState AuthenticationState { get; }
Property Value
| Type | Description |
|---|---|
| AuthenticationState |
Methods
AddAuthorization(HttpHeaders)
Declaration
public Task AddAuthorization(HttpHeaders headers)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpHeaders | headers |
Returns
| Type | Description |
|---|---|
| Task |
GetOrganizationAsync(OrganizationId)
Gets a single IOrganization.
Declaration
public Task<IOrganization> GetOrganizationAsync(OrganizationId organizationId)
Parameters
| Type | Name | Description |
|---|---|---|
| OrganizationId | organizationId | The OrganizationId of the IOrganization to get. |
Returns
| Type | Description |
|---|---|
| Task<IOrganization> | A task that once completed returns an IOrganization. |
Exceptions
| Type | Condition |
|---|---|
| NotFoundException |
GetUserInfoAsync()
A task to fetch asynchronously user information.
Declaration
public Task<IUserInfo> GetUserInfoAsync()
Returns
| Type | Description |
|---|---|
| Task<IUserInfo> | An IUserInfo instance. |
HasValidPreconditionsAsync()
Indicates if the IAuthenticator has valid preconditions to provide authentication in the current execution context.
Declaration
public Task<bool> HasValidPreconditionsAsync()
Returns
| Type | Description |
|---|---|
| Task<bool> | A task that when completed indicates if the |
InitializeAsync()
A task to initialize the AuthenticationState from either cache or direct injection value.
Declaration
public Task InitializeAsync()
Returns
| Type | Description |
|---|---|
| Task | A task. |
ListOrganizationsAsync(Range, CancellationToken)
Lists IOrganization.
Declaration
public IAsyncEnumerable<IOrganization> ListOrganizationsAsync(Range range, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| Range | range | A range of IOrganization to request. |
| CancellationToken | cancellationToken | The cancellation token. |
Returns
| Type | Description |
|---|---|
| IAsyncEnumerable<IOrganization> | An IAsyncEnumerable<T> of Type IOrganization. |
Events
AuthenticationStateChanged
Triggers when the AuthenticationState of the current user changes.
Declaration
public 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;
}
}
}