public void AuthenticateCAS(string ticket, out AppUserTypes result, out User user) { //CODE OMMITED FOR SECURITY REASONS string netid = ticket; if (netid != null) { user = uiw.Repository<User>().GetByIdentity(netid); if (user == null) { result = RegisterUser(netid); user = uiw.Repository<User>().GetByIdentity(netid); } if (user != null) { if (user.RoleId == 1) { UpdateTeacherCourses(user.Username); result = AppUserTypes.teacher; } else if (user.RoleId == 2) { UpdateStudentCourses(user.Username); result = AppUserTypes.student; } else if (user.RoleId == 3) { result = AppUserTypes.admin; } } } }
private void SignIn(User user) { List<Claim> claims = new List<Claim>{ new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", user.Username), new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", user.Id.ToString()), new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", "Surveys") }; ClaimsIdentity identity = new System.Security.Claims.ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role); HttpContext.GetOwinContext().Authentication.SignIn(new AuthenticationProperties() { IsPersistent = true }, identity); }