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

            using (AuthRepository _repo = new AuthRepository())
            {
                IdentityUser user = await _repo.FindUser(context.UserName, context.Password);

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

                var identity = new ClaimsIdentity(context.Options.AuthenticationType);

                identity.AddClaim(new Claim(ClaimTypes.Name, user.UserName));

                var roles = await _repo.FindUserRoles(user.Id);

                foreach (var r in roles)
                {
                    identity.AddClaim(new Claim(ClaimTypes.Role, r));
                }
                //identity.AddClaim(new Claim("sub", context.UserName));
                
                context.Validated(identity);
            }
        }
Esempio n. 2
0
 public UserProfileRepository()
 {
     _db = new AuthContext();
     _au = new AuthRepository();
 }
Esempio n. 3
0
 public AccountController()
 {
     _repo = new AuthRepository();
     _upr = new UserProfileRepository();
 }
Esempio n. 4
0
 public ProfileController()
 {
     _repo = new UserProfileRepository();
     _auth = new AuthRepository();
 }
Esempio n. 5
0
 public RoleController()
 {
     _auth = new AuthRepository();
 }