Update your secret recipe...
<p>Get various user information from the context object</p> <pre><code class="language-cs">public class CurrentUser : ICurrentUser { private readonly IHttpContextAccessor _httpContextAccessor; public CurrentUser(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; } public IEnumerable<Claim>? GetUserClaims() { return _httpContextAccessor?.HttpContext?.User.Claims; } public string? GetUserId() { return _httpContextAccessor?.HttpContext?.User .FindFirst(ClaimTypes.NameIdentifier)?.Value; } public string? GetUserEmail() { return _httpContextAccessor?.HttpContext?.User .FindFirst(ClaimTypes.Email)?.Value; } public string? GetUserIpAddress() { return _httpContextAccessor?.HttpContext ?.Connection?.RemoteIpAddress?.ToString(); } public bool IsAuthenticated() { return _httpContextAccessor?.HttpContext ?.User.Identity?.IsAuthenticated ?? false; } } </code></pre> <p>Add more as necessary.</p>
Update Note
Back To All Notes