Exemplo n.º 1
0
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            UserViewModel usermodel;

            using (SchoolServiceContext _repo = new SchoolServiceContext())
            {
                Users user = _repo.Users.Where(u => u.UserName == context.UserName && u.UserPassword == context.Password).FirstOrDefault();
                if (user == null)
                {
                    context.SetError("invalid_grant", "The user name or password is incorrect.");
                    return;
                }
                usermodel = user;
            }
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim(ClaimTypes.Sid, Convert.ToString(usermodel.Id)));
            identity.AddClaim(new Claim(ClaimTypes.Name, usermodel.UserName));

            context.Validated(identity);
            //context.Validated(new ClaimsIdentity(context.Options.AuthenticationType));
        }