private void FacebookAuth(string accessToken)
    {
        Firebase.Auth.Credential credential =
            Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.Log("SignInWithCredentialAsync was canceled.");
                onLogedIn.SetActive(false);
                return;
            }
            if (task.IsFaulted)
            {
                Debug.Log("SignInWithCredentialAsync encountered an error: ");
                onLogedIn.SetActive(false);
                ErrorPanel.SetActive(true);
                return;
            }

            user = auth.CurrentUser;


            // Load another Scene
            // SceneManager.LoadScene("Game", LoadSceneMode.Single);

            onLogedIn.SetActive(true);

            Debug.Log(string.Format("User signed in successfully: {0} ({1})",
                                    user.DisplayName, user.UserId));
        });
    }
Beispiel #2
0
    public void AuthenticatewithFirebase(string accessToken)
    {
        try
        {
            Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
            auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.Log("SignInWithCredentialAsync encountered an error: " + task.Exception);
                    return;
                }
                Firebase.Auth.FirebaseUser newUser = task.Result;

                Debug.Log(string.Format("User signed in successfully: {0} ({1})",
                                        newUser.DisplayName, newUser.UserId));
                PlayerPrefs.SetString("uidSave", newUser.UserId);
                SceneManager.LoadScene(1);
            });
        }
        catch (Exception ex)
        {
            Debug.LogError("LOG LOGIN FACEBOOK" + ex.Message);
        }
    }
Beispiel #3
0
    private void FacebookAuth(string accessToken)
    {
        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential =
            Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
        });
        Firebase.Auth.FirebaseUser user = auth.CurrentUser;
        if (user != null)
        {
            string     myname      = user.DisplayName;
            string     myemail     = user.Email;
            System.Uri myphoto_url = user.PhotoUrl;
            // The user's Id, unique to the Firebase project.
            // Do NOT use this value to authenticate with your backend server, if you
            // have one; use User.TokenAsync() instead.
            string uid = user.UserId;
        }
    }
Beispiel #4
0
    public void LinkEmailToPhone()
    {
        Firebase.Auth.Credential credential = Firebase.Auth.EmailAuthProvider.GetCredential(email.text, password.text);

        auth.CurrentUser.LinkWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("LinkWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("LinkWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            newUser = task.Result;
            Debug.LogFormat("Credentials successfully linked to Firebase user: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
            registeredUserID = newUser.UserId;
            isSignupDone     = true;
            // CreateUserDocument();
            // register = true;
        });
    }
