Beispiel #1
0
        public UM_AndroidSignInClient()
        {
            SA_MonoEvents.OnApplicationPause.AddSafeListener(this, (paused) => {
                if (!paused)
                {
                    //We do not want to do Silent SignIn on resume in case player not yet signed.
                    if (PlayerInfo.State == UM_PlayerState.SignedOut)
                    {
                        // In case it's not null, this means we are missng something, so we will do  Silent SignIn
                        // The case may happend because we sending fail event on propxy Activity Destory event.
                        // But propxy Activity Destory not always means that player is failed to log in.
                        // We have to send fail evennt on propxy Activity Destory, since if we not, in cases where google and our proxy
                        // activity both are destoryed, we will not get any event.
                        if (AN_GoogleSignIn.GetLastSignedInAccount() == null)
                        {
                            return;
                        }
                    }

                    //We need to perform Silent SignIn every time we back from pause
                    SignInClient.SilentSignIn((silentSignInResult) => {
                        if (silentSignInResult.IsSucceeded)
                        {
                            RetrivePlayer((result) => { });
                        }
                        else
                        {
                            //looks Like player singed out
                            UpdatePlayerInfo(null);
                        }
                    });
                }
            });
        }
        public void SignOutRequest(Action <bool, AN_CommonStatusCodes> resultCallback = null, bool revokeAccess = false)
        {
            if (!IsGoogleApiAvailable)
            {
                return;
            }

            var gso    = new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).Build();
            var client = AN_GoogleSignIn.GetClient(gso);

            //sign out
            client.SignOut(() =>
            {
                GoogleSignedInAccount = null;
                _currentPlayerData    = null;
                resultCallback.SafeInvoke(false, AN_CommonStatusCodes.SUCCESS);

                _isSigninIgnored = true;
                PlayerPrefs.SetInt("IsSigninIgnored", 1);

                OnGPlayAuth.SafeInvoke(false);
            });

            //revoke access
            if (revokeAccess)
            {
                client.RevokeAccess(() =>
                {
                    GoogleSignedInAccount = null;
                    _currentPlayerData    = null;
                });
            }
        }
Beispiel #3
0
    private void SignInNoSilent()
    {
        AN_GoogleSignInOptions.Builder builder = new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
        builder.RequestId();
        builder.RequestEmail();
        builder.RequestProfile();

        AN_GoogleSignInOptions gso    = builder.Build();
        AN_GoogleSignInClient  client = AN_GoogleSignIn.GetClient(gso);

        AN_Logger.Log("SignInNoSilent Start ");

        client.SignIn((signInResult) => {
            AN_Logger.Log("Sign In StatusCode: " + signInResult.StatusCode);
            if (signInResult.IsSucceeded)
            {
                AN_Logger.Log("SignIn Succeeded");
                UpdateUIWithAccount(signInResult.Account);
            }
            else
            {
                AN_Logger.Log("SignIn filed: " + signInResult.Error.FullMessage);
            }
        });
    }
Beispiel #4
0
    private void SignOutFlow()
    {
        AN_GoogleSignInOptions gso    = new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).Build();
        AN_GoogleSignInClient  client = AN_GoogleSignIn.GetClient(gso);

        client.SignOut(() => {});
    }
        public bool IsSignedIn()
        {
            if (!IsGoogleApiAvailable)
            {
                return(false);
            }

            return(AN_GoogleSignIn.GetLastSignedInAccount() != null);
        }
Beispiel #6
0
 public override void Test()
 {
     if (AN_GoogleSignIn.GetLastSignedInAccount() != null)
     {
         SignInClient.SignOut(() => {
             SignIn();
         });
     }
     else
     {
         SignIn();
     }
 }
