Those who know me also know that I was always an advocate of Thread.CurrentPrincipal (or ClaimsPrincipal.Current in .NET 4.5). But I also understand that some people (or frameworks) don’t like ambients and rather deal with instance variables.
To cater for that, I did a small addition to Thinktecture.IdentityModel – when you set the SetPrincipalOnRequestInstance property on AuthenticationConfiguration to true (which it is by default), the resulting ClaimsPrincipal gets added to the properties collection of the HttpRequestMessage instance.
You can then access it from anywhere where you have access to the request either directly or via a new extension method like this:
public ViewClaims Get()
{
var principal = Request.GetClaimsPrincipal();
return ViewClaims.GetAll(principal);
}
The code is on github and soon on nuget.
HTH