Beispiel #5
0
    private void OnLogIn(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

            AccessToken token = AccessToken.CurrentAccessToken;
            Firebase.Auth.Credential credential =
                Firebase.Auth.FacebookAuthProvider.GetCredential(token + "");
            auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("SignInWithCredentialAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                    return;
                }

                Firebase.Auth.FirebaseUser newUser = task.Result;
                Debug.LogFormat("User signed in successfully: {0} ({1})",
                                newUser.DisplayName, newUser.UserId);
                userIdText.text = newUser.UserId;
            });
            Debug.LogError("User sign tmam");
        }
    }
    public void FacebookLogin(Delegates.UserLoginSuccess successListener, Delegates.UserLoginFail failListener)
    {
        FacebookManager.FacebookManagerInstance().FacebookLogin(delegate(string accessToken) {
            Firebase.Auth.Credential credential =
                Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
            auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("SignInWithCredentialAsync was canceled.");
                    failListener("SignInWithCredentialAsync was canceled.");
                    return;
                }
                if (task.IsFaulted || task.Exception != null)
                {
                    Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                    failListener(GetErrorMessage(task.Exception.InnerExceptions [0] as FirebaseException));
                    return;
                }

                Firebase.Auth.FirebaseUser newUser = task.Result;
                successListener(newUser.UserId);
                Debug.LogFormat("User signed in successfully: {0} ({1})",
                                newUser.DisplayName, newUser.UserId);
            });
        }, delegate(string error) {
            failListener(error);
        });
    }
    private void AuthFirebase()
    {
        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential = Firebase.Auth.FacebookAuthProvider.GetCredential(Facebook.Unity.AccessToken.CurrentAccessToken.TokenString);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser user = auth.CurrentUser;
            if (user != null)
            {
                string name          = user.DisplayName;
                string email         = user.Email;
                System.Uri photo_url = user.PhotoUrl;
                // The user's Id, unique to the Firebase project.
                // Do NOT use this value to authenticate with your backend server, if you
                // have one; use User.TokenAsync() instead.
                string uid = user.UserId;
                SceneManager.LoadScene("SampleScene", LoadSceneMode.Single);
            }
        });
    }
    private void FacebookAuth(string accessToken)
    {
        Firebase.Auth.Credential credential =
            Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                WriteLog("SignInWithCredentialAsync was canceled.", "ERR");
                return;
            }
            if (task.IsFaulted)
            {
                WriteLog("SignInWithCredentialAsync encountered an error: " + task.Exception, "ERR");
                return;
            }

            user = auth.CurrentUser;

            WriteLog(String.Format("User signed in successfully: {0} ({1})",
                                   user.DisplayName, user.UserId));

            txtSignedUsername.text = user.DisplayName;

            WriteLog("PhotoUrl:" + user.PhotoUrl.AbsoluteUrlOrEmptyString());

            ////It might an error, but with url get from firebase, now we can't get a profile image. So we succgess a solution,
            ////we will use profile url from facebook that we get after login.
            //StartCoroutine(LoadImage(CheckImageUrl(user.PhotoUrl.AbsoluteUrlOrEmptyString())));
            StartCoroutine(LoadImage(imageUrl));
        });
    }
Beispiel #9
0
    public void FBFirebaseAuth(AccessToken accessToken)
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

        Debug.Log(FB.IsInitialized);

        Debug.Log("Facebook is clicked");

        Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken.TokenString);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            Debug.Log(credential.ToString());
            Debug.Log(task.ToString());

            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
            Debug.Log(newUser.Email);
        });
    }
    //Handle when Google Sign In successfully
    void OnGoogleAuthenticationFinished(Task <GoogleSignInUser> task)
    {
        if (task.IsFaulted)
        {
            using (IEnumerator <System.Exception> enumerator =
                       task.Exception.InnerExceptions.GetEnumerator())
            {
                if (enumerator.MoveNext())
                {
                    GoogleSignIn.SignInException error =
                        (GoogleSignIn.SignInException)enumerator.Current;
                    UnityEngine.Debug.Log("Got Error: " + error);
                    ErrorPanel.SetActive(true);
                    // ErrorMessage.text = (string)error;
                }
                else
                {
                    UnityEngine.Debug.Log("Got Unexpected Exception?!?");
                }
            }
        }
        else if (task.IsCanceled)
        {
            UnityEngine.Debug.Log("Canceled");
        }
        else
        {
            UnityEngine.Debug.Log("Google Sign-In successed");

            UnityEngine.Debug.Log("IdToken: " + task.Result.IdToken);
            UnityEngine.Debug.Log("ImageUrl: " + task.Result.ImageUrl.AbsoluteUrlOrEmptyString());
            UnityEngine.Debug.Log("Email: " + task.Result.Email);

            //Start Firebase Auth
            Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(task.Result.IdToken, null);
            auth.SignInWithCredentialAsync(credential).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    UnityEngine.Debug.Log("SignInWithCredentialAsync was canceled.");
                    return;
                }
                if (t.IsFaulted)
                {
                    UnityEngine.Debug.Log("SignInWithCredentialAsync encountered an error: " + t.Exception);
                    return;
                }

                user = auth.CurrentUser;
                UnityEngine.Debug.Log("Email: " + user.Email);

                // SceneManager.LoadScene("Game", LoadSceneMode.Single);
                onLogedIn.SetActive(true);
            });
        }
    }
