docs.unity3d.com
    Show / Hide Table of Contents

    Interface IAuthenticationService

    The functions for Authentication service.

    Namespace: Unity.Services.Authentication
    Syntax
    public interface IAuthenticationService

    Properties

    AccessToken

    Returns the current player's access token when they are signed in, otherwise null.

    Declaration
    string AccessToken { get; }
    Property Value
    Type Description
    String

    IsAuthorized

    Checks whether the player is still authorized. A player is authorized as long as his access token remains valid.

    Declaration
    bool IsAuthorized { get; }
    Property Value
    Type Description
    Boolean

    Returns true if player is authorized, else false.

    IsExpired

    Checks whether the player session is expired.

    Declaration
    bool IsExpired { get; }
    Property Value
    Type Description
    Boolean

    Returns true if player's session expired.

    IsSignedIn

    Checks whether the player is signed in or not. A player can remain signed in but have an expired session.

    Declaration
    bool IsSignedIn { get; }
    Property Value
    Type Description
    Boolean

    Returns true if player is signed in, else false.

    PlayerId

    Returns the current player's ID when they are signed in, otherwise null.

    Declaration
    string PlayerId { get; }
    Property Value
    Type Description
    String

    PlayerInfo

    Returns the current player's info, including linked identities.

    Declaration
    PlayerInfo PlayerInfo { get; }
    Property Value
    Type Description
    PlayerInfo

    Profile

    The profile isolates the values saved to the PlayerPrefs. You can use profiles to sign in to multiple accounts on a single device. Use the SwitchProfile(String) method to change this value.

    Declaration
    string Profile { get; }
    Property Value
    Type Description
    String

    SessionTokenExists

    Check if there is an existing session token stored for the current profile.

    Declaration
    bool SessionTokenExists { get; }
    Property Value
    Type Description
    Boolean

    Methods

    ClearSessionToken()

    Deletes the session token if it exists.

    Declaration
    void ClearSessionToken()
    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player is not signed out.

    DeleteAccountAsync()

    Deletes the currently signed in player permanently.

    Declaration
    Task DeleteAccountAsync()
    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player is not authorized to perform this operation.

    GetPlayerInfoAsync()

    Returns the info of the logged in player, which includes the player's id, creation time and linked identities.

    Declaration
    Task<PlayerInfo> GetPlayerInfoAsync()
    Returns
    Type Description
    Task<PlayerInfo>

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player is not authorized to perform this operation.

    LinkWithAppleAsync(String, LinkOptions)

    Link the current player with the Apple account using Apple's ID token.

    Declaration
    Task LinkWithAppleAsync(string idToken, LinkOptions options = null)
    Parameters
    Type Name Description
    String idToken

    Apple's ID token

    LinkOptions options

    Options for the link operations.

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode AccountAlreadyLinked if the player tries to link a social account while the social account is already linked with another player.
    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player is not authorized to perform this operation.
    • Throws with ErrorCode AccountLinkLimitExceeded if the player has already reached the limit of links for this provider type.

    LinkWithFacebookAsync(String, LinkOptions)

    Link the current player with the Facebook account using Facebook's access token.

    Declaration
    Task LinkWithFacebookAsync(string accessToken, LinkOptions options = null)
    Parameters
    Type Name Description
    String accessToken

    Facebook's access token

    LinkOptions options

    Options for the link operations.

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode AccountAlreadyLinked if the player tries to link a social account while the social account is already linked with another player.
    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player is not authorized to perform this operation.
    • Throws with ErrorCode AccountLinkLimitExceeded if the player has already reached the limit of links for this provider type.

    LinkWithGoogleAsync(String, LinkOptions)

    Link the current player with the Google account using Google's ID token.

    Declaration
    Task LinkWithGoogleAsync(string idToken, LinkOptions options = null)
    Parameters
    Type Name Description
    String idToken

    Google's ID token

    LinkOptions options

    Options for the link operations.

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode AccountAlreadyLinked if the player tries to link a social account while the social account is already linked with another player.
    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player is not authorized to perform this operation.
    • Throws with ErrorCode AccountLinkLimitExceeded if the player has already reached the limit of links for this provider type.

    LinkWithSteamAsync(String, LinkOptions)

    Link the current player with the Steam account using Steam's session ticket.

    Declaration
    Task LinkWithSteamAsync(string sessionTicket, LinkOptions options = null)
    Parameters
    Type Name Description
    String sessionTicket

    Steam's session ticket

    LinkOptions options

    Options for the link operations.

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode AccountAlreadyLinked if the player tries to link a social account while the social account is already linked with another player.
    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player is not authorized to perform this operation.
    • Throws with ErrorCode AccountLinkLimitExceeded if the player has already reached the limit of links for this provider type.

    SignInAnonymouslyAsync(SignInOptions)

    Signs in the current player anonymously. No credentials are required and the session is confined to the current device.

    Declaration
    Task SignInAnonymouslyAsync(SignInOptions options = null)
    Parameters
    Type Name Description
    SignInOptions options

    Options for the operation

    Returns
    Type Description
    Task

    Task for the operation

    Remarks

    If a player has signed in previously with a session token stored on the device, they are signed back in regardless of if they're an anonymous player or not.

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player has already signed in or a sign-in operation is in progress.

    SignInWithAppleAsync(String, SignInOptions)

    Sign in using Apple's ID token. If no options are used, this will create an account if none exist.

    Declaration
    Task SignInWithAppleAsync(string idToken, SignInOptions options = null)
    Parameters
    Type Name Description
    String idToken

    Apple's ID token

    SignInOptions options

    Options for the operation

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player has already signed in or a sign-in operation is in progress.

    SignInWithFacebookAsync(String, SignInOptions)

    Sign in using Facebook's access token. If no options are used, this will create an account if none exist.

    Declaration
    Task SignInWithFacebookAsync(string accessToken, SignInOptions options = null)
    Parameters
    Type Name Description
    String accessToken

    Facebook's access token

    SignInOptions options

    Options for the operation

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player has already signed in or a sign-in operation is in progress.

    SignInWithGoogleAsync(String, SignInOptions)

    Sign in using Google's ID token. If no options are used, this will create an account if none exist.

    Declaration
    Task SignInWithGoogleAsync(string idToken, SignInOptions options = null)
    Parameters
    Type Name Description
    String idToken

    Google's ID token

    SignInOptions options

    Options for the operation

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player has already signed in or a sign-in operation is in progress.

    SignInWithSteamAsync(String, SignInOptions)

    Sign in using Steam's session ticket. If no options are used, this will create an account if none exist.

    Declaration
    Task SignInWithSteamAsync(string sessionTicket, SignInOptions options = null)
    Parameters
    Type Name Description
    String sessionTicket

    Steam's session ticket

    SignInOptions options

    Options for the operation

    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode InvalidParameters if parameter is empty or invalid.
    • Throws with ErrorCode ClientInvalidUserState if the player has already signed in or a sign-in operation is in progress.

    SignOut(Boolean)

    Sign out the current player.

    Declaration
    void SignOut(bool clearCredentials = false)
    Parameters
    Type Name Description
    Boolean clearCredentials

    Option to clear the session token that enables logging in to the same account

    SwitchProfile(String)

    Switch the current profile. You can use profiles to sign in to multiple accounts on a single device. A profile isolates the values saved to the PlayerPrefs. The profile may only contain alphanumeric values, -, _, and must be no longer than 30 characters. The player must be signed out for this operation to succeed.

    Declaration
    void SwitchProfile(string profile)
    Parameters
    Type Name Description
    String profile

    The profile to switch to.

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player is not signed out.
    • Throws with ErrorCode ClientInvalidProfile if the profile name is invalid.

    UnlinkAppleAsync()

    Unlinks the Apple account from the current player account.

    Declaration
    Task UnlinkAppleAsync()
    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player has not authorized to perform this operation.
    • Throws with ErrorCode ClientUnlinkExternalIdNotFound if the player's PlayerInfo does not have a matching external id.

    UnlinkFacebookAsync()

    Unlinks the Facebook account from the current player account.

    Declaration
    Task UnlinkFacebookAsync()
    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player has not authorized to perform this operation.
    • Throws with ErrorCode ClientUnlinkExternalIdNotFound if the player's PlayerInfo does not have a matching external id.

    UnlinkGoogleAsync()

    Unlinks the Google account from the current player account.

    Declaration
    Task UnlinkGoogleAsync()
    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player has not authorized to perform this operation.
    • Throws with ErrorCode ClientUnlinkExternalIdNotFound if the player's PlayerInfo does not have a matching external id.

    UnlinkSteamAsync()

    Unlinks the Steam account from the current player account.

    Declaration
    Task UnlinkSteamAsync()
    Returns
    Type Description
    Task

    Task for the operation

    Exceptions
    Type Condition
    AuthenticationException

    The task fails with the exception when the task cannot complete successfully due to Authentication specific errors.

    • Throws with ErrorCode ClientInvalidUserState if the player has not authorized to perform this operation.
    • Throws with ErrorCode ClientUnlinkExternalIdNotFound if the player's PlayerInfo does not have a matching external id.

    Events

    Expired

    Invoked when a session expires.

    Declaration
    event Action Expired
    Event Type
    Type Description
    Action

    SignedIn

    Invoked when a sign-in attempt has completed successfully.

    Declaration
    event Action SignedIn
    Event Type
    Type Description
    Action

    SignedOut

    Invoked when a sign-out attempt has completed successfully.

    Declaration
    event Action SignedOut
    Event Type
    Type Description
    Action

    SignInFailed

    Invoked when a sign-in attempt has failed. The reason for failure is passed as the parameter AuthenticationException.

    Declaration
    event Action<RequestFailedException> SignInFailed
    Event Type
    Type Description
    Action<RequestFailedException>
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023