/// <summary> /// Gets a standard claim from the header. /// A standard cliam is either a string or a value of another type serialized in JSON format. /// </summary> /// <param name="claimType">The key of the claim.</param> /// <returns>The standard claim string; or null if not found.</returns> internal string GetStandardClaim(string claimType) { object value = null; if (TryGetValue(claimType, out value)) { string str = value as string; if (str != null) { return(str); } return(JsonExtensions.SerializeToJson(value)); } return(null); }
/// <summary> /// Gets a standard claim from the header. /// A standard claim is either a string or a value of another type serialized in JSON format. /// </summary> /// <param name="claimType">The key of the claim.</param> /// <returns>The standard claim string; or null if not found.</returns> internal string GetStandardClaim(string claimType) { if (TryGetValue(claimType, out object value)) { if (value == null) { return(null); } if (value is string str) { return(str); } return(JsonExtensions.SerializeToJson(value)); } return(null); }
internal IList <string> GetIListClaims(string claimType) { List <string> claimValues = new List <string>(); object value = null; if (!TryGetValue(claimType, out value)) { return(claimValues); } string str = value as string; if (str != null) { claimValues.Add(str); return(claimValues); } // values must be an enumeration of strings; IEnumerable <object> values = value as IEnumerable <object>; if (values != null) { foreach (var item in values) { claimValues.Add(item.ToString()); } } else { claimValues.Add(JsonExtensions.SerializeToJson(value)); } return(claimValues); }
/// <summary> /// Serializes this instance to JSON. /// </summary> /// <returns>This instance as JSON.</returns> /// <remarks>Use <see cref="JsonExtensions.Serializer"/> to customize JSON serialization.</remarks> public virtual string SerializeToJson() { return(JsonExtensions.SerializeToJson(this as IDictionary <string, object>)); }