Mauricio Pastorini Mauricio Pastorini - 1 year ago 154
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.

enter image description here

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download