using Jellyfin.Plugin.SSO_Auth.Api;
using Newtonsoft.Json;
namespace Jellyfin.Plugin.SSO_Auth.State;
///
/// Converts to and from the representation held by a state store.
///
public static class SsoStateSerializer
{
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Include,
DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind
};
///
/// Serializes an authorization state.
///
/// The state to serialize.
/// The serialized state.
public static string Serialize(TimedAuthorizeState state)
{
return JsonConvert.SerializeObject(state, Settings);
}
///
/// Deserializes an authorization state.
///
/// The serialized state, which may be null or empty.
/// The state, or null when there is nothing to deserialize.
public static TimedAuthorizeState Deserialize(string payload)
{
return string.IsNullOrEmpty(payload) ? null : JsonConvert.DeserializeObject(payload, Settings);
}
}