Beispiel #7
0
    private void SignInFlow()
    {
        AN_Logger.Log("Play Services Sign In started....");
        AN_GoogleSignInOptions.Builder builder = new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);

        //Google play documentation syas that
        // you don't need to use this, however, we recommend you still
        // add those option to your Sing In builder. Some version of play service lib
        // may retirn a signed account with all fileds empty if you will not add this.
        // However according to the google documentation this step isn't required
        // So the decision is up to you.
        builder.RequestId();
        builder.RequestEmail();
        builder.RequestProfile();

        // Add the APPFOLDER scope for Snapshot support.
        builder.RequestScope(AN_Drive.SCOPE_APPFOLDER);

        AN_GoogleSignInOptions gso    = builder.Build();
        AN_GoogleSignInClient  client = AN_GoogleSignIn.GetClient(gso);

        AN_Logger.Log("Let's try Silent SignIn first");
        client.SilentSignIn((result) => {
            if (result.IsSucceeded)
            {
                AN_Logger.Log("SilentSignIn Succeeded");
                UpdateUIWithAccount(result.Account);
            }
            else
            {
                // Player will need to sign-in explicitly using via UI

                AN_Logger.Log("SilentSignIn Failed with code: " + result.Error.Code);
                AN_Logger.Log("Starting the default Sign in flow");

                //Starting the interactive sign-in
                client.SignIn((signInResult) => {
                    AN_Logger.Log("Sign In StatusCode: " + signInResult.StatusCode);
                    if (signInResult.IsSucceeded)
                    {
                        AN_Logger.Log("SignIn Succeeded");
                        UpdateUIWithAccount(signInResult.Account);
                    }
                    else
                    {
                        AN_Logger.Log("SignIn filed: " + signInResult.Error.FullMessage);
                    }
                });
            }
        });
    }
        public void GetSignedInPlayerData(Action <AN_Player> resultCallback = null)
        {
            if (!IsGoogleApiAvailable || AN_GoogleSignIn.GetLastSignedInAccount() == null)
            {
                return;
            }

            if (_currentPlayerData != null) //early exit with existing player data
            {
                //Printing player info:
                Debug.Log("player.Id: " + _currentPlayerData.PlayerId);
                Debug.Log("player.Title: " + _currentPlayerData.Title);
                Debug.Log("player.DisplayName: " + _currentPlayerData.DisplayName);
                Debug.Log("player.HiResImageUri: " + _currentPlayerData.HiResImageUri);
                Debug.Log("player.IconImageUri: " + _currentPlayerData.IconImageUri);
                Debug.Log("player.HasIconImage: " + _currentPlayerData.HasIconImage);
                Debug.Log("player.HasHiResImage: " + _currentPlayerData.HasHiResImage);

                resultCallback.SafeInvoke(_currentPlayerData);

                return;
            }

            AN_PlayersClient client = AN_Games.GetPlayersClient();

            client.GetCurrentPlayer(result =>
            {
                if (result.IsSucceeded)
                {
                    _currentPlayerData = result.Data;

                    //Printing player info:
                    Debug.Log("player.Id: " + _currentPlayerData.PlayerId);
                    Debug.Log("player.Title: " + _currentPlayerData.Title);
                    Debug.Log("player.DisplayName: " + _currentPlayerData.DisplayName);
                    Debug.Log("player.HiResImageUri: " + _currentPlayerData.HiResImageUri);
                    Debug.Log("player.IconImageUri: " + _currentPlayerData.IconImageUri);
                    Debug.Log("player.HasIconImage: " + _currentPlayerData.HasIconImage);
                    Debug.Log("player.HasHiResImage: " + _currentPlayerData.HasHiResImage);

                    resultCallback.SafeInvoke(_currentPlayerData);
                }
                else
                {
                    Debug.Log("Failed to load Current Player " + result.Error.FullMessage);
                    resultCallback.SafeInvoke(null);
                }
            });
        }
Beispiel #9
0
#pragma warning restore 649


    //Avoid using API with Awake. The main Android activity may not be ready yet.
    private void Start()
    {
        AN_Logger.Log("AN_GMS_Auth_Example Start");
        //Let's see if user has already signed in
        var signedInAccount = AN_GoogleSignIn.GetLastSignedInAccount();

        if (signedInAccount != null)
        {
            //That's good but we need to re-connect anyway

            SignInNoSilent();
            //UpdateUIWithAccount(signedInAccount);
        }

        /*
         * m_checkAvalibility.onClick.AddListener(() => {
         *  int result = AN_GoogleApiAvailability.IsGooglePlayServicesAvailable();
         *  if (result != AN_ConnectionResult.SUCCESS) {
         *      Debug.Log("Play Services does not available on this device. Resolving....");
         *
         *      AN_GoogleApiAvailability.MakeGooglePlayServicesAvailable((resolution) => {
         *          if (resolution.IsSucceeded) {
         *              Debug.Log("Resolved! Play Services is available on this device");
         *          } else {
         *              Debug.Log("Failed to resolve: " + resolution.Error.Message);
         *          }
         *      });
         *  } else {
         *      Debug.Log("Play Services is available on this device");
         *  }
         * });
         *
         */


        m_connect.onClick.AddListener(() => {
            var account = AN_GoogleSignIn.GetLastSignedInAccount();
            if (account == null)
            {
                SignInFlow();
            }
            else
            {
                SignOutFlow();
            }
        });
    }
