public async Task <IViewComponentResult> InvokeAsync() { if (User.Identity.IsAuthenticated) { var identity = (System.Security.Claims.ClaimsIdentity)User.Identity; var email = identity.Claims.Where(w => w.Type == System.Security.Claims.ClaimTypes.Email).Select(s => s.Value)?.FirstOrDefault()?.ToString(); CorporateUserModel user = await _corporateUserQuery.GetByEmail(email); return(View("/Areas/Corporate/Views/Shared/Components/CorporateHeader/CorporateHeader.cshtml", user)); } return(View("/Areas/Corporate/Views/Shared/Components/CorporateHeader/CorporateHeader.cshtml")); }
public async Task <bool> SignIn(HttpContext context, string email, CorporateUserModel user) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, user.Name), new Claim(ClaimTypes.Email, user.Email), new Claim(ClaimTypes.Role, "CorporateAdmin") }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { AllowRefresh = false, // Refreshing the authentication session should be allowed. ExpiresUtc = DateTimeOffset.UtcNow.AddDays(2), // The time at which the authentication ticket expires. A // value set here overrides the ExpireTimeSpan option of // CookieAuthenticationOptions set with AddCookie. IsPersistent = false, // Whether the authentication session is persisted across // multiple requests. When used with cookies, controls // whether the cookie's lifetime is absolute (matching the // lifetime of the authentication ticket) or session-based. IssuedUtc = DateTime.UtcNow // The time at which the authentication ticket was issued. //RedirectUri = <string> // The full path or absolute URI to be used as an http // redirect response value. }; await context.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity), authProperties); return(true); }