Mauricio Pastorini Mauricio Pastorini - 1 month ago 18
C# Question

(OWIN) How to get User from token?

Im using OWIN for Web Api, I wonder how to get the user associated to token.
Thanks

enter image description here

Answer

The User associated with the transaction is a property of ApiController, which your controller inherits from. You can access it like this:

public IHttpActionResult GetUserFromToken()
{
    var u = User;
    return Ok(u);
}

If you are interested in the user's name, you can find that with User.Identity.Name.