private void HandleAuthResultHandlerSignUp(AuthDataResult data, Foundation.NSError error)
        {
            if (error != null)
            {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8) // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)error.Code);
                }
                else // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)error.Code);
                }

                // Posible error codes that CreateUser method could throw
                switch (errorCode)
                {
                case AuthErrorCode.InvalidEmail:
                case AuthErrorCode.EmailAlreadyInUse:
                case AuthErrorCode.OperationNotAllowed:
                case AuthErrorCode.WeakPassword:
                default:
                    signUpResult   = false;
                    hasLoginResult = true;
                    break;
                }
            }
            else
            {
                signUpResult   = true;
                hasLoginResult = true;
            }
            tokenSource.Cancel();
        }
        void SignInOnCompletion(AuthDataResult authResult, NSError error)
        {
            if (error != null)
            {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8)                 // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)error.Code);
                }
                else                 // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)error.Code);
                }

                // Posible error codes that SignIn method with credentials could throw
                // Visit https://firebase.google.com/docs/auth/ios/errors for more information
                switch (errorCode)
                {
                case AuthErrorCode.InvalidCredential:
                case AuthErrorCode.InvalidEmail:
                case AuthErrorCode.OperationNotAllowed:
                case AuthErrorCode.EmailAlreadyInUse:
                case AuthErrorCode.UserDisabled:
                case AuthErrorCode.WrongPassword:
                default:
                    AppDelegate.ShowMessage("Could not login!", error.LocalizedDescription, NavigationController);
                    break;
                }

                return;
            }

            NavigationController.PushViewController(new UserViewController("Google"), true);
        }
Example #3
0
        public async void OnAuthenticationCompleted(GoogleOAuthToken token)
        {
            // SFSafariViewController doesn't dismiss itself
            DismissViewController(true, null);

            DisplayLoadingIndicator();

            var googleUserInfo = await _authViewModel.RetrieveGoogleUserInfoAsync(token.TokenType, token.AccessToken);

            var firebaseUserInfo = await _authViewModel.AuthenticateUserWithFirebaseAsync(googleUserInfo);

            if (firebaseUserInfo != null)
            {
                AuthCredential credential = GoogleAuthProvider.GetCredential(token.IdToken, token.AccessToken);
                AuthDataResult result     = await FirebaseManager.Auth.SignInAndRetrieveDataWithCredentialAsync(credential);

                token.SaveToDevice();
                googleUserInfo.SaveToDevice();
                firebaseUserInfo.SaveToDevice();

                PerformSegueToHome(googleUserInfo.GivenName);
            }
            else
            {
                await _authViewModel.RevokeTokenAsync(token.TokenType, token.AccessToken);

                RemoveLoadingIndicator();

                txtNotAuthorizedMessage.Text = _authViewModel.FirebaseNotAuthorizedErrorMessage;
                GoogleLoginButton.Hidden     = true;
            }
        }
        // Sign in Anonymously
        void SignInAnonymouslyCompleted(AuthDataResult authDataResult, NSError error)
        {
            if (error == null)
            {
                AppDelegate.UserUid = authDataResult.User.Uid;

                // Points to https://MyDatabaseId.firebaseio.com/users
                userNode = AppDelegate.RootNode.GetChild("users").GetChild(AppDelegate.UserUid);

                VerifyIfUserExists();
            }
            else
            {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8)                 // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)error.Code);
                }
                else                 // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)error.Code);
                }

                var title = "Anonymous sign-in failed!";

                // Posible error codes that SignInAnonymously method could throw
                // Visit https://firebase.google.com/docs/auth/ios/errors for more information
                switch (errorCode)
                {
                case AuthErrorCode.OperationNotAllowed:
                    UIAlertHelper.ShowMessage(title,
                                              "The app uses Anonymous sign-in to work correctly and seems to be disabled…\n" +
                                              "Please, go to Firebase console and enable Anonymous login.\n" +
                                              "Open «Application Output» in Xamarin Studio for more information.",
                                              NavigationController,
                                              "Ok, let me enable it!");
                    Console.WriteLine("Anonymous sign-in seems to be disabled. Please, visit the following link to know how " +
                                      "to enable it: https://firebase.google.com/docs/auth/ios/anonymous-auth#before-you-begin");
                    break;

                case AuthErrorCode.NetworkError:
                    UIAlertHelper.ShowMessage(title,
                                              "Seems to be the first time that you run the sample and you don't have access to internet.\n" +
                                              "The sample needs to run with internet at least once so you can create an Anonymous user.",
                                              NavigationController,
                                              "Ok");
                    break;

                default:
                    UIAlertHelper.ShowMessage(title,
                                              "An unknown error has ocurred…",
                                              NavigationController,
                                              "Ok");
                    break;
                }

                indicatorView.StopAnimating();
            }
        }
        async Task <bool> SignIn()
        {
            try {
                AuthDataResult authData = await auth.SignInAnonymouslyAsync();

                AppDelegate.UserUid = authData.User.Uid;
                return(true);
            } catch (NSErrorException ex) {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8)                 // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)ex.Error.Code);
                }
                else                 // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)ex.Error.Code);
                }

                var title       = "Anonymous sign-in failed!";
                var buttonTitle = "Ok";
                var message     = new StringBuilder();

                // Posible error codes that SignInAnonymously method could throw
                // Visit https://firebase.google.com/docs/auth/ios/errors for more information
                switch (errorCode)
                {
                case AuthErrorCode.OperationNotAllowed:
                    message.AppendLine("The app uses Anonymous sign-in to work correctly and seems to be disabled…");
                    message.AppendLine("Please, go to Firebase console and enable Anonymous login.");
                    message.Append("Open «Application Output» in Xamarin Studio for more information.");
                    buttonTitle = "Ok, let me enable it!";
                    Console.WriteLine("Anonymous sign-in seems to be disabled. Please, visit the following link to know how " +
                                      "to enable it: https://firebase.google.com/docs/auth/ios/anonymous-auth#before-you-begin");
                    break;

                case AuthErrorCode.NetworkError:
                    message.AppendLine("Seems to be the first time that you run the sample and you don't have access to internet.");
                    message.Append("The sample needs to run with internet at least once so you can create an Anonymous user.");
                    break;

                default:
                    message.Append("An unknown error has ocurred…");
                    break;
                }

                InvokeOnMainThread(() => {
                    indicatorView.StopAnimating();
                    UIAlertHelper.ShowMessage(title, message.ToString(), NavigationController, buttonTitle);
                });

                return(false);
            }
        }
        private async Task <IFirebaseAuthResult> SignInAsync(AuthCredential credential)
        {
            try
            {
                AuthDataResult authResult = await Auth.DefaultInstance.SignInAndRetrieveDataAsync(credential);

                return(new FirebaseAuthResult(authResult));
            }
            catch (NSErrorException ex)
            {
                throw GetFirebaseAuthException(ex);
            }
        }
