public IActionResult Login(AuthUser authUser) { try { if (ModelState.IsValid) { var loginResponse = AuthenticationHelpers.VerifyLogin(authUser); if (loginResponse != null) { var projectDetails = loginResponse.WebsiteDetails; var userDetails = loginResponse.UserDetails; var developerDetails = loginResponse.DeveloperContactDetails; var claims = new List <Claim> { new Claim(ClaimTypes.Role, "Admin"), new Claim("UserAuthId", loginResponse.DeveloperId) }; if (!string.IsNullOrEmpty(loginResponse.SchemaId)) { claims.Add(new Claim("SchemaId", loginResponse.SchemaId)); } if (!string.IsNullOrEmpty(loginResponse.EntityName)) { claims.Add(new Claim("EntityName", loginResponse.EntityName)); } if (!string.IsNullOrEmpty(loginResponse.DeveloperId)) { claims.Add(new Claim("DeveloperId", loginResponse.DeveloperId)); } if (userDetails != null) { if (!string.IsNullOrEmpty(userDetails.UserName)) { claims.Add(new Claim("Username", userDetails.UserName)); } if (!string.IsNullOrEmpty(userDetails.UserId)) { claims.Add(new Claim("WebsiteUserId", userDetails.UserId)); } if (!string.IsNullOrEmpty(userDetails.AccessType)) { claims.Add(new Claim("AccessType", userDetails.AccessType)); } if (userDetails.Contact != null && !string.IsNullOrEmpty(userDetails.Contact.FullName)) { claims.Add(new Claim("CustomerName", userDetails.Contact.FullName)); } if (userDetails.Contact != null && !string.IsNullOrEmpty(userDetails.Contact.Email)) { claims.Add(new Claim("CustomerEmail", userDetails.Contact.Email)); } if (userDetails.Contact != null && !string.IsNullOrEmpty(userDetails.Contact.PhoneNumber)) { claims.Add(new Claim("CustomerPhoneNumber", userDetails.Contact.PhoneNumber)); } } if (projectDetails != null) { if (!string.IsNullOrEmpty(projectDetails.ProjectId)) { claims.Add(new Claim("ProjectId", projectDetails.ProjectId)); } if (!string.IsNullOrEmpty(projectDetails.WebsiteUrl)) { claims.Add(new Claim("WebsiteUrl", projectDetails.WebsiteUrl)); claims.Add(new Claim("Domain", projectDetails.WebsiteUrl)); } if (!string.IsNullOrEmpty(projectDetails.WebsiteId)) { claims.Add(new Claim("CustomerId", projectDetails.WebsiteId)); } } if (developerDetails != null) { if (!string.IsNullOrEmpty(developerDetails.Email)) { claims.Add(new Claim("DeveloperEmail", developerDetails.Email)); } } var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity)); if (IsHostedOnAlicloud()) { Response.Cookies.Append("CLOUD_PROVIDER", "ALI_CLOUD"); } return(Ok("success")); } else { return(Ok("invalid")); } } else { return(Ok("invalid")); } } catch (Exception ex) { return(BadRequest("invalid")); } }
private bool VerifyLogin(AuthUser authUser) { var loginResponse = AuthenticationHelpers.VerifyLogin(authUser); return(authUser != null); }