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 |
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 |
UserInfo
Returns the current player's user info, including linked external ids.
Declaration
UserInfo UserInfo { get; }
Property Value
Type | Description |
---|---|
UserInfo |
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.
|
GetUserInfoAsync()
Sign out the current player. Returns the info of the logged in player, which includes id, idDomain, createdAt and externalIds properties.
Declaration
Task<UserInfo> GetUserInfoAsync()
Returns
Type | Description |
---|---|
Task<UserInfo> | 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.
|
LinkWithAppleAsync(String)
Link the current player with the Apple account using Apple's ID token.
Declaration
Task LinkWithAppleAsync(string idToken)
Parameters
Type | Name | Description |
---|---|---|
String | idToken | Apple's ID token |
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.
|
LinkWithExternalTokenAsync(ExternalTokenRequest)
Link the current player with the external provider.
Declaration
Task LinkWithExternalTokenAsync(ExternalTokenRequest externalToken)
Parameters
Type | Name | Description |
---|---|---|
ExternalTokenRequest | externalToken | The user token from the external provider |
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.
|
LinkWithFacebookAsync(String)
Link the current player with the Facebook account using Facebook's access token.
Declaration
Task LinkWithFacebookAsync(string accessToken)
Parameters
Type | Name | Description |
---|---|---|
String | accessToken | Facebook's access token |
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.
|
LinkWithGoogleAsync(String)
Link the current player with the Google account using Google's ID token.
Declaration
Task LinkWithGoogleAsync(string idToken)
Parameters
Type | Name | Description |
---|---|---|
String | idToken | Google's ID token |
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.
|
LinkWithSteamAsync(String)
Link the current player with the Steam account using Steam's session ticket.
Declaration
Task LinkWithSteamAsync(string sessionTicket)
Parameters
Type | Name | Description |
---|---|---|
String | sessionTicket | Steam's session ticket |
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.
|
SignInAnonymouslyAsync()
Signs in the current player anonymously. No credentials are required and the session is confined to the current device.
Declaration
Task SignInAnonymouslyAsync()
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.
|
SignInWithAppleAsync(String)
Sign in using Apple's ID token.
Declaration
Task SignInWithAppleAsync(string idToken)
Parameters
Type | Name | Description |
---|---|---|
String | idToken | Apple's ID token |
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.
|
SignInWithExternalTokenAsync(ExternalTokenRequest)
SignIn the current player with the external provider.
Declaration
Task SignInWithExternalTokenAsync(ExternalTokenRequest externalToken)
Parameters
Type | Name | Description |
---|---|---|
ExternalTokenRequest | externalToken | The user token from the external provider |
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.
|
SignInWithFacebookAsync(String)
Sign in using Facebook's access token.
Declaration
Task SignInWithFacebookAsync(string accessToken)
Parameters
Type | Name | Description |
---|---|---|
String | accessToken | Facebook's access token |
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.
|
SignInWithGoogleAsync(String)
Sign in using Google's ID token.
Declaration
Task SignInWithGoogleAsync(string idToken)
Parameters
Type | Name | Description |
---|---|---|
String | idToken | Google's ID token |
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.
|
SignInWithSessionTokenAsync()
Sign in the current player with the session token stored on the device.
Declaration
Task SignInWithSessionTokenAsync()
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.
|
SignInWithSteamAsync(String)
Sign in using Steam's session ticket.
Declaration
Task SignInWithSteamAsync(string sessionTicket)
Parameters
Type | Name | Description |
---|---|---|
String | sessionTicket | Steam's session ticket |
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.
|
SignOut()
Sign out the current player.
Declaration
void SignOut()
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 |
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.
|
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.
|
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.
|
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.
|
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
Declaration
event Action<RequestFailedException> SignInFailed
Event Type
Type | Description |
---|---|
Action<RequestFailedException> |