Example #7
0
        public async Task <string> SignUpWithEmailPassword(string email, string password)
        {
            try
            {
                AuthDataResult user = await Auth.DefaultInstance.CreateUserAsync(email, password);

                return(await user.User.GetIdTokenAsync());
            }
            catch (Exception)
            {
                return(string.Empty);
            }
        }
        private async Task <IFirebaseAuthResult> LinkWithCredentialAsync(AuthCredential credential)
        {
            try
            {
                AuthDataResult authResult = await _user.LinkAndRetrieveDataAsync(credential);

                return(new FirebaseAuthResult(authResult));
            }
            catch (NSErrorException ex)
            {
                throw GetFirebaseAuthException(ex);
            }
        }
        public async Task <string> SignupWithEmailPasswordAsync(string email, string password)
        {
            try
            {
                AuthDataResult res = await Auth.DefaultInstance.CreateUserAsync(email, password);

                return(await Task.FromResult(res.User.Uid));
            }
            catch (NSErrorException ex)
            {
                return(await Task.FromResult("Error"));
            }
        }
        /// <summary>
        /// Signs the user in via email.
        /// </summary>
        /// <param name="email">The user’s email address.</param>
        /// <param name="password">The user’s password.</param>
        /// <returns>User account</returns>
        public async Task <IFirebaseAuthResult> SignInWithEmailAsync(string email, string password)
        {
            try
            {
                AuthDataResult authResult = await Auth.DefaultInstance.SignInAndRetrieveDataAsync(email, password);

                return(new FirebaseAuthResult(authResult));
            }
            catch (NSErrorException ex)
            {
                throw GetFirebaseAuthException(ex);
            }
        }
        void SignInOnCompletion(AuthDataResult authResult, NSError error)
        {
            if (error == null && authResult != null)
            {
                if (authType == AuthType.Phone)
                {
                    NSUserDefaults.StandardUserDefaults.RemoveObject("AuthVerificationID");
                }

                SetVerificationStatus(VerificationStatus.Success);
            }
            else
            {
                SetVerificationStatus(VerificationStatus.Failed, error.LocalizedDescription);
            }
        }
