public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            using (IdentityManager identityManager = _identityManagerFactory.CreateStoreManager())
            {
                if (!await identityManager.Passwords.CheckPasswordAsync(context.UserName, context.Password))
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }

                string userId = await identityManager.Logins.GetUserIdForLocalLoginAsync(context.UserName);

                IEnumerable <Claim> claims = await GetClaimsAsync(identityManager, userId);

                ClaimsIdentity oAuthIdentity = CreateIdentity(identityManager, claims,
                                                              context.Options.AuthenticationType);
                ClaimsIdentity cookiesIdentity = CreateIdentity(identityManager, claims,
                                                                _cookieOptions.AuthenticationType);
                AuthenticationProperties properties = await CreatePropertiesAsync(identityManager, userId);

                AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties);
                context.Validated(ticket);
                context.Request.Context.Authentication.SignIn(cookiesIdentity);
            }
        }