Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        user = auth.CurrentUser;

        if (user != null)
        {
            // テキストの表示
            this.userName.text = user.DisplayName;
            Debug.Log(user.DisplayName);
        }

        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://hamukatsu2-9bebb.firebaseio.com/");

        // Get the root reference location of the database.
        reference = FirebaseDatabase.DefaultInstance.RootReference;

        Debug.Log(user.UserId);
        Debug.Log(user.DisplayName);


        User newUser = new User(user.DisplayName);

        string json = JsonUtility.ToJson(newUser);

        reference.Child("users").Child(user.UserId).SetRawJsonValueAsync(json);

        FirebaseDatabase.DefaultInstance.GetReference("users").ValueChanged += HandleValueChanged;
    }
Ejemplo n.º 2
0
    public void GetOTP()                                                                 //Function to send otp to the valid user mobile number
    {
        Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;    //Firebase auth instance creation to start authorization activity


        uint phoneAuthTimeoutMs    = 10000;                                              //
        PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber("+91" + mobile.text, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("1");

            //OnVerifyOTP(credential);
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("Verification failed");
        },
                                   codeSent: (id, token) =>
        {
            phoneVerificationId = id;
            Debug.Log("+91" + mobile.text);
            Debug.Log("SMS Has been sent and the verification Id is  " + id);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            Debug.Log("Code Retrieval Time out");
        });
    }
Ejemplo n.º 3
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");
        }
    }
        private Task <PhoneNumberVerificationResult> VerifyPhoneNumberAsync(Firebase.Auth.FirebaseAuth auth, IPhoneMultiFactorInfo phoneMultiFactorInfo, IMultiFactorSession multiFactorSession, TimeSpan timeout, bool?requiresSmsValidation = null)
        {
            var activity = CrossCurrentActivity.Current.Activity ?? throw new NullReferenceException("current activity is null");

            var tcs       = new TaskCompletionSource <PhoneNumberVerificationResult>();
            var callbacks = new Callbacks(tcs);

            var builder = PhoneAuthOptions.NewBuilder(auth)
                          .SetActivity(activity)
                          .SetCallbacks(callbacks)
                          .SetMultiFactorHint(phoneMultiFactorInfo.ToNative())
                          .SetMultiFactorSession(multiFactorSession.ToNative())
                          .SetTimeout(new Java.Lang.Long((long)timeout.TotalMilliseconds), TimeUnit.Milliseconds);

            if (requiresSmsValidation.HasValue)
            {
                builder.RequireSmsValidation(requiresSmsValidation.Value);
            }

            auth.FirebaseAuthSettings.SetAutoRetrievedSmsCodeForPhoneNumber(null, null);

            PhoneAuthProvider.VerifyPhoneNumber(builder.Build());

            return(tcs.Task);
        }
Ejemplo n.º 5
0
 private void InitializeFirebase()
 {
     Debug.Log("Setting up Firebase Auth");
     Auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     FirebaseApp.DefaultInstance.SetEditorDatabaseUrl(databaseURL);
     Reference = FirebaseDatabase.DefaultInstance.RootReference;
 }
Ejemplo n.º 6
0
    public void Login()
    {
        email    = emailField.GetComponent <Text>().text;
        password = passwordField.GetComponent <Text>().text;

        authReference = Firebase.Auth.FirebaseAuth.DefaultInstance;

        if (!string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(email))
        {
            authReference.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task =>
            {
                if (task.IsCanceled)
                {
                    print("Login User was cancelled");
                    return;
                }
                if (task.IsFaulted)
                {
                    print("Login User encountered error");
                    return;
                }
                print("LOGIN SUCCESSFUL");
                SceneManager.LoadScene("HomeScene");
            });
        }
        else
        {
            print("Input is Empty");
        }
    }
Ejemplo n.º 7
0
 void InitializeFirebase()
 {
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     user = auth.CurrentUser;
     //auth.StateChanged += AuthStateChanged;
     //AuthStateChanged(this, null);
 }
Ejemplo n.º 8
0
 // Start is called before the first frame update
 void Start()
 {
     authManager.InitializeFirebase();
     dbManager.Awake();
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     signinFacebookButton.onClick.AddListener(OnSignInFacebook);
 }
Ejemplo n.º 9
0
        public void CreateUser(string[] context, Action <Firebase.Auth.FirebaseUser> onCompleted, Action onFaulted, Action onCanceled)
        {
            if (context == null || context.Length != 2)
            {
                DebugUtil.D.LogError("EmailAuth CreateUser context error.");
                onFaulted.SafeCall();
                return;
            }

            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
            auth.CreateUserWithEmailAndPasswordAsync(context[0], context[1]).ContinueWith(
                task =>
            {
                if (task.IsCanceled)
                {
                    DebugUtil.D.LogError("EmailAuth CreateUser was canceled.");
                    onCanceled.SafeCall();
                    return;
                }

                if (task.IsFaulted)
                {
                    DebugUtil.D.LogError("EmailAuth CreateUser encountered an error: " + task.Exception);
                    onFaulted.SafeCall();
                    return;
                }

                if (task.IsCompleted)
                {
                    Firebase.Auth.FirebaseUser newUser = task.Result;
                    onCompleted.SafeCall(newUser);
                }
            }
                );
        }
