Exemplo n.º 1
0
        public static UserAccountManager Create(
            IdentityFactoryOptions <UserAccountManager> options,
            IOwinContext context)
        {
            DbContext          forumContext = context.Get <DbContext>();
            UserAccountManager manager      = new UserAccountManager(new UserStore <UserAccount>(forumContext));

            manager.PasswordValidator = new PasswordValidator
            {
                RequireDigit     = true,
                RequiredLength   = 6,
                RequireLowercase = true,
                RequireUppercase = true
            };

            manager.UserValidator = new UserValidator <UserAccount>(manager)
            {
                RequireUniqueEmail = true
            };
            return(manager);
        }
Exemplo n.º 2
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            UserAccountManager accountManager =
                context.OwinContext.Get <UserAccountManager>("AspNet.Identity.Owin:"
                                                             + typeof(UserAccountManager).AssemblyQualifiedName);

            UserAccount user = await accountManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("AuthorizationError", "The username or password is incorrect");
            }
            else
            {
                ClaimsIdentity ident = await accountManager.CreateIdentityAsync(user, "Custom");

                AuthenticationTicket ticket = new AuthenticationTicket(ident, new AuthenticationProperties());
                context.Validated(ticket);
                context.Request.Context.Authentication.SignIn(ident);
            }
        }