Reputation: 255
I have a project I'm working on. It's using Thinktecture Identitity Server to pass the token to my application. Problem is I need to extract a claim value from the token, so far I was able to do Linq query to get the claim value (I am able to see it in result via debug), however I can't pull the actual value out, I've tried to string, toarray, etc. It keeps giving me the actual type. My code is below:
var company = ClaimsPrincipal.Current.Identities.ToArray();
var claimType1 = company[0].Claims.ToArray();
var claimtest = from x in claimType1 where x.Type == "http://identityserver.thinktecture.com/claims/profileclaims/company" select x.Value;
String claimfinal = claimtest.ToString();
ViewBag.Message = claimtest.GetType().ToString() + " " + claimfinal;
and this is the output:
System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Security.Claims.Claim,System.String] System.Linq.Enumerable+WhereSelectArrayIterator`2[System.Security.Claims.Claim,System.String]
FYI: This is in the controller only for testing purposes. Ideally I want to be able to process a claim, and store various info from it in a separate background class
Upvotes: 0
Views: 201
Reputation: 1038800
claimtest
is an IEnumerable, you probably want to select only the first claim of the specified type and then use its value:
var claimtest = claimType1
.First(x => x.Type == "http://identityserver.thinktecture.com/claims/profileclaims/company")
.Value;
Upvotes: 3