コード例 #1
0
    private void FirebaseAuthenticate()
    {
        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(authCode);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignIn was canceled.");
                //infoText.color = Color.red;
                //infoText.text += "SignIn was canceled.\n";
                return;
            }

            if (task.IsFaulted)
            {
                Debug.LogError("SignIn throw exception: " + task.Exception.Message + "\n");
                //infoText.color = Color.red;
                //infoText.text += "\nSignIn throw exception: " + task.Exception.Message;
                return;
            }

            if (task.IsCompleted)
            {
                user = task.Result;
                //infoText.text += "isCompleted";
                //infoText.text += "\n" + user.DisplayName + " " + user.UserId;
            }
        });
    }
コード例 #2
0
    public void SignInGoogle(Action callback, Action <String> fallback)
    {
        AuthGoogle(
            () => {
            String token = PlayGamesPlatform.Instance.GetIdToken();

            Firebase.Auth.Credential credential =
                Firebase.Auth.GoogleAuthProvider.GetCredential(token, null);
            auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
                if (task.IsCanceled || task.IsFaulted)
                {
                    fallback("Fail");
                }

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

            Firebase.Auth.FirebaseUser user = auth.CurrentUser;
            if (user != null)
            {
                userName  = user.DisplayName;
                email     = user.Email;
                photo_url = user.PhotoUrl;
                uid       = user.UserId;
            }
        },
            fallback
            );
    }
コード例 #3
0
 // Link the current user with an email / password credential.
 protected Task LinkWithEmailCredentialAsync()
 {
     if (auth.CurrentUser == null)
     {
         DebugLog("Not signed in, unable to link credential to user.");
         var tcs = new TaskCompletionSource <bool>();
         tcs.SetException(new Exception("Not signed in"));
         return(tcs.Task);
     }
     DebugLog("Attempting to link credential to user...");
     Firebase.Auth.Credential cred =
         Firebase.Auth.EmailAuthProvider.GetCredential(email, password);
     if (signInAndFetchProfile)
     {
         return(auth.CurrentUser.LinkAndRetrieveDataWithCredentialAsync(cred).ContinueWith(
                    task => {
             if (LogTaskCompletion(task, "Link Credential"))
             {
                 DisplaySignInResult(task.Result, 1);
             }
         }));
     }
     else
     {
         return(auth.CurrentUser.LinkWithCredentialAsync(cred).ContinueWith(task => {
             if (LogTaskCompletion(task, "Link Credential"))
             {
                 DisplayDetailedUserInfo(task.Result, 1);
             }
         }));
     }
 }
コード例 #4
0
 // This is functionally equivalent to the Signin() function.  However, it
 // illustrates the use of Credentials, which can be aquired from many
 // different sources of authentication.
 public void SigninWithCredentialAsync()
 {
     DebugLog(String.Format("Attempting to sign in as {0}...", FacebookManager.Instance.getAccessToken()));
     DisableUI();
     Firebase.Auth.Credential cred = Firebase.Auth.FacebookAuthProvider.GetCredential(FacebookManager.Instance.getAccessToken());
     auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSigninResult);
 }
コード例 #5
0
    /// <summary>
    /// Ova funkcija se zove kada se proba linkovanje trenutnog naloga sa fejsbukom(klikom na dugme), a neki drugi nalog je vec linkovan sa
    /// istim fb id-jem. Onda se poziva ova funkcija, gde se ucitavaju podaci korisnika koji je vec linkovan od ranije.
    /// </summary>
    public void SignInWithFacebook(string accessToken)
    {
        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);

            user           = newUser;
            App.player.uid = user.UserId;
            //Save();
            //Ovde ne treba save, nego load
            /// <summary>
            /// Ucitavamo podatke tog korisnika koji je linkovan sa zadatim fb id-jem
            /// </summary>
            Load();
        });
    }
コード例 #6
0
    private void SignInFirebase(string googleIdToken, string googleAccessToken)
    {
        status += "Calling SignInFirebase\n";

        Firebase.Auth.Credential credential = null;
        try{
            credential = Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, null);
            status    += "Credential ready\n";
        }
        catch (System.Exception e)
        {
            status += e.Message + "\n";
        }

        auth.SignInWithCredentialAsync(credential)
        .ContinueWith(task => {
            if (task.IsCanceled)
            {
                status += "SignInWithCredentialAsync was canceled.";
            }
            else if (task.IsFaulted)
            {
                status += "SignInWithCredentialAsync encountered an error: " + task.Exception;
            }
            else
            {
                Firebase.Auth.FirebaseUser newUser = task.Result;
                status += "Registered as firebase user successfully! Welcome " + newUser.DisplayName + " (" + newUser.UserId + ")";
            }
        });
    }