Ejemplo n.º 10
0
 void InitializeFirebase()
 {
     FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://grapphia.firebaseio.com/");
     reference = FirebaseDatabase.DefaultInstance.RootReference;
     auth      = Firebase.Auth.FirebaseAuth.DefaultInstance;
     user_fb   = auth.CurrentUser;
 }
Ejemplo n.º 11
0
    /// <summary>
    /// Register for events at the CloudRecoBehaviour
    /// </summary>
    void Start()
    {
        authReference = Firebase.Auth.FirebaseAuth.DefaultInstance;
        authUser      = authReference.CurrentUser;
        if (authUser == null)
        {
            SceneManager.LoadScene("LoginScene");
        }

        storage = Firebase.Storage.FirebaseStorage.DefaultInstance;

        FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://card-677f1.firebaseio.com/");

        // Register this event handler at the CloudRecoBehaviour
        m_CloudRecoBehaviour = GetComponent <CloudRecoBehaviour>();
        if (m_CloudRecoBehaviour)
        {
            m_CloudRecoBehaviour.RegisterEventHandler(this);
        }

        /*
         * if (m_CloudActivityIcon)
         * {
         *  m_CloudActivityIcon.enabled = false;
         * } */
    }
Ejemplo n.º 12
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);
        });
    }
Ejemplo n.º 13
0
    public void Push()
    {
        string newEmail    = "";
        string newPassword = "";

        FirebaseAuth.DefaultInstance.SignInWithEmailAndPasswordAsync(newEmail + "@unreal.com", newPassword).ContinueWith(task =>
        {
            if (task.IsCanceled)
            {
                Debug.LogError("SignInWithEmailAndPasswordAsync was canceled.");
                return;
            }
            if (task.IsFaulted)
            {
                Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception);
                return;
            }

            newUser = task.Result;
            //changetextsuccess = true;
            Debug.LogFormat("User signed in successfully: {0} ({1})",
                            newUser.DisplayName, newUser.UserId);
            ///start updating
            auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        });
    }
Ejemplo n.º 14
0
        public void SignIn(string[] context, Action <Firebase.Auth.FirebaseUser> onCompleted, Action onFaulted, Action onCanceled)
        {
            Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

            auth.SignInAnonymouslyAsync().ContinueWith(
                task =>
            {
                if (task.IsCanceled)
                {
                    DebugUtil.D.LogError("SignInAnonymouslyAsync was canceled.");
                    onCanceled.SafeCall();
                    return;
                }

                if (task.IsFaulted)
                {
                    DebugUtil.D.LogError("SignInAnonymouslyAsync encountered an error: " + task.Exception);
                    onFaulted.SafeCall();
                    return;
                }

                if (task.IsCompleted)
                {
                    Firebase.Auth.FirebaseUser newUser = task.Result;
                    onCompleted.SafeCall(newUser);
                }
            }
                );
        }
Ejemplo n.º 15
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;
        }
    }
Ejemplo n.º 16
0
        public AuthWrapper(Firebase.Auth.FirebaseAuth auth)
        {
            _auth = auth ?? throw new ArgumentNullException(nameof(auth));

            _auth.AuthState += OnAuthStateChanged;
            _auth.IdToken   += OnIdTokenChanged;
        }
Ejemplo n.º 17
0
    public void NewSignIn()
    {
        auth = FirebaseAuth.DefaultInstance;
        string            phoneNumber        = "+79244225416";
        uint              phoneAuthTimeoutMs = 100000;
        PhoneAuthProvider provider           = PhoneAuthProvider.GetInstance(auth);

        provider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
                                   verificationCompleted: (credential) =>
        {
            Debug.Log("Completed");
        },
                                   verificationFailed: (error) =>
        {
            Debug.Log("error");
        },
                                   codeSent: (id, token) =>
        {
            Debug.Log(id);
        },
                                   codeAutoRetrievalTimeOut: (id) =>
        {
            Debug.Log("Phone Auth, auto-verification timed out");
        });
    }
Ejemplo n.º 18
0
 void initializeFirebase()
 {
     FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://strokesurvivors-605a1.firebaseio.com/");
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     auth.StateChanged += AuthStateChanged;
     AuthStateChanged(this, null);
 }
Ejemplo n.º 19
0
 void InitializeFirebase()
 {
     Debug.Log("Setting up Firebase Auth");
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     auth.StateChanged += AuthStateChanged;
     AuthStateChanged(this, null);
 }
