To be able to test my application I had to create a ‘dummy’ ClaimsPrincipal and ClaimsIdentity:
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 claimsIdentity = new ClaimsIdentity(); | |
claimsIdentity.AddClaim(new Claim("http://schemas.example.be/iam/claims/userid", "123")); | |
claimsIdentity.AddClaim(new Claim("http://schemas.example.be/iam/claims/username", "test")); | |
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); |
However when I tried to run my test, the test failed because the ClaimsIdentity returned ‘false’ for the IsAuthenticated check.
To create an authenticated ‘dummy’ identity I had to pass on an extra ‘authenticationType’ parameter to the constructor:
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 claimsIdentity = new ClaimsIdentity(authenticationType:"test"); | |
claimsIdentity.AddClaim(new Claim("http://schemas.example.be/iam/claims/userid", "123")); | |
claimsIdentity.AddClaim(new Claim("http://schemas.example.be/iam/claims/username", "test")); | |
var claimsPrincipal = new ClaimsPrincipal(claimsIdentity); |
The exact value that you specify doesn't matter.