/// <summary>
        /// Signs into Game Center account and Firebase (creating an account
        /// automatically if needed).
        /// </summary>
        /// <returns>The task that will be completed when SignIn is completed.</returns>
        public static Task <FirebaseUser> SignIn()
        {
            if (Firebase.Auth.GameCenterAuthProvider.IsPlayerAuthenticated())
            {
                var credentialFuture = Firebase.Auth.GameCenterAuthProvider.GetCredentialAsync();
                var retUserFuture    = credentialFuture.ContinueWith(credentialTask => {
                    if (credentialTask.IsFaulted)
                    {
                        throw credentialTask.Exception;
                    }
                    if (!credentialTask.IsCompleted)
                    {
                        throw new FetchCredentialFailedException(
                            "Game Center SignIn() failed to fetch credential.");
                    }

                    var credential = credentialTask.Result;
                    var userFuture = FirebaseAuth.DefaultInstance.SignInWithCredentialAsync(credential);
                    return(userFuture);
                }).Unwrap().ContinueWith(userTask => {
                    if (userTask.IsFaulted)
                    {
                        throw userTask.Exception;
                    }
                    if (!userTask.IsCompleted)
                    {
                        throw new SignInFailedException(
                            "Game Center SignIn() failed to Sign In with Credential.");
                    }

                    SignInState.SetState(SignInState.State.GameCenter);
                    return(userTask.Result);
                });

                return(retUserFuture);
            }
            else
            {
                TaskCompletionSource <FirebaseUser> taskCompletionSource =
                    new TaskCompletionSource <FirebaseUser>();

                taskCompletionSource.SetException(
                    new SignInFailedException(
                        "Game Center SignIn() failed - User not authenticated to Game Center."));
                return(taskCompletionSource.Task);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Signs into Google Play Games account and Firebase (creating an account automatically
 /// if needed).
 /// </summary>
 /// <returns>The in.</returns>
 public static Task <FirebaseUser> SignIn()
 {
     return(SignIntoGooglePlayServices(
                (Credential credential, TaskCompletionSource <FirebaseUser> taskCompletionSource) => {
         FirebaseAuth.DefaultInstance.SignInWithCredentialAsync(credential).ContinueWith(t => {
             if (!t.IsCompleted || t.IsCanceled)
             {
                 taskCompletionSource.SetCanceled();
             }
             else if (t.IsFaulted)
             {
                 taskCompletionSource.SetException(t.Exception);
             }
             else
             {
                 SignInState.SetState(SignInState.State.GooglePlayServices);
                 taskCompletionSource.SetResult(t.Result);
             }
         });
     }));
 }
Beispiel #3
0
 /// <summary>
 /// Whether or not the game is allowed to auto sign in.
 /// </summary>
 /// <returns><c>true</c>, if auto sign in was allowed, <c>false</c> otherwise.</returns>
 public static bool CanAutoSignIn()
 {
     SignInState.State state = SignInState.GetState();
     return(state == SignInState.State.GooglePlayServices || state == SignInState.State.Unknown);
 }