Beispiel #11
0
    private static void AuthCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // AccessToken class will have session details
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            // Prints current access token's User ID
            Debug.Log("Access token: " + aToken.UserId.ToString());
            // Print current access token's granted permissions
            foreach (string perm in aToken.Permissions)
            {
                Debug.Log(perm);
                //Debug.Log("Access Token String: " + aToken.TokenString);
            }
            Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(aToken.TokenString);
            FirebaseAuth.DefaultInstance.SignInWithCredentialAsync(credential).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    Debug.Log("Facebook Login Canceled ... ");
                    ViewMessageOnScreen("Facebook Login Canceled ... ");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.Log("Facebook Login error: " + task.Exception);
                    ViewMessageOnScreen("Facebook Login error: " + task.Exception);
                    return;
                }

                Debug.Log("Signed In Successfully ... ");
                Firebase.Auth.FirebaseUser newUser = task.Result;
                Debug.Log("Welcome: " + newUser.DisplayName);
                Debug.Log("Email: " + newUser.Email);
                Globals.username             = newUser.DisplayName.ToString();
                Globals.email                = newUser.DisplayName.ToString();
                Globals.userId               = newUser.UserId.ToString();
                loadDashboard                = true;
                Globals.isLoggedIn           = true;
                Globals.loggedInWithFaceBook = true;
            });
        }
        else
        {
            Debug.Log("User cancelled login ... ");
            ViewMessageOnScreen("User Canceled Login ... ");
        }
    }
Beispiel #12
0
        void FirebaseSignInWithPlayGames()
        {
            // Get credentials from play games
            string authCode = PlayGamesPlatform.Instance.GetServerAuthCode();

            // Get default instance
            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

            // Create firebase credential from play games web server auth code
            Firebase.Auth.Credential credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);

            // Sign in
            auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("SignInWithCredentialAsync was canceled.");
                    logging = false;
                    Logged = false;
                    OnLogInFailed?.Invoke();
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                    logging = false;
                    Logged = false;
                    OnLogInFailed?.Invoke();
                    return;
                }

                logging = false;
                Logged = true;
                PlayerPrefs.SetInt(PlayerPrefsLoggedKey, 0);
                PlayerPrefs.Save();

                // Save data on firestore
                string userId = FirebaseManager.Instance.GetCurrentUser().UserId;
                string displayName = FirebaseManager.Instance.GetCurrentUser().DisplayName;
                string avatarUrl = FirebaseManager.Instance.GetCurrentUser().PhotoUrl.ToString();
                FirebaseManager.Instance.SaveUserDetail(userId, displayName, avatarUrl).ConfigureAwait(false);

                OnLoggedIn?.Invoke();

                Debug.Log("FirebaseUser.DisplayName:" + FirebaseManager.Instance.GetCurrentUser().DisplayName);
            });
        }
