While @Steven's suggestion will work fine with normal .NET Web API 2 applications, it is not suitable for self-hosted applications with Owin, since HttpContext.Current is always NULL there.
Based on @Steven's suggested solution, I was able to solve the problem as follows:
Install the Nuget package OwinRequestScopeContext.
Add app.UseRequestScopeContext(); to the Startup.cs.
Add a IClaimsProvider interface to the Domain project:
public interface IClaimsProvider
{
ClaimsPrincipal UserClaims { get; }
}
Add a OwinContextClaimsProvider class which implements IClaimsProvider to the startup project:
public class OwinContextClaimsProvider : IClaimsProvider
{
public ClaimsPrincipal UserClaims => OwinRequestScopeContext.Current.Environment["server.User"] as ClaimsPrincipal;
}
Register the ClaimsProvider using Autofac:
builder.RegisterType<OwinContextClaimsProvider>().As<IClaimsProvider>().InstancePerLifetimeScope();
Note: IClaimsProvider.UserClaims will be NULL if no user is authenticated.