Created
April 29, 2018 23:08
-
-
Save wellingtonjhn/17b2972d1e3de5d6324602267c7cdf1f to your computer and use it in GitHub Desktop.
Authenticated User - IHttpContextAccessor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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