forked from mirrors/jellyfin-plugin-sso
a167d00b73
ci/woodpecker/pr/ci Pipeline was successful
Keys each in-flight OpenID flow in the server's Valkey/Redis connection so a login can start on one replica and finish on another. Falls back to an in-memory store when no multiplexer is registered.
37 lines
1.3 KiB
C#
37 lines
1.3 KiB
C#
using Jellyfin.Plugin.SSO_Auth.Api;
|
|
using Newtonsoft.Json;
|
|
|
|
namespace Jellyfin.Plugin.SSO_Auth.State;
|
|
|
|
/// <summary>
|
|
/// Converts <see cref="TimedAuthorizeState"/> to and from the representation held by a state store.
|
|
/// </summary>
|
|
public static class SsoStateSerializer
|
|
{
|
|
private static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
|
{
|
|
NullValueHandling = NullValueHandling.Include,
|
|
DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind
|
|
};
|
|
|
|
/// <summary>
|
|
/// Serializes an authorization state.
|
|
/// </summary>
|
|
/// <param name="state">The state to serialize.</param>
|
|
/// <returns>The serialized state.</returns>
|
|
public static string Serialize(TimedAuthorizeState state)
|
|
{
|
|
return JsonConvert.SerializeObject(state, Settings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Deserializes an authorization state.
|
|
/// </summary>
|
|
/// <param name="payload">The serialized state, which may be null or empty.</param>
|
|
/// <returns>The state, or <c>null</c> when there is nothing to deserialize.</returns>
|
|
public static TimedAuthorizeState Deserialize(string payload)
|
|
{
|
|
return string.IsNullOrEmpty(payload) ? null : JsonConvert.DeserializeObject<TimedAuthorizeState>(payload, Settings);
|
|
}
|
|
}
|