Example #12
0
        /// <inheritdoc/>
        public IObservable <Unit> SignInAnonymously()
        {
            return(Observable.Create <Unit>(
                       async observer =>
            {
                AuthDataResult authResult = null;

                try
                {
                    authResult = await Auth.DefaultInstance.SignInAnonymouslyAsync();
                }
                catch (NSErrorException ex)
                {
                    observer.OnError(GetFirebaseAuthException(ex));
                    return;
                }

                observer.OnNext(Unit.Default /*new FirebaseAuthResult(authResult)*/);
                observer.OnCompleted();
            }));
        }
Example #13
0
        /// <inheritdoc/>
        public IObservable <Unit> SignInWithEmail(string email, string password)
        {
            return(Observable.Create <Unit>(
                       async observer =>
            {
                AuthDataResult authResult = null;

                try
                {
                    authResult = await Auth.DefaultInstance.SignInWithPasswordAsync(email, password);
                }
                catch (NSErrorException ex)
                {
                    observer.OnError(GetFirebaseAuthException(ex));
                    return;
                }

                observer.OnNext(Unit.Default /*new FirebaseAuthResult(authResult)*/);
                observer.OnCompleted();
            }));
        }
Example #14
0
        private void OnFirebaseRegistration(AuthDataResult authResult, NSError error)
        {
            try
            {
                if (error != null)
                {
                    AuthErrorCode errorCode;
                    if (IntPtr.Size == 8) // 64 bits devices
                    {
                        errorCode = (AuthErrorCode)((long)error.Code);
                    }
                    else // 32 bits devices
                    {
                        errorCode = (AuthErrorCode)((int)error.Code);
                    }

                    // Posible error codes that SignIn method with email and password could throw
                    // Visit https://firebase.google.com/docs/auth/ios/errors for more information
                    switch (errorCode)
                    {
                    case AuthErrorCode.OperationNotAllowed:
                    case AuthErrorCode.InvalidEmail:
                    case AuthErrorCode.UserDisabled:
                    case AuthErrorCode.WrongPassword:
                    default:
                        // Print error
                        break;
                    }

                    return;
                }
                else
                {
                    PasswordAuthentication();
                }
            }
            catch (Exception ex)
            {
            }
        }
Example #15
0
        async void HandleAuthDataResultHandler(AuthDataResult authResult, Foundation.NSError error)
        {
            if (error != null)
            {
                //Console.WriteLine(error.UserInfo["error_name"].Description);

                if (error.UserInfo["error_name"].ToString() == "ERROR_EMAIL_ALREADY_IN_USE")
                {
                    //Console.WriteLine("DUPLICATE_EMAIL_ERROR");
                    MessagingCenter.Send <IFirebaseAuthenticator>(this, "Go");
                }
                if (error.UserInfo["error_name"].Description == "ERROR_INVALID_EMAIL")
                {
                    MessagingCenter.Send <IFirebaseAuthenticator, int>(this, "MainPageError", 0);
                }
                if (error.UserInfo["error_name"].Description == "ERROR_USER_NOT_FOUND")
                {
                    MessagingCenter.Send <IFirebaseAuthenticator, int>(this, "MainPageError", 1);
                }
                if (error.UserInfo["error_name"].Description == "ERROR_WRONG_PASSWORD")
                {
                    MessagingCenter.Send <IFirebaseAuthenticator, int>(this, "MainPageError", 2);
                }
            }

            else
            {
                if (isCreateUser == true)
                {
                    localUserData.Add("firebaseID", authResult.User.Uid);

                    newClient.UploadValues("http://www.cvx4u.com/web_service/create_user.php", localUserData);
                }
                await App.currentUser.SetUserInfo(authResult.User.Uid);

                await Xamarin.Forms.Application.Current.MainPage.Navigation.PushAsync(new CandidateDashboard());
            }
        }
        private void HandleAuthResultHandlerGoogleSignin(AuthDataResult result, NSError error)
        {
            if (error != null)
            {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8) // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)error.Code);
                }
                else // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)error.Code);
                }

                // Posible error codes that SignIn method with credentials could throw
                switch (errorCode)
                {
                case AuthErrorCode.InvalidCredential:
                case AuthErrorCode.InvalidEmail:
                case AuthErrorCode.OperationNotAllowed:
                case AuthErrorCode.EmailAlreadyInUse:
                case AuthErrorCode.UserDisabled:
                case AuthErrorCode.WrongPassword:
                default:
                    loginResult    = false;
                    hasLoginResult = true;
                    break;
                }
            }
            else
            {
                loginResult    = true;
                hasLoginResult = true;
            }

            tokenSource.Cancel();
        }
