When using the new and improved WIF functionality in .NET 4.5 in a WCF service I noticed that although the OperationContext.Current.ClaimsPrincipal was set correctly, the Thread.CurrentPrincipal was null. To tell WCF to put the ClaimsPrincipal coming from the token handler on Thread.CurrentPrincipal you have to add the following service behavior to your configuration:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<behaviors> | |
<serviceBehaviors> | |
<behavior name="Test.Services.WifBehavior"> | |
<serviceCredentials useIdentityConfiguration="true" /> | |
<!---Set principalPermissionMode to always to pass the ClaimsIdentity info to the Thread.CurrentPrincipal--> | |
<serviceAuthorization principalPermissionMode="Always"/> | |
</behavior> | |
</behaviors> |
The end result is a ClaimsPrincipal containing the username, authentication method and authentication instant claims. Also the claims transformation/validation/authorization pipeline will be called if configured.