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

93 lines
2.8 KiB
C#

using System;
using System.Collections.Generic;
using Jellyfin.Plugin.SSO_Auth.Api;
namespace Jellyfin.Plugin.SSO_Auth.State;
/// <summary>
/// A redacted view of an in-flight authorization state. The PKCE code verifier and the authorization
/// URL derived from it are deliberately omitted so that listing flows cannot leak them.
/// </summary>
public class SsoStateInfo
{
/// <summary>
/// Gets or sets the OpenID state value.
/// </summary>
public string State { get; set; }
/// <summary>
/// Gets or sets the redirect URI the provider calls back to.
/// </summary>
public string RedirectUri { get; set; }
/// <summary>
/// Gets or sets when the flow started.
/// </summary>
public DateTime Created { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the flow has been validated.
/// </summary>
public bool Valid { get; set; }
/// <summary>
/// Gets or sets the user tied to the flow.
/// </summary>
public string Username { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the user is an administrator.
/// </summary>
public bool Admin { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the flow links an existing account.
/// </summary>
public bool IsLinking { get; set; }
/// <summary>
/// Gets or sets the folders the user is allowed access to.
/// </summary>
public IReadOnlyList<string> Folders { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the user is allowed to view live TV.
/// </summary>
public bool EnableLiveTv { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the user is allowed to manage live TV.
/// </summary>
public bool EnableLiveTvManagement { get; set; }
/// <summary>
/// Gets or sets the user avatar url.
/// </summary>
public string AvatarURL { get; set; }
/// <summary>
/// Projects a stored state onto its redacted view.
/// </summary>
/// <param name="state">The stored state.</param>
/// <returns>The redacted view.</returns>
public static SsoStateInfo FromState(TimedAuthorizeState state)
{
ArgumentNullException.ThrowIfNull(state);
return new SsoStateInfo
{
State = state.State?.State,
RedirectUri = state.State?.RedirectUri,
Created = state.Created,
Valid = state.Valid,
Username = state.Username,
Admin = state.Admin,
IsLinking = state.IsLinking,
Folders = state.Folders,
EnableLiveTv = state.EnableLiveTv,
EnableLiveTvManagement = state.EnableLiveTvManagement,
AvatarURL = state.AvatarURL
};
}
}