Beispiel #13
0
    private void OnLogIn(ILoginResult result)
    {
        //userID.text = "ENTREE";
        if (FB.IsLoggedIn)
        {
            DialogLoggedIn.SetActive(true);
            DialogLoggedOut.SetActive(false);
            FB.API("/me?fields=first_name", HttpMethod.GET, DisplayUsername);
            FB.API("/me?fields=last_name", HttpMethod.GET, DisplayUsername);


            //AccessToken tocken = result.AccessToken;//received access token
            AccessToken tocken = Facebook.Unity.AccessToken.CurrentAccessToken;//received access token
            //AccessToken tocken = AccessToken.CurrentAccessToken;//received access token
            //userID.text = "ENTREX2";
            //string tokn = result.AccessToken.TokenString;
            Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(tocken.TokenString);

            //AccessTokenN(credential);//invoke auth method
            auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                if (task.IsCanceled)
                {
                    Debug.LogError("SignInWithCredentialAsync was canceled.");
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                    return;
                }
                if (task.IsCompleted)
                {
                    userID.text = "ENTREX3";
                }
                Firebase.Auth.FirebaseUser newUser = task.Result;
                Debug.LogFormat("User signed in successfully: {0} ({1})",
                                newUser.DisplayName, newUser.UserId);
            });
        }
        else
        {
            DialogLoggedIn.SetActive(false);
            DialogLoggedOut.SetActive(true);
            Debug.Log("log failed");
        }
    }
        private void GoogleSignInAuthHandler(BaseEvent message)
        {
            LoginEvents.GoogleSignInAuthEvent castEvent  = message as LoginEvents.GoogleSignInAuthEvent;
            Firebase.Auth.Credential          credential = Firebase.Auth.GoogleAuthProvider.GetCredential(castEvent.idToken, null);
            auth.SignInWithCredentialAsync(credential).ContinueWith(t =>
            {
                if (t.IsCanceled)
                {
                    Log("SignInWithCredentialAsync was canceled.");
                    return;
                }
                if (t.IsFaulted)
                {
                    Log("SignInWithCredentialAsync encountered an error: " + t.Exception);
                    return;
                }

                user = auth.CurrentUser;
                MessagingSystem.Instance.DispatchEvent(new LoginEvents.GoogleSignInCredentialsLoginEvent());
            });
        }
Beispiel #15
0
    public void LoginGoogleButtonPressed()
    {
        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential = null; //Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, googleAccessToken);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
        });
    }
Beispiel #16
0
    public void SignInWithCredit(string googleIdToken, string googleAccessToken)
    {
        Firebase.Auth.Credential credential =
            Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, googleAccessToken);
        Auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            User = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            User.DisplayName, User.UserId);
        });
    }
Beispiel #17
0
    /// <summary>
    /// 구글 로그인
    /// </summary>
    public static void GoogleFireBaseLogin()
    {
        PopupManager.Close_Popup();

        if (auth.CurrentUser == null)
        {
            Debug.Log("로그인 안 되어 있음");

            Firebase.Auth.Credential credential =
                Firebase.Auth.GoogleAuthProvider.GetCredential(SocalManager.GetTokens(), null);
            auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    return;
                }
                if (task.IsFaulted)
                {
                    return;
                }

                user_id = auth.CurrentUser.UserId;
                BackEndDataManager.instance.Get_First_Data();
            });
        }
        else
        {
            //Set_State("로그인 되어 있음 " + auth.CurrentUser.UserId);
            Debug.Log("로그인 되어 있음 " + auth.CurrentUser.DisplayName + " \n "
                      + auth.CurrentUser.Email + " \n "
                      + auth.CurrentUser.IsAnonymous + " \n "
                      + auth.CurrentUser.IsEmailVerified + " \n "
                      + auth.CurrentUser.ProviderId + " \n "
                      + auth.CurrentUser.UserId + " \n ");

            user_id = auth.CurrentUser.UserId;
            BackEndDataManager.instance.Get_First_Data();
        }
    }
Beispiel #18
0
    void SignIn()
    {
        Firebase.Auth.Credential credential =
            Firebase.Auth.EmailAuthProvider.GetCredential(Email, Password);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
        });
    }
Beispiel #19
0
    private void SigninWithGoogle(string googleIdToken, string googleAccessToken)
    {
        //Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

        Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, googleAccessToken);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                DebugLog("SignInWithCredentialAsync was canceled");
                return;
            }
            if (task.IsFaulted)
            {
                DebugLog("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            DebugLog("User signed in successfully: " +
                     newUser.DisplayName + " " + newUser.UserId);
        });
    }
