Example #1
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "http://localhost:53695" });
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Credentials", new[] { "true" });

            var user = await _userManager.FindAsync(context.UserName, context.Password);

            if (user == null)
            {
                context.SetError("invalid_grant", "The user name or password is incorrect.");
                return;
            }

            var oAuthIdentity = await user.GenerateUserIdentityAsync(_userManager,
                                                                     OAuthDefaults.AuthenticationType);

            var cookiesIdentity = await user.GenerateUserIdentityAsync(_userManager,
                                                                       CookieAuthenticationDefaults.AuthenticationType);

            var properties = CreateProperties(user.UserName);
            var ticket     = new AuthenticationTicket(oAuthIdentity, properties);

            context.Validated(ticket);
            context.Request.Context.Authentication.SignIn(new AuthenticationProperties
            {
                IsPersistent = true
            }, cookiesIdentity);
        }
Example #2
0
        private async Task <bool> IsUserBanned(string userName, string password)
        {
            var user = await _userManager.FindAsync(userName, password) ?? await _userManager.FindByPhoneNumberAsUserNameAsync(userName, password);

            return(user?.IsBanned ?? false);
        }