title: Is Thread.CurrentPrincipal reliable using OWIN authentication and Web API?
body: <p>Prior to MVC5 I've heard of / been able to reproduce an issue in the past where the Thread.CurrentPrincipal is not always set correctly when using async operations. Here's one blog post that discusses the issue: <a href="http://www.hanselman.com/blog/SystemThreadingThreadCurrentPrincipalVsSystemWebHttpContextCurrentUserOrWhyFormsAuthenticationCanBeSubtle.aspx" rel="nofollow">http://www.hanselman.com/blog/SystemThreadingThreadCurrentPrincipalVsSystemWebHttpContextCurrentUserOrWhyFormsAuthenticationCanBeSubtle.aspx</a></p>
  
  <p>Now I've set up authentication in a new Web API project using OWIN middleware on .NET 4.5.2 (using a token auth provider). The Web API's controllers are made up of mostly async operations which call into another business layer assembly. I would like to use the ClaimsPrincipalPermission attributes to secure invocation into this assembly's methods. This attribute works with a ClaimsAuthorizationManager which checks access. I assume under the covers this uses Thread.CurrentPrincipal, and so I'm skeptical as to whether or not I'm going to run into the same issue where the Thread.CurrentPrincipal does not match that of the original Web API's caller.</p>
  
  <p><strong>Am I likely to experience this same issue?</strong> So far I have not reproduced it, but I am not convinced the problem is actually solved. I think it is more likely I have just not yet been able to reproduce a problem that is still there.</p>
  
  <p>References:</p>
  
  <p><a href="https://msdn.microsoft.com/en-us/library/system.identitymodel.services.claimsprincipalpermissionattribute(v=vs.110).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/system.identitymodel.services.claimsprincipalpermissionattribute(v=vs.110).aspx</a></p>
  
  <p><a href="http://dotnetcodr.com/2013/02/21/introduction-to-claims-based-security-in-net4-5-with-c-part-4-authorisation-with-claims/" rel="nofollow">http://dotnetcodr.com/2013/02/21/introduction-to-claims-based-security-in-net4-5-with-c-part-4-authorisation-with-claims/</a></p>