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.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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.
|
RequestFailedException | The task fails with the exception when the task cannot complete successfully.
|
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 RequestFailedException AuthenticationException.
Declaration
event Action<RequestFailedException> SignInFailed
Event Type
Type | Description |
---|---|
Action<RequestFailedException> |