I have Web API application with working authentication etc. Now I want to be able to (N)inject some data about currently logged user. So I've configured ninject to look something like this:
kernel.Bind<UserContext>().ToMethod(ctx =>
{
var identity = HttpContext.Current?.Request?.LogonUserIdentity
if (identity != null)
{
return new UserContext
{
UserId = identity.GetUserId(),
};
}
return new UserContext();
}).InRequestScope()
But when this method gets to be called the LogonUserIdentity
looks nothing like identity created via OAuthAuthorizationServerProvider.GrantResourceOwnerCredentials
but more like local windows account identity. There is no id or email (name is my local account name). HttpContext.Current.User
on the other hand is "empty" (no name, no id).
How can I retrieve current OAuth user?
Solved
Found solution here: User (IPrincipal) not avaliable on ApiController's constructor using Web Api 2.1 and Owin