Im trying to get an Access token, and to do it I need this line:
string userId = User.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
However, unless I Implement Controller it cannot find User. I've tried HttpContext.User And a few other things as well.
It comes from ControllerBase and looks like public ClaimsPrincipal User { get; }. Is there no way to get this in a normal class with an import?
You can inject IHttpContextAccessor and access the user like this
_httpContextAccessor.HttpContext.User
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With