Files
unkin-agent a167d00b73
ci/woodpecker/pr/ci Pipeline was successful
store OAuth state in the shared cache
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.
2026-09-19 22:47:43 +10:00

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);
}
}