|
|
|
@ -9,25 +9,38 @@ namespace Ombi.Helpers
|
|
|
|
|
{
|
|
|
|
|
public override bool CanConvert(Type objectType)
|
|
|
|
|
{
|
|
|
|
|
return (objectType == typeof(Claim));
|
|
|
|
|
return (objectType == typeof(System.Security.Claims.Claim));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
var claim = (System.Security.Claims.Claim)value;
|
|
|
|
|
JObject jo = new JObject();
|
|
|
|
|
jo.Add("Type", claim.Type);
|
|
|
|
|
jo.Add("Value", IsJson(claim.Value) ? new JRaw(claim.Value) : new JValue(claim.Value));
|
|
|
|
|
jo.Add("ValueType", claim.ValueType);
|
|
|
|
|
jo.Add("Issuer", claim.Issuer);
|
|
|
|
|
jo.Add("OriginalIssuer", claim.OriginalIssuer);
|
|
|
|
|
jo.WriteTo(writer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
|
|
|
|
{
|
|
|
|
|
JObject jo = JObject.Load(reader);
|
|
|
|
|
string type = (string)jo["Type"];
|
|
|
|
|
string value = (string)jo["Value"];
|
|
|
|
|
JToken token = jo["Value"];
|
|
|
|
|
string value = token.Type == JTokenType.String ? (string)token : token.ToString(Formatting.None);
|
|
|
|
|
string valueType = (string)jo["ValueType"];
|
|
|
|
|
string issuer = (string)jo["Issuer"];
|
|
|
|
|
string originalIssuer = (string)jo["OriginalIssuer"];
|
|
|
|
|
return new Claim(type, value, valueType, issuer, originalIssuer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool CanWrite => false;
|
|
|
|
|
|
|
|
|
|
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
|
|
|
|
private bool IsJson(string val)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
return (val != null &&
|
|
|
|
|
(val.StartsWith("[") && val.EndsWith("]")) ||
|
|
|
|
|
(val.StartsWith("{") && val.EndsWith("}")));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|