Example #17
0
        public async Task <string> SignUpWithEmailPassword(string email, string password)
        {
            if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(password))
            {
                try
                {
                    AuthDataResult user = await Auth.DefaultInstance.CreateUserAsync(email, password);

                    return(await user.User.GetIdTokenAsync(false));
                }
                catch (NSErrorException ex)
                {
                    AuthErrorCode errorCode;
                    if (IntPtr.Size == 8) // 64 bits devices
                    {
                        errorCode = (AuthErrorCode)((long)ex.Error.Code);
                    }
                    else // 32 bits devices
                    {
                        errorCode = (AuthErrorCode)((int)ex.Error.Code);
                    }
                    switch (errorCode)
                    {
                    case AuthErrorCode.UserNotFound:
                        return("ERROR_USER_NOT_FOUND");

                    case AuthErrorCode.InvalidEmail:
                        return("ERROR_INVALID_EMAIL");

                    default:
                        return("");
                    }
                }
            }
            return("ERROR_EMAIL_OR_PASSWORD_MISSING");
        }
Example #18
0
        void SignInOnCompletion(AuthDataResult authResult, NSError error)
        {
            indicatorView.StopAnimating();

            if (error != null)
            {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8)                 // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)error.Code);
                }
                else                 // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)error.Code);
                }

                // Posible error codes that SignIn method with email and password could throw
                // Visit https://firebase.google.com/docs/auth/ios/errors for more information
                switch (errorCode)
                {
                case AuthErrorCode.OperationNotAllowed:
                case AuthErrorCode.InvalidEmail:
                case AuthErrorCode.UserDisabled:
                case AuthErrorCode.WrongPassword:
                default:
                    AppDelegate.ShowMessage("Could not login!", error.LocalizedDescription, NavigationController);
                    break;
                }

                return;
            }

            NSUserDefaults.StandardUserDefaults.RemoveObject("AuthVerificationID");

            NavigationController.PushViewController(new UserViewController("Firebase2"), true);
        }
        private void HandleAuthResultLoginHandler(AuthDataResult data, Foundation.NSError error)
        {
            if (error != null)
            {
                AuthErrorCode errorCode;
                if (IntPtr.Size == 8) // 64 bits devices
                {
                    errorCode = (AuthErrorCode)((long)error.Code);
                }
                else // 32 bits devices
                {
                    errorCode = (AuthErrorCode)((int)error.Code);
                }

                // Posible error codes that SignIn method with email and password could throw
                // Visit https://firebase.google.com/docs/auth/ios/errors for more information
                switch (errorCode)
                {
                case AuthErrorCode.OperationNotAllowed:
                case AuthErrorCode.InvalidEmail:
                case AuthErrorCode.UserDisabled:
                case AuthErrorCode.WrongPassword:
                default:
                    loginResult    = false;
                    hasLoginResult = true;
                    break;
                }
            }
            else
            {
                // Do your magic to handle authentication result
                loginResult    = true;
                hasLoginResult = true;
            }
            tokenSource.Cancel();
        }
        private void actionHandler(AuthDataResult authResult, NSError error)
        {
            if (error != null)
            {
                return;
            }
            else
            {
                if (authResult != null && authResult.User != null)
                {
                    var user = new Model.User();
                    user.Uid             = authResult.User.Uid;
                    user.DisplayName     = authResult.User.DisplayName;
                    user.PhoneNumber     = authResult.User.PhoneNumber;
                    user.Email           = authResult.User.Email;
                    user.PhotoUrl        = authResult.User.PhotoUrl;
                    user.ProviderId      = authResult.User.ProviderId;
                    user.IsEmailVerified = authResult.User.IsEmailVerified;

                    Settings.FirebaseLoggedInUser = user;
                }
                NavigateToView();
            }
        }
Example #21
0
 public AuthResultWrapper(AuthDataResult authResult)
 {
     _authResult = authResult ?? throw new ArgumentNullException(nameof(authResult));
 }
 public AuthResultWrapper(AuthDataResult authResult)
 {
     _authResult = authResult;
 }
Example #23
0
 public FirebaseAuthResult(AuthDataResult authResult)
 {
     _authResult = authResult;
 }
        public async Task <string> LoginWithEmailPassword(string email, string password)
        {
            AuthDataResult user = await Auth.DefaultInstance.SignInWithPasswordAsync(email, password);

            return(await user.User.GetIdTokenAsync(false));
        }