Beispiel #20
0
    //Twitter Auth

    public void StartTwitterLogin()
    {
        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential = Firebase.Auth.TwitterAuthProvider.GetCredential(TwtAuthToken, TwtAuthTokenSecret);
        //Firebase.Auth.Credential credential = Firebase.Auth.TwitterAuthProvider.GetCredential(SampleAuth, SampleSecret);

        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser user = auth.CurrentUser;
            Debug.Log("UserName is " + user.DisplayName);
            Debug.Log("Photo URL is " + user.PhotoUrl.ToString());
            if (user != null)
            {
                UserName       = user.DisplayName;
                UserEmail      = user.Email;
                photo_url      = user.PhotoUrl;
                photourlstring = user.PhotoUrl.ToString();
                // The user's Id, unique to the Firebase project.
                // Do NOT use this value to authenticate with your backend server, if you
                // have one; use User.TokenAsync() instead.
            }
        });

        SceneManager.LoadScene("Main Menu");
    }
        private void FacebookAuthHandler(BaseEvent message)
        {
            LoginEvents.FacebookAuthEvent castEvent = message as LoginEvents.FacebookAuthEvent;

            Firebase.Auth.Credential credential =
                Firebase.Auth.FacebookAuthProvider.GetCredential(castEvent.accessToken);

            auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    Log("SignInWithCredentialAsync was canceled.", "ERR");
                    return;
                }
                if (task.IsFaulted)
                {
                    Log("SignInWithCredentialAsync encountered an error: " + task.Exception, "ERR");
                    return;
                }

                user = auth.CurrentUser;
                MessagingSystem.Instance.DispatchEvent(new LoginEvents.FacebookCredentialsLoginEvent());
            });
        }
Beispiel #22
0
 private void AuthCallback(ILoginResult result)
 {
     if (FB.IsLoggedIn)
     {
         // AccessToken class will have session details
         var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
         // Print current access token's User ID
         Debug.Log(aToken.UserId);
         // Print current access token's granted permissions
         foreach (string perm in aToken.Permissions)
         {
             Debug.Log(perm);
         }
         print("Esse é o Token do Cliente_02: " + Facebook.Unity.AccessToken.CurrentAccessToken.TokenString);
         Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(Facebook.Unity.AccessToken.CurrentAccessToken.TokenString);
         FirebaseAuth.DefaultInstance.SignInWithCredentialAsync(credential).ContinueWith(task => {
             if (task.IsCanceled)
             {
                 Debug.LogError("SignInWithCredentialAsync was canceled.");
                 return;
             }
             if (task.IsFaulted)
             {
                 Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                 return;
             }
             Firebase.Auth.FirebaseUser newUser = task.Result;
             Debug.LogFormat("User signed in successfully: {0} ({1})",
                             newUser.DisplayName, newUser.UserId);
         });
     }
     else
     {
         Debug.Log("User cancelled login");
     }
 }
Beispiel #23
0
    private void SignInAndUpdate(Credential credential)
    {
        Debug.Log("We are here");
        gameManager.ShowLoading(true);
        Auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " +
                               task.Exception);
                return;
            }

            User = task.Result;

            Debug.Log("User signed in successfully");
            Firebase.Auth.Credential credentialUpdate = Firebase.Auth.EmailAuthProvider.GetCredential(Email, Password);
            User.LinkWithCredentialAsync(credentialUpdate).ContinueWith(UpdateCredentialTask =>
            {
                if (UpdateCredentialTask.IsCanceled)
                {
                    Debug.LogError("LinkWithCredentialAsync was canceled.");
                    return;
                }
                if (UpdateCredentialTask.IsFaulted)
                {
                    Debug.LogError("LinkWithCredentialAsync encountered an error: " + UpdateCredentialTask.Exception);
                    return;
                }

                User = UpdateCredentialTask.Result;
                Debug.LogFormat("Credentials successfully linked to Firebase user: {0} ({1})",
                                User.Email);
            });

            IDictionary <string, object> updatedFields = new Dictionary <string, object> {
                { "Email", Email },
                { "Password", Password },
                { "PhoneNumber", Phone_Number },
                { "Id", User.UserId },
                { "Name", Name },
                { "LastName", LastName },
                { "Patronymic", Patronymic },
                { "Birthday", Birthday },
            };

            Reference.Child("users").Child(User.UserId).UpdateChildrenAsync(updatedFields).ContinueWithOnMainThread(UpdateTask =>
            {
                if (UpdateTask.IsFaulted)
                {
                    Debug.Log("Error " + UpdateTask.Exception);
                }
                else if (UpdateTask.IsCompleted)
                {
                    gameManager.Panels[2].GetComponent <Animator>().Play("SSCR Fade-out");

                    //Signin(Email, Password);
                    Debug.Log("User's data was successfully updated");
                    PlayerPrefs.SetString(PrefsKey.RememberEmail, Email);
                    PlayerPrefs.SetString(PrefsKey.RememberPass, Password);
                    Reference.Child("users").Child(User.UserId).ChildChanged += HandleValueChanged;

                    GetData();
                }
            });
        });
        gameManager.ShowLoading(false);
    }