コード例 #7
0
    void SigninWithFB(string accessToken)
    {
        isLoading = false;
        Firebase.Auth.Credential credential =
            Firebase.Auth.FacebookAuthProvider.GetCredential(accessToken);
        auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
            if (task.IsCanceled)
            {
                DebugLog("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                DebugLog("SignInWithCredentialAsync encountered an error: " + task.Exception);
                Debug.Log(task.Exception);
                return;
            }
            Firebase.Auth.FirebaseUser newUser = task.Result;
            //FBUser();


            //OpenMainPage();

            UpdateFBUser();

            Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.UserId, newUser.DisplayName);
        });
    }
コード例 #8
0
    public static void AuthSignOut()
    {
        userName  = "";
        userEmail = "";
        userId    = "";

        authPhases = 0;

        if (!setupReady)
        {
            return;
        }
        if (auth == null)
        {
            return;
        }

        auth.SignOut();
        auth.Dispose();
        auth = null;
        if (credential != null)
        {
            credential.Dispose();
            credential = null;
        }
    }
コード例 #9
0
    IEnumerator CoFireBaseGoogleLogin()
    {
        if (!isFireLogin)
        {
            yield return(null);

            string idToken = SocialManager.Instance._IDtoken;


            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

            Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(idToken, null);
            auth.SignInWithCredentialAsync(credential).ContinueWith(
                task =>
            {
                if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
                {
                    // User is now signed in.
                    Firebase.Auth.FirebaseUser newUser = task.Result;
                    Debug.Log(string.Format("FirebaseUser:{0}\nEmail:{1}", newUser.UserId, newUser.Email));
                    isFireLogin = true;
                }
                else
                {
                }
            });
        }
    }
コード例 #10
0
    // TODO Unused...
    public void GoogleSignIn()
    {
        string googleIdToken     = "";
        string googleAccessToken = null;

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

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
            this.infoText.text = "User signed in successfully: " + newUser.UserId;
        });
    }
コード例 #11
0
ファイル: LoginManager.cs プロジェクト: nedcrow/picrossland
    void SignUp()
    {
        try
        {
            string idToken = ((PlayGamesLocalUser)Social.localUser).GetIdToken(); //PlayGamesPlatform.Instance.GetIdToken();
            //Debug.Log("getToken");

            Firebase.Auth.Credential credential =
                Firebase.Auth.GoogleAuthProvider.GetCredential(idToken, null);
            auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
            {
                if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
                {
                    user = task.Result;

                    //result = string.Format("Email : {0}, name : {1}", user.Email, user.DisplayName);

                    UserManager.Instance.currentUser.id   = user.UserId.ToString();
                    UserManager.Instance.currentUser.name = Social.localUser.userName;
                    Debug.Log("FB : " + user.DisplayName.ToString() + " / Social : " + Social.localUser.userName);

                    googleLoginSuccess = true;
                    MainDataBase.instance.OnSaveAdmin(false);
                }
            });
        }
        catch
        {
            Debug.Log("Please Check Your Network Connection.");
        }
    }
コード例 #12
0
ファイル: Login.cs プロジェクト: wer3799/FirebaseSample
    // Use this for initialization
    void Start()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
                                              .RequestIdToken()
                                              .Build();

        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.Activate();

        string googleIdToken = ((PlayGamesLocalUser)Social.localUser).mPlatform.GetIdToken();

        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential =
            Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, null);
        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);
        });
    }
コード例 #13
0
 // This is functionally equivalent to the Signin() function.  However, it
 // illustrates the use of Credentials, which can be aquired from many
 // different sources of authentication.
 public Task SigninWithCredentialAsync()
 {
     DebugLog(String.Format("Attempting to sign in as {0}...", email));
     DisableUI();
     Firebase.Auth.Credential cred = Firebase.Auth.EmailAuthProvider.GetCredential(email, password);
     return(auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSigninResult));
 }
