Chuyển tới nội dung chính

IProjectVAuthenticationPresenter interface

The sign-in contract for the Login scene: observe the state, call a command, redraw on change. Commands return a result for server, network and input failures instead of throwing. A command started while another runs waits for it to finish.

Namespace: SilverTiger.ProjectV.Unity.Presentation.Authentication

public interface IProjectVAuthenticationPresenter

Properties​

PropertyTypeDescription
CurrentProjectVAuthenticationSnapshotThe sign-in state right now; never null. Starts as SignedOut.

Methods​

GetNativeAvailability(ProjectVNativeAuthenticationProvider provider)​

Tells whether a Google or Apple sign-in button can work on this device and build.

ProjectVNativeAuthenticationAvailabilityView GetNativeAvailability(ProjectVNativeAuthenticationProvider provider);

Parameters

NameTypeDescription
providerProjectVNativeAuthenticationProviderThe sign-in provider to check.

Returns

ProjectVNativeAuthenticationAvailabilityView: The availability; show the button only when ProjectVNativeAuthenticationAvailabilityView.IsAvailable is true.

Exceptions

ExceptionWhen
ArgumentOutOfRangeExceptionprovider is not a known provider.

SubscribeAsync(Action<ProjectVAuthenticationSnapshot> listener)​

Calls listener with the current state right away, then again on every change.

Task<IDisposable> SubscribeAsync(Action<ProjectVAuthenticationSnapshot> listener);

Parameters

NameTypeDescription
listenerAction<ProjectVAuthenticationSnapshot>Redraws the Login UI; must not be null. An exception it throws on a later change is ignored.

Returns

Task<IDisposable>: The subscription; dispose it when the scene closes.

Exceptions

ExceptionWhen
ArgumentNullExceptionlistener is null.
ObjectDisposedExceptionThe presenter was already shut down.

RestoreAsync(CancellationToken cancellationToken)​

Signs the player back in with the sign-in saved from an earlier play, if there is one. Call it when the Login scene opens.

Task<ProjectVAuthenticationCommandResult> RestoreAsync(CancellationToken cancellationToken);

Parameters

NameTypeDescription
cancellationTokenCancellationTokenCancels the attempt, for example when the scene closes.

Returns

Task<ProjectVAuthenticationCommandResult>: When a saved sign-in worked, ProjectVAuthenticationSnapshot.IsAuthenticated is true. When there was none, ProjectVAuthenticationCommandResult.IsSuccess is true and the state is SignedOut: show the sign-in options. When the saved sign-in was refused, the state is SignedOut with an ProjectVAuthenticationSnapshot.Error; show the sign-in options too.

LoginPasswordAsync(string username, string password, CancellationToken cancellationToken)​

Signs in with a username and password.

Task<ProjectVAuthenticationCommandResult> LoginPasswordAsync(string username, string password, CancellationToken cancellationToken);

Parameters

NameTypeDescription
usernamestringThe username the player typed; a blank value fails without contacting the server.
passwordstringThe password the player typed; an empty value fails without contacting the server.
cancellationTokenCancellationTokenCancels the attempt.

Returns

Task<ProjectVAuthenticationCommandResult>: ProjectVAuthenticationSnapshot.IsAuthenticated is true when the player is signed in. Otherwise ProjectVAuthenticationSnapshot.Error says why, for example refused credentials.

RegisterPasswordAsync(ProjectVPasswordRegistrationInput input, CancellationToken cancellationToken)​

Creates a username and password account. It does not sign the player in: on success, call LoginPasswordAsync with the same username and password.

Task<ProjectVAuthenticationCommandResult> RegisterPasswordAsync(ProjectVPasswordRegistrationInput input, CancellationToken cancellationToken);

Parameters

NameTypeDescription
inputProjectVPasswordRegistrationInputWhat the player typed into the register form; a blank username or empty password fails without contacting the server.
cancellationTokenCancellationTokenCancels the attempt.

Returns

Task<ProjectVAuthenticationCommandResult>: ProjectVAuthenticationCommandResult.IsSuccess is true when the account was created; the state is then SignedOut. Otherwise ProjectVAuthenticationSnapshot.Error says why, for example the username is taken.

Exceptions

ExceptionWhen
ArgumentNullExceptioninput is null.

SignInWithGoogleAsync(ProjectVNativeAuthenticationOptions? options, CancellationToken cancellationToken)​

Opens the Google sign-in prompt, then signs the player in with the chosen Google account.

Task<ProjectVAuthenticationCommandResult> SignInWithGoogleAsync(ProjectVNativeAuthenticationOptions? options, CancellationToken cancellationToken);

Parameters

NameTypeDescription
optionsProjectVNativeAuthenticationOptions?Extra options, or null.
cancellationTokenCancellationTokenCancels the attempt.

Returns

Task<ProjectVAuthenticationCommandResult>: ProjectVAuthenticationSnapshot.IsAuthenticated is true when the player is signed in. Otherwise ProjectVAuthenticationSnapshot.Error says why: the Cancelled category means the player closed the prompt. It also fails when Google sign-in is not available on this device.

SignInWithAppleAsync(ProjectVNativeAuthenticationOptions? options, CancellationToken cancellationToken)​

Opens the Sign in with Apple prompt, then signs the player in with the chosen Apple ID.

Task<ProjectVAuthenticationCommandResult> SignInWithAppleAsync(ProjectVNativeAuthenticationOptions? options, CancellationToken cancellationToken);

Parameters

NameTypeDescription
optionsProjectVNativeAuthenticationOptions?Extra options, or null.
cancellationTokenCancellationTokenCancels the attempt.

Returns

Task<ProjectVAuthenticationCommandResult>: ProjectVAuthenticationSnapshot.IsAuthenticated is true when the player is signed in. Otherwise ProjectVAuthenticationSnapshot.Error says why: the Cancelled category means the player closed the prompt. It also fails when Apple sign-in is not available on this device.

AuthenticateDeviceAsync(string id, ProjectVNativeAuthenticationOptions? options, CancellationToken cancellationToken)​

Signs in as a Guest tied to this device. Get the ID from IProjectVGuestIdentityProvider.GetOrCreateAsync so the player keeps the same Guest account.

Task<ProjectVAuthenticationCommandResult> AuthenticateDeviceAsync(string id, ProjectVNativeAuthenticationOptions? options, CancellationToken cancellationToken);

Parameters

NameTypeDescription
idstringThe device's Guest ID; a blank value fails without contacting the server.
optionsProjectVNativeAuthenticationOptions?Extra options, or null.
cancellationTokenCancellationTokenCancels the attempt.

Returns

Task<ProjectVAuthenticationCommandResult>: ProjectVAuthenticationSnapshot.IsAuthenticated is true when the player is signed in. Otherwise ProjectVAuthenticationSnapshot.Error says why.

LogoutAsync(CancellationToken cancellationToken)​

Signs the player out on this device. The player must sign in again to play.

Task<ProjectVAuthenticationCommandResult> LogoutAsync(CancellationToken cancellationToken);

Parameters

NameTypeDescription
cancellationTokenCancellationTokenCancels the attempt.

Returns

Task<ProjectVAuthenticationCommandResult>: ProjectVAuthenticationCommandResult.IsSuccess is true and the state is SignedOut when the player was signed out. Otherwise ProjectVAuthenticationSnapshot.Error says why.