Beispiel #24
0
    public void AuthenticateUser()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false /* Don't force refresh */).Build();

        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        UnityEngine.Social.localUser.Authenticate((bool success) => {
            if (success == true)
            {
                //firebase login
                authCode = PlayGamesPlatform.Instance.GetServerAuthCode();
                if (string.IsNullOrEmpty(authCode))
                {
                    Debug.LogError("signed into playgames services but failed to get auth code");
                }
                // Debug.LogFormat("auth code is {0}",authCode);
                Debug.Log("Logged in to Google Play Games Services");

                Firebase.Auth.Credential credential =
                    Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);


                auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                    if (task.IsCanceled)
                    {
                        Debug.LogError("SignInWithCredentialAsync was canceled.");

                        return;
                    }
                    if (task.IsFaulted)
                    {
                        Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                        return;
                    }

                    Firebase.Auth.FirebaseUser newUser = task.Result;

                    user = auth.CurrentUser;

                    if (user != null)
                    {
                        string playerName = user.DisplayName;

                        // The user's Id, unique to the Firebase project.
                        // Do NOT use this value to authenticate with your backend server, if you
                        // have one; use User.TokenAsync() instead.
                        string uid = user.UserId;
                    }
                    Debug.Log("trying to retreive data from firebase");
                    FirebaseDatabase.DefaultInstance
                    .GetReference("users")
                    .GetValueAsync().ContinueWith(task2 => {
                        if (task2.IsFaulted)
                        {
                            // Handle the error...
                            Debug.Log("cant get reference to server");
                        }
                        else if (task2.IsCompleted)
                        {
                            DataSnapshot snapshot = task2.Result;


                            // Do something with snapshot...
                            if (snapshot.Child(user.UserId).Value == null)
                            {
                                writeNewUser(user.UserId, user.DisplayName, 0); Debug.Log("snapshot is null,adding new user to database");
                            }
                            FirebaseDatabase.DefaultInstance
                            .GetReference("users")
                            .GetValueAsync().ContinueWith(task1 => {
                                if (task1.IsFaulted)
                                {
                                    // Handle the error...
                                }
                                else if (task1.IsCompleted)
                                {
                                    DataSnapshot snapshot1 = task1.Result;
                                    // Do something with snapshot...

                                    Debug.Log("user authenticated");

                                    // string json = JsonUtility.FromJson(snapshot);

                                    string data = snapshot1.Child(user.UserId).Child("purchasedcoins").Value.ToString();

                                    Debug.Log("snapshot recovered");

                                    Debug.Log(data);
                                    retreivedCoinsData = int.Parse(data);
                                    Debug.LogFormat("snapshot is:{0}", retreivedCoinsData);

                                    PlayerPrefs.SetInt("Boughtcoins", retreivedCoinsData);
                                    Debug.LogFormat("setting playerprefs: {0}", PlayerPrefs.GetInt("Boughtcoins", 0));


                                    writeNewUser(user.UserId, user.DisplayName, PlayerPrefs.GetInt("Boughtcoins", 0));
                                }
                            });
                        }
                    });



                    // Debug.LogFormat("User signed in successfully: {0} ({1})",
                    //  newUser.DisplayName, newUser.UserId);
                });
            }
            else
            {
                Debug.LogError("Unable to sign in to Google Play Games Srvices");
            }
        }
                                                  );
    }