Ejemplo n.º 20
0
 protected void InitializeFirebase()
 {
     DebugLog("Setting up Firebase Auth");
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     auth.StateChanged   += AuthStateChanged;
     auth.IdTokenChanged += IdTokenChanged;
     // Specify valid options to construct a secondary authentication object.
     if (otherAuthOptions != null &&
         !(String.IsNullOrEmpty(otherAuthOptions.ApiKey) ||
           String.IsNullOrEmpty(otherAuthOptions.AppId) ||
           String.IsNullOrEmpty(otherAuthOptions.ProjectId)))
     {
         try
         {
             otherAuth = Firebase.Auth.FirebaseAuth.GetAuth(Firebase.FirebaseApp.Create(
                                                                otherAuthOptions, "Secondary"));
             otherAuth.StateChanged   += AuthStateChanged;
             otherAuth.IdTokenChanged += IdTokenChanged;
         }
         catch (Exception)
         {
             DebugLog("ERROR: Failed to initialize secondary authentication object.");
         }
     }
     AuthStateChanged(this, null);
 }
Ejemplo n.º 21
0
 // Track state changes of the auth object.
 void AuthStateChanged(object sender, System.EventArgs eventArgs)
 {
     Firebase.Auth.FirebaseAuth senderAuth = sender as Firebase.Auth.FirebaseAuth;
     Firebase.Auth.FirebaseUser user       = null;
     if (senderAuth != null)
     {
         userByAuth.TryGetValue(senderAuth.App.Name, out user);
     }
     if (senderAuth == auth && senderAuth.CurrentUser != user)
     {
         bool signedIn = user != senderAuth.CurrentUser && senderAuth.CurrentUser != null;
         if (!signedIn && user != null)
         {
             DebugLog("Signed out " + user.UserId);
         }
         user = senderAuth.CurrentUser;
         userByAuth[senderAuth.App.Name] = user;
         if (signedIn)
         {
             DebugLog("AuthStateChanged Signed in " + user.UserId);
             displayName = user.DisplayName ?? "";
             DisplayDetailedUserInfo(user, 1);
         }
     }
 }
Ejemplo n.º 22
0
    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);
            }
        });
    }
Ejemplo n.º 23
0
 void InitializeFirebase()
 {
     console.text       = "Setting up Firebase Auth";
     auth               = Firebase.Auth.FirebaseAuth.DefaultInstance;
     auth.StateChanged += AuthStateChanged;
     AuthStateChanged(this, null);
 }
Ejemplo n.º 24
0
 void Awake()
 {
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     DatabaseManager.sharedInstance.GetReader(auth.CurrentUser.UserId, result => {
         Debug.Log(result.email);
         profilePanel.GetComponent <Profile>().Display(result);
     });
 }
Ejemplo n.º 25
0
 void Start()
 {
     errorText.SetActive(false);
     emailSignInException = "";
     auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
     resendOTPText.SetActive(false);
     resendOTPButton.SetActive(false);
 }
Ejemplo n.º 26
0
 // Track ID token changes.
 void IdTokenChanged(object sender, System.EventArgs eventArgs)
 {
     Firebase.Auth.FirebaseAuth senderAuth = sender as Firebase.Auth.FirebaseAuth;
     if (senderAuth == auth && senderAuth.CurrentUser != null && !fetchingToken)
     {
         senderAuth.CurrentUser.TokenAsync(false).ContinueWithOnMainThread(
             task => DebugLog(String.Format("Token[0:8] = {0}", task.Result.Substring(0, 8))));
     }
 }
Ejemplo n.º 27
0
    public void SignOut()
    {
        auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        Debug.Log("user signed out and removed from remember-me option , need to enter credentials on the next app open");
        PlayerPrefs.SetInt("rememberUserLogin", 0);

        auth.SignOut();
        SceneManager.LoadScene("SignIn");
    }
Ejemplo n.º 28
0
    //  DatabaseReference reference;

    // Start is called before the first frame update
    void Start()
    {
        auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
        // Set up the Editor before calling into the realtime database.
        //FirebaseApp.DefaultInstance.SetEditorDatabaseUrl("https://voter-41176.firebaseio.com/");

        // Get the root reference location of the database.
        //reference = FirebaseDatabase.DefaultInstance.RootReference;
    }
Ejemplo n.º 29
0
 void InitializeFirebase()
 {
     Debug.Log("Setting up Firebase Auth");
     auth      = Firebase.Auth.FirebaseAuth.DefaultInstance;
     reference = FirebaseDatabase.DefaultInstance.RootReference;
     StartCoroutine(CheckAutoLogin());
     auth.StateChanged += AuthStateChanged;
     AuthStateChanged(this, null);
 }
    void Awake()
    {
        //Setup for Google Sign In
        configuration = new GoogleSignInConfiguration
        {
            WebClientId    = webClientId,
            RequestIdToken = true
        };

        auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
    }