Reputation: 549
I have the below code that retrieves claims for my user after authentication when doing unit test:
var claims = new List<Claim>()
{
new Claim(ClaimTypes.GivenName, "John"),
new Claim(ClaimTypes.Surname, "Doe"),
new Claim(ClaimTypes.Email, "[email protected]"),
};
The above code returns the claims in the following format -e.g for GivenName
:
{http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname: John}
But my controller expects it in this format:
{firstname: John}
Is there a way to adjust my code to return it as per the controller requirement?
Also the claim in my controller has the firstname tag but there is no such tag when creating dummy claim in the unit test, instead of firstname, it only allows me to use givenname tag, is there a way to change this?
Upvotes: 1
Views: 115
Reputation: 36
please try this
var claims = new List<Claim>()
{
new Claim("firstname", "John"),
new Claim("surname", "Doe"),
new Claim("email", "[email protected]"),
};
Upvotes: 1
Reputation: 17658
The claim is basically just a key/value pair and allows you to construct it like this:
new Claim("firstname", "John")
See MSDN.
With respect to this:
Also the claim in my controller has the firstname tag but there is no such tag when creating dummy claim in the unit test, instead of firstname, it only allows me to use givenname tag, is there a way to change this?
Depending on what the unit test is actually testing, this might be an indication that something is wrong. If in doubt, it's best to consult with the author of see the documentation.
Do note: the fact it doesn't exit in the unit-tests does not necessarily means its wrong - you should have a closer look what the test is actually about.
Upvotes: 3