Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Created April 29, 2018 23:08
Show Gist options
  • Save wellingtonjhn/17b2972d1e3de5d6324602267c7cdf1f to your computer and use it in GitHub Desktop.
Save wellingtonjhn/17b2972d1e3de5d6324602267c7cdf1f to your computer and use it in GitHub Desktop.
Authenticated User - IHttpContextAccessor
public class AuthenticatedUser
{
private readonly IHttpContextAccessor _accessor;
public AuthenticatedUser(IHttpContextAccessor accessor)
{
_accessor = accessor;
}
public string Email => _accessor.HttpContext.User.Identity.Name;
public string Name => GetClaimsIdentity().FirstOrDefault(a => a.Type == ClaimTypes.NameIdentifier)?.Value;
public IEnumerable<Claim> GetClaimsIdentity()
{
return _accessor.HttpContext.User.Claims;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment