/// <summary> /// Adds a number of <see cref="T:System.Security.Claims.Claim" /> to the <see cref="T:System.IdentityModel.Tokens.JwtPayload" /> as JSON { name, value } pairs. /// </summary> /// <param name="claims">for each <see cref="T:System.Security.Claims.Claim" /> a JSON pair { 'Claim.Type', 'Claim.Value' } is added. If duplicate claims are found then a { 'Claim.Type', List<object> } will be created to contain the duplicate values.</param> /// <remarks><para>Each <see cref="T:System.Security.Claims.Claim" /> added will have <see cref="P:System.Security.Claims.Claim.Type" /> translated according to the mapping found in <see cref="P:System.IdentityModel.Tokens.JwtSecurityTokenHandler.OutboundClaimTypeMap" />. Adding and removing to <see cref="P:System.IdentityModel.Tokens.JwtSecurityTokenHandler.OutboundClaimTypeMap" /> /// will affect the name component of the Json claim</para> /// <para>Any <see cref="T:System.Security.Claims.Claim" /> in the <see cref="T:System.Collections.Generic.IEnumerable`1" /> that is null, will be ignored.</para></remarks> /// <exception cref="T:System.ArgumentNullException">'claims' is null.</exception> public void AddClaims(IEnumerable <Claim> claims) { if (claims == null) { throw new ArgumentNullException(nameof(claims)); } foreach (Claim claim in claims) { if (claim != null) { string key = (string)null; if (!JwtSecurityTokenHandler.OutboundClaimTypeMap.TryGetValue(claim.Type, out key)) { key = claim.Type; } object obj1 = claim.ValueType.Equals("http://www.w3.org/2001/XMLSchema#string", StringComparison.Ordinal) ? (object)claim.Value : JwtPayload.GetClaimValueUsingValueType(claim); object obj2; if (this.TryGetValue(key, out obj2)) { IList <object> objectList = obj2 as IList <object>; if (objectList == null) { objectList = (IList <object>) new List <object>(); objectList.Add(obj2); this[key] = (object)objectList; } objectList.Add(obj1); } else { this[key] = obj1; } } } }