コード例 #14
0
    private void FacebookAuthCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            // AccessToken class will have session details
            var aToken = AccessToken.CurrentAccessToken;
            Debug.Log(AccessToken.CurrentAccessToken.TokenString);

            Firebase.Auth.Credential credential = Firebase.Auth.FacebookAuthProvider.GetCredential(AccessToken.CurrentAccessToken.TokenString);
            mAuth.SignInWithCredentialAsync(credential).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    return;
                }
                if (task.IsFaulted)
                {
                    return;
                }

                Firebase.Auth.FirebaseUser newUser = task.Result;
                Debug.Log("User signed in successfully: " + newUser.DisplayName + " (," + newUser.UserId + ")");
            });
        }
        else
        {
            Debug.Log("User cancelled login");
        }
    }
コード例 #15
0
    IEnumerator coLogin()
    {
        result_text.text = string.Format("\n Try to get Token...");
        while (System.String.IsNullOrEmpty(((PlayGamesLocalUser)Social.localUser).GetIdToken()))
        {
            yield return(null);
        }

        string idToken = ((PlayGamesLocalUser)Social.localUser).GetIdToken();

        result_text.text = string.Format("\n Token : {0}", idToken);


        Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(idToken, null);

        auth.SignInWithCredentialAsync(credential).ContinueWith(
            task =>
        {
            if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
            {
                firebase_user    = task.Result;
                result_text.text = string.Format("FirebaseUser : {0}\nEmail:{1}", firebase_user.UserId, firebase_user.Email);
                firebaseDB.instance.CheckUserDB(firebase_user.UserId, firebase_user.Email);



                // firebase_user.SendEmailVerificationAsync().ContinueWith(t => {
                //  Debug.Log("Verification Email Sent");
                // });
                // System.Uri photo_url = firebase_user.PhotoUrl;
            }
        });
    }
コード例 #16
0
    public void LoginGoogleAccount()
    {
        Debug.Log("LoginGoogleAccount");
        const string googleIdToken     = "990503357582-pkp49i6o86hlui8b8oii9dscgplhr673.apps.googleusercontent.com";
        const string googleAccessToken = "bGJNcivuVZgQHXGZ89AmLK3L";

        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;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
        });
    }
コード例 #17
0
 // This is functionally equivalent to the Signin() function.  However, it
 // illustrates the use of Credentials, which can be aquired from many
 // different sources of authentication.
 public void SigninWithCredential()
 {
     DebugLog(String.Format("Attempting to sign in as {0}...", Email.text));
     //DisableUI();
     Firebase.Auth.Credential cred = Firebase.Auth.EmailAuthProvider.GetCredential(Email.text, Password.text);
     auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSigninResult);
 }
コード例 #18
0
    public void signin()
    {
        emailstring1 = email1.text.ToString();
        passstring1  = password1.text.ToString();
        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential =
            Firebase.Auth.EmailAuthProvider.GetCredential(emailstring1, passstring1);
        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);
        });
        cehcktext = true;
    }
コード例 #19
0
    private void OnLogIn(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            AccessToken token = AccessToken.CurrentAccessToken;
            print("usuario" + token.UserId);

            Firebase.Auth.Credential credential =
                Firebase.Auth.FacebookAuthProvider.GetCredential(token.UserId);
            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);
            });
        }
        else
        {
            print("Canceled");
        }
    }
コード例 #20
0
        /// <summary>
        /// Reauthenticate the user with the current email / password
        /// </summary>
        /// <returns></returns>
        protected Task ReauthenticateAsync()
        {
            var user = auth.CurrentUser;

            if (user == null)
            {
                DebugLog("Not signed in, unable to reauthenticate user.");
                var tcs = new TaskCompletionSource <bool>();
                tcs.SetException(new Exception("Not signed in"));
                return(tcs.Task);
            }
            DebugLog("Reauthenticating...");

            Firebase.Auth.Credential cred = Firebase.Auth.EmailAuthProvider.GetCredential(email, password);
            if (signInAndFetchProfile)
            {
                return(user.ReauthenticateAndRetrieveDataAsync(cred).ContinueWithOnMainThread(task =>
                {
                    if (LogTaskCompletion(task, "Reauthentication"))
                    {
                        DisplaySignInResult(task.Result, 1);
                    }
                }));
            }
            else
            {
                return(user.ReauthenticateAsync(cred).ContinueWithOnMainThread(task =>
                {
                    if (LogTaskCompletion(task, "Reauthentication"))
                    {
                        DisplayDetailedUserInfo(auth.CurrentUser, 1);
                    }
                }));
            }
        }
