示例#1
0
        public async Task LoginAsync(string email, string password)
        {
            try
            {
                if (CrossConnectivity.Current.IsConnected == true)
                {
                    var auth = await _firebaseAuthProvider.SignInWithEmailAndPasswordAsync(email, password);

                    await SecureStorage.SetAsync("token", auth.RefreshToken);

                    await SecureStorage.SetAsync("userId", auth.User.LocalId);
                }
                else
                {
                    throw new Exception("Server is unavailable right now, try again later");
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains("INVALID_PASSWORD") || e.Message.Contains("EMAIL_NOT_FOUND"))
                {
                    throw new Exception("Your email or password are not valid", e);
                }
                else
                {
                    throw new Exception(e.Message, e);
                }
            }
        }
        public async Task <FirebaseAuthLink> LoginUser(string email, string password)
        {
            var auth = await authProvider.SignInWithEmailAndPasswordAsync(email, password);

            SaveAuth(auth);
            // save the new token each time it is refreshed
            auth.FirebaseAuthRefreshed += (s, e) => SaveAuth(e.FirebaseAuth);
            // use the token and let it refresh automatically (can be part of FirebaseOptions for access to Firebase DB)
            return(await auth.GetFreshAuthAsync());
        }
示例#3
0
        public async Task <LoginStatus> Login(Login login)
        {
            var auth = await authProvider.SignInWithEmailAndPasswordAsync(login.Email, login.Password);

            if (auth is null || auth.User is null)
            {
                throw new FirebaseAuthException(string.Empty, string.Empty, string.Empty, new InvalidOperationException());
            }

            return(new LoginStatus(auth.User.LocalId, auth.User.Email, auth.User.IsEmailVerified, auth.ExpiresIn, auth.FirebaseToken, auth.RefreshToken));
        }
示例#4
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            MyUser CurUser = new MyUser() //User given info
            {
                Email = textbox1.Text,
            };

            MyUser.getEmail(CurUser);
            try
            {
                _ = provider.SignInWithEmailAndPasswordAsync(textbox1.Text, textbox2.Text).Result;
                Response.Redirect("WebForm6.aspx");
            }
            catch
            {
                Response.Write("<script>alert('The email and password you entered did not match our records!')</script>");
            }
        }
        public void LoginShouldGetAndSaveUserIdentity()
        {
            var expected = new FirebaseAuthLink(_authProvider, new FirebaseAuth())
            {
                FirebaseToken =
                    "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBtYWxlc3VhZGEgZWxlbWVudHVtIGFudGUgYXQgZmV1Z2lh",
                User = new User {
                    Email = "*****@*****.**", LocalId = "TG9yZW0gaXBzdW0="
                }
            };

            _authProvider.SignInWithEmailAndPasswordAsync("*****@*****.**", "pass").Returns(expected);

            _sut.Login("*****@*****.**", "pass");

            var actual = _sut.Identity;

            actual.FirebaseToken.Should()
            .Be(
                "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBtYWxlc3VhZGEgZWxlbWVudHVtIGFudGUgYXQgZmV1Z2lh");
            actual.User.LocalId.Should().Be("TG9yZW0gaXBzdW0=");
        }
示例#6
0
        public async Task <IActionResult> LoginAsync([FromForm] LoginViewModel login)
        {
            try
            {
                var auth = await firebaseAuthProvider.SignInWithEmailAndPasswordAsync(login.Email, login.Password);

                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);

                identity.AddClaim(new Claim("Firebase-Token", auth.FirebaseToken));
                identity.AddClaim(new Claim(ClaimTypes.Role, "Administrator"));

                var claimsPrincipal = new ClaimsPrincipal(identity);

                await HttpContext.SignInAsync(claimsPrincipal);

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Email", ex.Message);
                return(View(login));
            }
        }
示例#7
0
 public void LoginUser(string email, string password)
 {
     FirebaseAuth = _firebaseAuthProvider.SignInWithEmailAndPasswordAsync(email, password).Result;
 }
示例#8
0
 public void Login(string user, string password)
 {
     Identity = _authProvider.SignInWithEmailAndPasswordAsync(user, password).Result;
 }
示例#9
0
        public async Task <string> GenerateUserToken(string email, string password)
        {
            var auth = await _authProvider.SignInWithEmailAndPasswordAsync(email, password);

            return(auth.FirebaseToken);
        }