docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Interface IAuthenticationService

    The functions for Authentication service.

    Namespace: Unity.Services.Authentication
    Assembly: Unity.Services.Authentication.dll
    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
    bool

    Returns true if player is authorized, else false.

    IsExpired

    Checks whether the player session is expired.

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

    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
    bool

    Returns true if player is signed in, else false.

    LastNotificationDate

    The date the last notification for the player was created or null if there are no notifications

    Declaration
    string LastNotificationDate { get; }
    Property Value
    Type Description
    string

    Notifications

    Returns player's notifications after GetNotificationsAsync is called successfully.

    Declaration
    List<Notification> Notifications { get; }
    Property Value
    Type Description
    List<Notification>

    PlayerId

    Returns the current player's ID. This value is cached between sessions.

    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

    PlayerName

    Returns the current player's name. This value is cached between sessions.

    Declaration
    string PlayerName { get; }
    Property Value
    Type Description
    string

    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
    bool

    Methods

    AddUsernamePasswordAsync(string, string)

    Sign up with a new Username/Password and add it to the current logged in user.

    Declaration
    Task AddUsernamePasswordAsync(string username, string password)
    Parameters
    Type Name Description
    string username

    Username of the player. Note that it must be unique per project and contains 3-20 characters of alphanumeric and/or these special characters [. - @ _].

    string password

    Password of the player. Note that it must contain 8-30 characters with at least 1 upper case, 1 lower case, 1 number, and 1 special character.

    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.

    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.

    ConfirmCodeAsync(string, string, string)

    Sends a request to check the status of the provided sign-in code, such as if it's been confirmed by an authenticated user or is still pending. "Confirming" the sign-in code means the server has recognized and accepted the code as valid.

    Declaration
    Task ConfirmCodeAsync(string code, string idProvider = null, string externalToken = null)
    Parameters
    Type Name Description
    string code

    The sign-in code to be confirmed.

    string idProvider

    The ID provider (optional).

    string externalToken

    The external token (optional).

    Returns
    Type Description
    Task

    A Task Representing the asynchronous operation. If the operation succeeds, the task will complete successfully (indicating a successful response from the server). Otherwise, exceptions can be thrown as described below.

    Exceptions
    Type Condition
    AuthenticationException

    Thrown when the code is null or empty.

    AuthenticationException

    Thrown when the current authentication state is invalid for this operation.

    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.

    GenerateSignInCodeAsync(string)

    Asynchronously generates a sign-in code that can be used to sign in. This method should be called before attempting to sign in using the sign-in code.

    Declaration
    Task<SignInCodeInfo> GenerateSignInCodeAsync(string identifier = null)
    Parameters
    Type Name Description
    string identifier

    An optional identifier. If provided, it may influence the generated sign-in code or be used for additional checks.

    Returns
    Type Description
    Task<SignInCodeInfo>

    A Task representing the asynchronous generation operation. The task result contains the generated SignInCodeInfo details:

    • SignInCodeThe unique code generated for signing in. This code should be used in subsequent sign-in attempts.
    • ExpirationThe date and time when the generated sign-in code will expire and become invalid for sign-in attempts.
    Exceptions
    Type Condition
    AuthenticationException

    Thrown when the current authentication state is invalid for this operation.

    GetNotificationsAsync()

    Retrieves the Notifications that were created for the signed in player

    Declaration
    Task<List<Notification>> GetNotificationsAsync()
    Returns
    Type Description
    Task<List<Notification>>
    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.

    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.

    GetPlayerNameAsync(bool)

    Returns the name of the logged in player if it has been set. If no name has been set, this will return null if autoGenerate is set to false. This will also cache the name locally.

    Declaration
    Task<string> GetPlayerNameAsync(bool autoGenerate = true)
    Parameters
    Type Name Description
    bool autoGenerate

    Option auto generate a player name if none already exist. Defaults to true

    Returns
    Type Description
    Task<string>

    Task for the operation with the resulting player name

    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.

    GetSignInCodeInfoAsync(string)

    Fetches detailed information about a given sign-in code, including its associated identifier and expiration details.

    Declaration
    Task<SignInCodeInfo> GetSignInCodeInfoAsync(string code)
    Parameters
    Type Name Description
    string code

    The sign-in code to fetch information for.

    Returns
    Type Description
    Task<SignInCodeInfo>

    The identifier associated with the provided code.

    Exceptions
    Type Condition
    AuthenticationException

    Thrown when the code is null or empty.

    AuthenticationException

    Thrown when the current authentication state is invalid for 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.

    LinkWithAppleGameCenterAsync(string, string, string, string, ulong, LinkOptions)

    Link the current player with the AppleGameCenter account using AppleGameCenter's teamPlayerId.

    Declaration
    Task LinkWithAppleGameCenterAsync(string signature, string teamPlayerId, string publicKeyURL, string salt, ulong timestamp, LinkOptions options = null)
    Parameters
    Type Name Description
    string signature

    AppleGameCenter's signature

    string teamPlayerId

    AppleGameCenter's teamPlayerId

    string publicKeyURL

    AppleGameCenter's publicKeyURL

    string salt

    AppleGameCenter's salt

    ulong timestamp

    AppleGameCenter's timestamp

    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.

    LinkWithGooglePlayGamesAsync(string, LinkOptions)

    Link the current player with the Google play games account using Google play games' authorization code.

    Declaration
    Task LinkWithGooglePlayGamesAsync(string authCode, LinkOptions options = null)
    Parameters
    Type Name Description
    string authCode

    Google play games' authorization code

    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.

    LinkWithOculusAsync(string, string, LinkOptions)

    Link the current player with an Oculus account

    Declaration
    Task LinkWithOculusAsync(string nonce, string userId, LinkOptions options = null)
    Parameters
    Type Name Description
    string nonce

    Client provided nonce key used by the server to verify that the provided Oculus userId is valid

    string userId

    Oculus account userId

    LinkOptions options

    Options for th 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 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.

    LinkWithOpenIdConnectAsync(string, string, LinkOptions)

    Link the current player with a custom openID Connect id provider account.

    Declaration
    Task LinkWithOpenIdConnectAsync(string idProviderName, string idToken, LinkOptions options = null)
    Parameters
    Type Name Description
    string idProviderName

    the name of the id provider created. Note that it must start with "oidc-" and have between 1 and 20 characters

    string idToken

    Id Token for the custom id provider

    LinkOptions 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 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, string, string, LinkOptions)

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

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

    Steam's session ticket

    string identity

    The identity of the calling service

    string appId

    App Id that was used to generate the ticket. Only required for additional app ids (e.g.: PlayTest, Demo, etc)

    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, string, LinkOptions)

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

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

    Steam's session ticket

    string identity

    The identity of the calling service

    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. This method is deprecated and may be removed in future versions.

    Declaration
    [Obsolete("This method is deprecated as of version 2.7.1. Please use the LinkWithSteamAsync method with the 'identity' parameter for better security.")]
    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

    LinkWithUnityAsync(string, LinkOptions)

    Link the current player with Unity account using Unity's access token

    Declaration
    Task LinkWithUnityAsync(string token, LinkOptions options = null)
    Parameters
    Type Name Description
    string token

    Unity'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.

    ProcessAuthenticationTokens(string, string)

    Process the accessToken issued by the Unity Authentication Service. Effectively setting the access token for other UGS services to use and extracting the playerId. If the session token is set the SDK will also process it and refresh the token at the expected intervals.

    Declaration
    void ProcessAuthenticationTokens(string accessToken, string sessionToken = null)
    Parameters
    Type Name Description
    string accessToken

    Unity Player Authentication accessToken used to access other UGS services

    string sessionToken

    sessionToken used to refresh the accessToken, if null the game server needs to refresh the accessToken on its own and call this method again

    Exceptions
    Type Condition
    AuthenticationException

    Thrown when the accessToken fails to parse.

    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.

    SignInWithAppleGameCenterAsync(string, string, string, string, ulong, SignInOptions)

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

    Declaration
    Task SignInWithAppleGameCenterAsync(string signature, string teamPlayerId, string publicKeyURL, string salt, ulong timestamp, SignInOptions options = null)
    Parameters
    Type Name Description
    string signature

    AppleGameCenter's signature

    string teamPlayerId

    AppleGameCenter's teamPlayerId

    string publicKeyURL

    AppleGameCenter's publicKeyURL

    string salt

    AppleGameCenter's salt

    ulong timestamp

    AppleGameCenter's timestamp

    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.

    SignInWithCodeAsync(bool, CancellationToken)

    Asynchronously attempts to sign in using the previously generated sign-in code. This method can optionally poll the server for sign-in confirmation.

    Declaration
    Task SignInWithCodeAsync(bool usePolling = false, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    bool usePolling

    If set to true, the method will continuously poll the server to check if the code has been confirmed, until either the device signs in successfully, the code expires, or the CancellationToken is triggered. False by default.

    CancellationToken cancellationToken

    A token used to cancel the ongoing operation, especially useful when polling is enabled.

    Returns
    Type Description
    Task

    A Task representing the asynchronous operation.

    Exceptions
    Type Condition
    AuthenticationException

    Thrown when the current authentication state is invalid for this operation.

    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.

    SignInWithGooglePlayGamesAsync(string, SignInOptions)

    Sign in using Google Play Games' authorization code. If no options are used, this will create an account if none exist.

    Declaration
    Task SignInWithGooglePlayGamesAsync(string authCode, SignInOptions options = null)
    Parameters
    Type Name Description
    string authCode

    Google Play Games' authorization code

    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.

    SignInWithOculusAsync(string, string, SignInOptions)

    Sign in using an Oculus account userId and nonce key If no options are used, this will create an account if none exists

    Declaration
    Task SignInWithOculusAsync(string nonce, string userId, SignInOptions options = null)
    Parameters
    Type Name Description
    string nonce

    Client provided nonce key used by the server to verify that the provided Oculus userId is valid

    string userId

    Oculus account userId

    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.

    SignInWithOpenIdConnectAsync(string, string, SignInOptions)

    Sign in using a custom openID Connect id provider account. If no options are used, this will create an account if none exist.

    Declaration
    Task SignInWithOpenIdConnectAsync(string idProviderName, string idToken, SignInOptions options = null)
    Parameters
    Type Name Description
    string idProviderName

    the name of the id provider created. Note that it must start with "oidc-" and have between 1 and 20 characters

    string idToken

    Id Token for the custom id provider

    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, string, 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, string identity, string appId, SignInOptions options = null)
    Parameters
    Type Name Description
    string sessionTicket

    Steam's session ticket

    string identity

    The identity of the calling service

    string appId

    App Id that was used to generate the ticket. Only required for additional app ids (e.g.: PlayTest, Demo, etc)

    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, 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, string identity, SignInOptions options = null)
    Parameters
    Type Name Description
    string sessionTicket

    Steam's session ticket

    string identity

    The identity of the calling service

    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. This method is deprecated and may be removed in future versions.

    Declaration
    [Obsolete("This method is deprecated as of version 2.7.1. Please use the SignInWithSteamAsync method with the 'identity' parameter for better security.")]
    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

    SignInWithUnityAsync(string, SignInOptions)

    Sign in using Unity Player Login's access token

    Declaration
    Task SignInWithUnityAsync(string token, SignInOptions options = null)
    Parameters
    Type Name Description
    string token

    Unity Player Login's access token

    SignInOptions options

    Options for the operation

    Returns
    Type Description
    Task

    Task for the async 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 sign-in in progress.

    SignInWithUsernamePasswordAsync(string, string)

    Sign in using Username and Password credentials.

    Declaration
    Task SignInWithUsernamePasswordAsync(string username, string password)
    Parameters
    Type Name Description
    string username

    Username of the player. Note that it must be unique per project and contains 3-20 characters of alphanumeric and/or these special characters [. - @ _].

    string password

    Password of the player. Note that it must contain 8-30 characters with at least 1 upper case, 1 lower case, 1 number, and 1 special character.

    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(bool)

    Sign out the current player.

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

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

    SignUpWithUsernamePasswordAsync(string, string)

    Sign up using Username and Password credentials.

    Declaration
    Task SignUpWithUsernamePasswordAsync(string username, string password)
    Parameters
    Type Name Description
    string username

    Username of the player. Note that it must be unique per project and contains 3-20 characters of alphanumeric and/or these special characters [. - @ _].

    string password

    Password of the player. Note that it must contain 8-30 characters with at least 1 upper case, 1 lower case, 1 number, and 1 special character.

    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.

    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.

    UnlinkAppleGameCenterAsync()

    Unlinks the AppleGameCenter account from the current player account.

    Declaration
    Task UnlinkAppleGameCenterAsync()
    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.

    UnlinkGooglePlayGamesAsync()

    Unlinks the Google play games account from the current player account.

    Declaration
    Task UnlinkGooglePlayGamesAsync()
    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.

    UnlinkOculusAsync()

    Unlinks the Oculus account from the current player account

    Declaration
    Task UnlinkOculusAsync()
    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.

    UnlinkOpenIdConnectAsync(string)

    Unlinks the custom openID Connect id provider account from the current player account.

    Declaration
    Task UnlinkOpenIdConnectAsync(string idProviderName)
    Parameters
    Type Name Description
    string idProviderName

    the name of the id provider created. Note that it must start with "oidc-" and have between 1 and 20 characters

    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.

    UnlinkUnityAsync()

    Unlinks the Unity account from the current player account

    Declaration
    Task UnlinkUnityAsync()
    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.

    UpdatePasswordAsync(string, string)

    Update Password credentials for username/password user.

    Declaration
    Task UpdatePasswordAsync(string currentPassword, string newPassword)
    Parameters
    Type Name Description
    string currentPassword

    Current password of the player. Note that it must contain 8-30 characters with at least 1 upper case, 1 lower case, 1 number, and 1 special character.

    string newPassword

    New password of the player. Note that it must contain 8-30 characters with at least 1 upper case, 1 lower case, 1 number, and 1 special character.

    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.

    UpdatePlayerNameAsync(string)

    Updates the player name of the logged in player.

    Declaration
    Task<string> UpdatePlayerNameAsync(string name)
    Parameters
    Type Name Description
    string name

    The new name for the player. It must not contain spaces.

    Returns
    Type Description
    Task<string>

    Task for the operation with the resulting player name

    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.
    • Throws with ErrorCode InvalidParameters if the provided player name is invalid.

    Events

    Expired

    Invoked when a session expires.

    Declaration
    event Action Expired
    Event Type
    Type Description
    Action

    SignInCodeExpired

    Invoked when the sign-in code expires.

    Declaration
    event Action SignInCodeExpired
    Event Type
    Type Description
    Action

    SignInCodeReceived

    Invoked when the SignInWithCodeAsync method successfully generates a SignInCode.

    Declaration
    event Action<SignInCodeInfo> SignInCodeReceived
    Event Type
    Type Description
    Action<SignInCodeInfo>

    SignInFailed

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

    Declaration
    event Action<RequestFailedException> SignInFailed
    Event Type
    Type Description
    Action<RequestFailedException>

    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
    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)