Beispiel #10
0
    //Avoid using API with Awake. The main Android activity may not be ready yet.
    private void Start()
    {
        AN_Logger.Log("AN_GMS_Auth_Example Start");
        //Let's see if user has already signed in
        var signedInAccount = AN_GoogleSignIn.GetLastSignedInAccount();

        if (signedInAccount != null)
        {
            SignInNoSilent();
        }



        var account = AN_GoogleSignIn.GetLastSignedInAccount();

        if (account == null)
        {
            SignInFlow();
        }
        else
        {
            SignOutFlow();
        }
    }
        public void SignInRequest(Action <bool, AN_CommonStatusCodes> resultCallback = null, bool ignorePrefs = false)
        {
            if (!IsGoogleApiAvailable)
            {
                return;
            }

            Debug.Log("Signing request...");

            if (IsSignedIn()) //if already signed in
            {
                resultCallback.SafeInvoke(true, AN_CommonStatusCodes.SUCCESS);
                GetSignedInPlayerData();
                ActivateGPlayPopup();

                _isSigninIgnored = false;
                PlayerPrefs.SetInt("IsSigninIgnored", 0);
                OnGPlayAuth.SafeInvoke(true);

                return;
            }

            if (!ignorePrefs)
            {
                if (_isSigninIgnored)
                {
                    resultCallback.SafeInvoke(false, AN_CommonStatusCodes.CANCELED);
                    Debug.Log("Signin Ignored!");
                    return;
                }
            }

            AN_GoogleSignInOptions.Builder builder =
                new AN_GoogleSignInOptions.Builder(AN_GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
            builder.RequestId();
            builder.RequestEmail();
            builder.RequestProfile();
            //builder.RequestScope(AN_Drive.SCOPE_APPFOLDER);

            var gso    = builder.Build();
            var client = AN_GoogleSignIn.GetClient(gso);

            var authStatus = AN_CommonStatusCodes.SIGN_IN_REQUIRED;

            //silent sign in
            client.SilentSignIn(signInResult =>
            {
                Debug.Log("Sign In StatusCode [silent]: " + signInResult.StatusCode);
                authStatus = signInResult.StatusCode;

                if (signInResult.IsSucceeded)
                {
                    Debug.Log("SignIn Succeeded [silent]");
                    GoogleSignedInAccount = signInResult.Account;
                    resultCallback.SafeInvoke(true, authStatus);
                    ActivateGPlayPopup();

                    //finally when signin is success, cache the player data for first time
                    if (authStatus == AN_CommonStatusCodes.SUCCESS)
                    {
                        GetSignedInPlayerData();

                        _isSigninIgnored = false;
                        PlayerPrefs.SetInt("IsSigninIgnored", 0);

                        OnGPlayAuth.SafeInvoke(true);
                    }
                }
                else
                {
                    GoogleSignedInAccount = null;
                    Debug.Log("Silent SignIn failed [silent] : " + signInResult.Error.FullMessage);

                    //interactive sign in
                    if (authStatus == AN_CommonStatusCodes.SIGN_IN_REQUIRED)
                    {
                        client.SignIn(interactiveSignInResult =>
                        {
                            authStatus = interactiveSignInResult.StatusCode;
                            Debug.Log("Sign In StatusCode [interactive]: " + interactiveSignInResult.StatusCode);

                            if (interactiveSignInResult.IsSucceeded)
                            {
                                Debug.Log("SignIn Succeeded [interactive]");
                                GoogleSignedInAccount = interactiveSignInResult.Account;
                                resultCallback.SafeInvoke(true, authStatus);
                                ActivateGPlayPopup();

                                //finally when signin is success, cache the player data for first time
                                if (authStatus == AN_CommonStatusCodes.SUCCESS)
                                {
                                    GetSignedInPlayerData();

                                    _isSigninIgnored = false;
                                    PlayerPrefs.SetInt("IsSigninIgnored", 0);

                                    OnGPlayAuth.SafeInvoke(true);
                                }
                            }
                            else
                            {
                                resultCallback.SafeInvoke(false, authStatus);
                                Debug.Log("SignIn failed [interactive]: " + interactiveSignInResult.Error.FullMessage);

                                if (authStatus == AN_CommonStatusCodes.CANCELED || authStatus == AN_CommonStatusCodes.ERROR)
                                {
                                    _isSigninIgnored = true;
                                    PlayerPrefs.SetInt("IsSigninIgnored", 1);
                                }
                            }
                        });
                    }
                }
            });

            //finally when signin is success, cache the player data for first time
            if (authStatus == AN_CommonStatusCodes.SUCCESS)
            {
                GetSignedInPlayerData();
                ActivateGPlayPopup();

                _isSigninIgnored = false;
                PlayerPrefs.SetInt("IsSigninIgnored", 0);

                OnGPlayAuth.SafeInvoke(true);
            }
        }