Let’s end this week with a last WIF related post. When you create a new ClaimsIdentity in your code and you check the IsAuthenticated property it will return false by default. This is a breaking change compared to the previous identity types. The idea is that in a claims model your users can be anonymous although they have specified some claims(e.g. an age claim).
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
var identity=new ClaimsIdentity(new Claim[] { new Claim("Age", 21) }); |
If you want your IsAuthenticated property to return true, you need to set an authentication type when instantiating the ClaimsIdentity object:
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
var identity=new ClaimsIdentity(new Claim[] { new Claim("Age", 21) },"customAuthenticationType"); |