コード例 #21
0
    public void signInUserAfterSignUp()
    {
        email    = emailText.text;
        password = passwordText.text;

        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);

            // Activate Scanning
            //ScanUIScreen ();
        });
    }
コード例 #22
0
 // This is functionally equivalent to the Signin() function.  However, it
 // illustrates the use of Credentials, which can be aquired from many
 // different sources of authentication.
 public Task SigninWithCredentialAsync(string email, string password)
 {
     _email    = email;
     _password = password;
     Debug.Log(String.Format("Attempting to sign in as {0}...", email));
     Firebase.Auth.Credential cred = Firebase.Auth.EmailAuthProvider.GetCredential(email, password);
     return(auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSigninResult));
 }
コード例 #23
0
 void LinkWithCredential()
 {
     if (auth.CurrentUser == null)
     {
         DebugLog("Not signed in, unable to link credential to user.");
         return;
     }
     DebugLog("Attempting to link credential to user...");
     Firebase.Auth.Credential cred = Firebase.Auth.EmailAuthProvider.GetCredential(email, password);
     auth.CurrentUser.LinkWithCredentialAsync(cred).ContinueWith(HandleLinkCredential);
 }
コード例 #24
0
    /// <summary>
    /// called in googlesignin() after to check authentication success
    /// </summary>
    /// <param name="task"> Contains all the output returned by google</param>
    internal void OnAuthenticationFinished(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;
                    Debug.Log("Got Error: " + error.Status + " " + error.Message);
                }
                else
                {
                    Debug.Log("Got Unexpected Exception?!?" + task.Exception);
                }
            }
        }
        else if (task.IsCanceled)
        {
            Debug.Log("Canceled");
        }

        else
        {
            //signin
            debtext.text = "Welcome: " + task.Result.DisplayName + "!";
            Debug.Log("Hello!" + task.Result.DisplayName);
            username = task.Result.DisplayName;
            signedIn = true;
            SaveUserData();
        }

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

            Firebase.Auth.FirebaseUser newUser = fbtask.Result;
            fbdebtext.text = ("User signed in successfully:" + newUser.DisplayName + newUser.UserId);
            Debug.Log("Logged firebase:" + newUser.DisplayName + newUser.UserId);
        });
    }
コード例 #25
0
ファイル: FirebaseManager.cs プロジェクト: boolks/MenuAR
    IEnumerator gmailLogin()
    {
        while (System.String.IsNullOrEmpty(((PlayGamesLocalUser)Social.localUser).GetIdToken()))
        {
            yield return(null);
        }

        string idToken = ((PlayGamesLocalUser)Social.localUser).GetIdToken();

        Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(idToken, null);

        // auth의 값이 파이어베이스에 제대로 전달 될 경우 로그인을 실행하는 작업.
        auth.SignInWithCredentialAsync(credential).ContinueWith(
            task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignIn canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignIn error: " + task.Exception);
                return;
            }

            if (task.IsCompleted && !task.IsCanceled && !task.IsFaulted)
            {
                // User is now signed in.
                Firebase.Auth.FirebaseUser newUser = task.Result;
                SceneManager.LoadScene("menuScene");
            }
        });

        // 여러 인증 제공업체를 통해 로그인을 할 경우 한 가지로 관리하기 위한 설정.
        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;
            }

            Firebase.Auth.FirebaseUser newUser = task.Result;
            SceneManager.LoadScene("menuScene");
        });
    }
