docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class UnityEditorAuthenticator

    An IAuthenticator implementation to access the user authenticated session in the Unity Editor.

    Inheritance
    object
    UnityEditorAuthenticator
    Implements
    IAuthenticator
    IServiceAuthorizer
    IAuthenticationStateProvider
    IUserInfoProvider
    IOrganizationRepository
    IDisposable
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: Unity.Cloud.Identity.Editor
    Assembly: Unity.Cloud.Identity.Editor.dll
    Syntax
    public class UnityEditorAuthenticator : IAuthenticator, IServiceAuthorizer, IAuthenticationStateProvider, IUserInfoProvider, IOrganizationRepository, IDisposable

    Constructors

    UnityEditorAuthenticator()

    Returns an IAuthenticator implementation that expects an access token from a Unity Editor environment.

    Declaration
    public UnityEditorAuthenticator()

    UnityEditorAuthenticator(IAccessTokenExchanger<TargetClientIdToken, UnityServicesToken>)

    Returns an IAuthenticator implementation that expects an access token from a Unity Editor environment.

    Declaration
    public UnityEditorAuthenticator(IAccessTokenExchanger<TargetClientIdToken, UnityServicesToken> accessTokenExchanger)
    Parameters
    Type Name Description
    IAccessTokenExchanger<TargetClientIdToken, UnityServicesToken> accessTokenExchanger

    An IAccessTokenExchanger<T1, T2> where the T1 input is a TargetClientIdToken and T2 output is a UnityServicesToken

    UnityEditorAuthenticator(IAccessTokenExchanger<TargetClientIdToken, UnityServicesToken>, IUnityEditorAccessTokenProvider)

    Returns an IAuthenticator implementation that expects an access token from a Unity Editor environment.

    Declaration
    public UnityEditorAuthenticator(IAccessTokenExchanger<TargetClientIdToken, UnityServicesToken> accessTokenExchanger, IUnityEditorAccessTokenProvider unityEditorAccessTokenProvider)
    Parameters
    Type Name Description
    IAccessTokenExchanger<TargetClientIdToken, UnityServicesToken> accessTokenExchanger

    An IAccessTokenExchanger<T1, T2> where the T1 input is a TargetClientIdToken and T2 output is a UnityServicesToken

    IUnityEditorAccessTokenProvider unityEditorAccessTokenProvider

    An IUnityEditorAccessTokenProvider reference.

    Properties

    AuthenticationState

    Holds the current AuthenticationState.

    Declaration
    public AuthenticationState AuthenticationState { get; }
    Property Value
    Type Description
    AuthenticationState

    Methods

    AddAuthorization(HttpHeaders)

    Applies authorization information to a given set of HttpHeaders.

    Declaration
    public Task AddAuthorization(HttpHeaders headers)
    Parameters
    Type Name Description
    HttpHeaders headers

    The HttpHeaders to add authorization information to.

    Returns
    Type Description
    Task

    A Task for the operation.

    Exceptions
    Type Condition
    ArgumentNullException

    Thrown if headers is null.

    Dispose()

    Disposes of any IDisposable references.

    Declaration
    public void Dispose()

    Dispose(bool)

    Disposes of any IDisposable references.

    Declaration
    protected virtual void Dispose(bool disposing)
    Parameters
    Type Name Description
    bool disposing

    Dispose pattern boolean value received from public Dispose method.

    GetOrganizationAsync(OrganizationId)

    Gets a single IOrganization.

    Declaration
    public Task<IOrganization> GetOrganizationAsync(OrganizationId organizationId)
    Parameters
    Type Name Description
    OrganizationId organizationId

    The Unity.Cloud.Common.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 UnityEditorAuthenticator running instance has access to an access token from the Unity Editor environment.

    Declaration
    public Task<bool> HasValidPreconditionsAsync()
    Returns
    Type Description
    Task<bool>

    If the UnityEditorAuthenticator running instance has access to an access token from the Unity Editor environment.

    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;
                                   }
                               }
                           }
    

    Implements

    IAuthenticator
    Unity.Cloud.Common.IServiceAuthorizer
    IAuthenticationStateProvider
    IUserInfoProvider
    IOrganizationRepository
    IDisposable
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)