public static SecurityUserManager Create(IdentityFactoryOptions <SecurityUserManager> options,
                                                 IOwinContext context)
        {
            var manager = new SecurityUserManager(new UserStore(context.Get <UserRepository>()));

            manager.PasswordHasher = new AppPasswordHasher();
            return(manager);
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            SecurityUserManager userManager = context.OwinContext.Get <SecurityUserManager>("AspNet.Identity.Owin:"
                                                                                            + typeof(SecurityUserManager).AssemblyQualifiedName);

            // string hashedPassword = _securityHelper.HashPassword(context.Password);
            AppUser user = await userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The username or password is incorrect");
            }
            else
            {
                ClaimsIdentity ident = await userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);

                AuthenticationTicket ticket = new AuthenticationTicket(ident, new AuthenticationProperties());
                context.Validated(ticket);

                context.Request.Context.Authentication.SignIn(ident);
            }
        }