コード例 #26
0
    void IntFirebase(string key)
    {
        fromLogin = true;
        FirebaseApp app = FirebaseApp.DefaultInstance;

        Firebase.Auth.FirebaseAuth auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Firebase.Auth.Credential   credential = Firebase.Auth.PlayGamesAuthProvider.GetCredential(key);

        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;
            FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(taskd =>
            {
                dependencyStatus = taskd.Result;
                if (dependencyStatus == DependencyStatus.Available)
                {
                    ;
                    if (app.Options.DatabaseUrl != null)
                    {
                        app.SetEditorDatabaseUrl(app.Options.DatabaseUrl);
                    }
                    var user = newUser;

                    //Add To databse
                    DatabaseReference reference = FirebaseDatabase.DefaultInstance.GetReference("game").Child("users").Child(user.UserId);
                    //     GameManager
                    reference.Child("uid").SetValueAsync(user.UserId);
                    reference.Child("name").SetValueAsync(user.DisplayName);
                    reference.Child("image_url").SetValueAsync(user.PhotoUrl);

                    LoadingScreen.init.SetKomplitLogin();
                }
                else
                {
                    LoadingScreen.init.Reset();
                }
            });
        });
    }
コード例 #27
0
    private Firebase.Auth.Credential GetFirebaseCredential(Task <string> googleIdTokenTask)
    {
        Debug.Log("Get firebase credential");
        Firebase.Auth.Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdTokenTask.Result, null);

        if (credential == null)
        {
            throw new System.Exception("Could not get Google Auth provider credential. Id Token provided: " + googleIdTokenTask.Result);
        }
        else
        {
            Debug.Log(credential.ToString());
            return(credential);
        }
    }
コード例 #28
0
 public override void HandleUIEvent(GameObject source, object eventData)
 {
     if (source == dialogComponent.CancelButton.gameObject)
     {
         manager.PopState();
     }
     else if (source == dialogComponent.ContinueButton.gameObject)
     {
         Firebase.Auth.Credential credential =
             Firebase.Auth.EmailAuthProvider.GetCredential(
                 dialogComponent.Email.text, dialogComponent.Password.text);
         manager.PushState(new WaitForTask(auth.CurrentUser.LinkWithCredentialAsync(credential),
                                           StringConstants.LabelLinkingAccount, true));
     }
 }
コード例 #29
0
    public async void FirebaseLogin()
    {
        auth       = Firebase.Auth.FirebaseAuth.DefaultInstance;
        credential = Firebase.Auth.FacebookAuthProvider.GetCredential(FbToken);
        bool isError = false;
        await auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                isError = true;
                LoadingCircle.SetActive(false);
                Faildtxt.SetActive(true);
                Debug.LogError("SignInWithCredentialAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                isError = true;
                //LoadingCircle.SetActive (false);
                //Faildtxt.SetActive (true);
                Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                return;
            }
            newUser = task.Result;
            Debug.LogFormat("User signed in successfully: {0} ({1})", newUser.DisplayName, newUser.UserId);
        });

        if (!isError)
        {
            user = auth.CurrentUser;
            if (user != null)
            {
                Debug.Log("Entered (user != null)");
                FireName  = user.DisplayName;
                FireEmail = user.Email;
                FireId    = user.UserId;
                photo_url = user.PhotoUrl.OriginalString;
                isFB      = true;
                if (PlayerPrefs.GetInt("firsttime", -1) == 0)
                {
                    PlayerPrefs.SetInt("firsttime", 1);
                    Player.coin += 50;
                }
                SaveSession();
                finished = true;
            }
        }
    }
コード例 #30
0
    private void AuthCallback(ILoginResult result)
    {
        if (FB.IsLoggedIn)
        {
            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
            List <string> permissions       = new List <string>();

            // AccessToken class will have session details
            var aToken = Facebook.Unity.AccessToken.CurrentAccessToken;
            // Print current access token's User ID
            Debug.Log("Token:");
            Debug.Log(aToken.UserId);
            Debug.Log(aToken.TokenString);
            //
            nameText.text = "Authenticating...";
            Firebase.Auth.Credential credential =
                Firebase.Auth.FacebookAuthProvider.GetCredential(aToken.TokenString);
            auth.SignInWithCredentialAsync(credential).ContinueWithOnMainThread(task =>
            {
                if (task.IsCanceled)
                {
                    Debug.LogError("SignInWithCredentialAsync was canceled.");
                    nameText.text = "SignInWithCredentialAsync was canceled";
                    return;
                }
                if (task.IsFaulted)
                {
                    Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
                    nameText.text = "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);
                isAuth        = true;
                UserID        = newUser.UserId;
                UserName      = newUser.DisplayName;
                nameText.text = UserName;
                GetHighScore();
            });
        }
        else
        {
            Debug.Log("User cancelled login");
            nameText.text = "...";
        }
    }