public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            var userLogic = new UserLogic();

            userLogic.UserManager = context.OwinContext.Get <AppUserManager>();
            userLogic.RoleManager = context.OwinContext.Get <AppRoleManager>();

            var userModel = userLogic.AuthenticateUser(context.UserName, context.Password);

            if (userModel == null)
            {
                context.SetError("Invalid Credentials");
                return;
            }
            else
            {
                var identity = userLogic.CreateClaimsIdentity(userModel.UserId, context.Options.AuthenticationType);
                identity.AddClaim(new Claim("UserId", userModel.UserId));
                identity.AddClaim(new Claim("UserName", userModel.UserName));

                AuthenticationProperties prop   = CreateAuthenticationProperties(userModel);
                AuthenticationTicket     ticket = new AuthenticationTicket(identity, prop);
                context.Validated(ticket);
            }
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            //context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin",new[] { "http://"+context.Request.Host.Value });
            UserLogic logic = new UserLogic();

            logic.UserManager = context.OwinContext.GetUserManager <LicUserManager>();
            logic.RoleManager = context.OwinContext.GetUserManager <LicRoleManager>();

            User user = logic.AuthenticateUser(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("", "invalid grant");
                return;
            }

            var identity = logic.CreateClaimsIdentity(user.UserId, context.Options.AuthenticationType);
            //var identity1 = logic.CreateClaimsIdentity(user.UserId, CookieAuthenticationDefaults.AuthenticationType);
            AuthenticationProperties properties = CreateProperties(user);


            var authTicket = new AuthenticationTicket(identity, properties);

            context.Validated(authTicket);
            // context.Request.Context.Authentication.SignIn(identity1);
        }
Пример #3
0
        public Boolean AuthenticateUser(string username, string password, ref string message)
        {
            Boolean ret = false;

            ret = userLogic.AuthenticateUser(username, password, ref message);

            return(ret);
        }
Пример #4
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(txtUsername.Text))
            {
                MessageBox.Show("Gebruikersnaam is niet ingevuld!");
                return;
            }

            if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("Wachtwoord is niet ingevuld!");
                return;
            }

            if (!PingHost("192.168.20.221"))
            {
                MessageBox.Show("Kan geen verbinding maken met de database.\r\nBent u ingelogd op het juiste netwerk?");
                return;
            }

            try
            {
                var userLogic = new UserLogic(new UserOracleContext());

                User = userLogic.AuthenticateUser(txtUsername.Text, userLogic.GetHashedPassword(txtPassword.Text));

                Properties.Settings.Default.Username = User.Username;
                Properties.Settings.Default.Save();

                DialogResult = DialogResult.OK;
                Close();
            }
            catch (InvalidCredentialException ex)
            {
                MessageBox.Show(ex.Message);
                txtPassword.Text = string.Empty;
            }
        }
Пример #5
0
        public void AuthenticateUser()
        {
            var data = logic.AuthenticateUser("*****@*****.**", "Test@1234");

            Assert.IsNotNull(data);
        }