Beispiel #25
0
        internal void OnAuthenticationFinished(Task <GoogleSignInUser> task)
        {
            if (task.IsFaulted)
            {
                ShowButtons();
                using (IEnumerator <System.Exception> enumerator =
                           task.Exception.InnerExceptions.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        ShowButtons();
                        GoogleSignIn.SignInException error =
                            (GoogleSignIn.SignInException)enumerator.Current;
                        AddStatusText("Got Error: " + error.Status + " " + error.Message);
                        OnSignOut();
                        GameSettings.MyDebug(statusText.text);
                    }
                    else
                    {
                        ShowButtons();
                        AddStatusText("Got Unexpected Exception?!?" + task.Exception);
                        OnSignOut();
                        GameSettings.MyDebug(statusText.text);
                    }
                }
            }
            else if (task.IsCanceled)
            {
                ShowButtons();
                OnSignOut();
                AddStatusText("Canceled");
                GameSettings.MyDebug(statusText.text);
            }
            else
            {
                AddStatusText("Welcome: " + task.Result.DisplayName + "!" + task.Result);
                GameSettings.MyDebug(statusText.text);

                Firebase.Auth.Credential credential =
                    Firebase.Auth.GoogleAuthProvider.GetCredential(task.Result.IdToken, null);
                auth.SignInWithCredentialAsync(credential).ContinueWith(task2 => {
                    if (task2.IsCanceled)
                    {
                        ShowButtons();
                        GameSettings.MyDebug("SignInWithCredentialAsync was canceled.");
                        OnSignOut();
                        return;
                    }
                    if (task2.IsFaulted)
                    {
                        ShowButtons();
                        GameSettings.MyDebug("SignInWithCredentialAsync encountered an error: " + task2.Exception);
                        OnSignOut();
                        return;
                    }

                    user = task2.Result;
                    GameSettings.user = user;
                    GameSettings.MyDebug("User signed in successfully: {0} ({1}) " + user.UserId + " - " + user.UserId);

                    CallServer();
                });
            }
        }
Beispiel #26
0
    //----------------------------------------------------------------------------
    // Facebook <-> Firebase Connection
    //----------------------------------------------------------------------------

    public void accessToken(AccessToken accessToken_)
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

        Firebase.Auth.Credential credential =
            Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken_.TokenString);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
        });

        /*
         * if (!FB.IsLoggedIn)
         * {
         *  return;
         * }
         * Debug.Log("Jumped into accesToken method");
         *
         * try
         * {
         *  Debug.Log("Checkpoint 1");
         *
         *  auth.SignInWithCredentialAsync(c).ContinueWith(task =>
         *  {
         *      Debug.Log("Checkpoint 2");
         *
         *      //Debug.Log(task.Result.ToString());
         *
         *      if (task.IsCanceled)
         *      {
         *          Debug.LogError("SignInWithCredentialAsync was canceled.");
         *          return;
         *      }
         *      if (task.IsFaulted)
         *      {
         *          Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
         *          return;
         *      }
         *      Debug.Log("Checkpoint 3");
         *
         *      FirebaseUser newUser = task.Result;
         *
         *      Debug.LogFormat("User signed in successfully: {0} ({1})",
         *          newUser.DisplayName, newUser.UserId);
         *
         *      Debug.Log("Checkpoint 4");
         *
         *  });
         * } catch(System.Exception e)
         * {
         *  Debug.LogError(e);
         * }
         * }*/
    }