Kavita/Kavita.API/Store/IUserContext.cs
Fesaa c62b20f54b
BE Tech Debt (#4497)
Co-authored-by: Joseph Milazzo <joseph.v.milazzo@gmail.com>
Co-authored-by: Joe Milazzo <josephmajora@gmail.com>
2026-03-07 10:04:08 -08:00

44 lines
1.3 KiB
C#

using System.Collections.Generic;
using Kavita.Models.Entities.Progress;
namespace Kavita.API.Store;
public interface IUserContext
{
/// <summary>
/// Gets the current authenticated user's ID.
/// Returns null if user is not authenticated or on [AllowAnonymous] endpoint.
/// </summary>
int? GetUserId();
/// <summary>
/// Gets the current authenticated user's ID.
/// Throws KavitaException if user is not authenticated.
/// </summary>
int GetUserIdOrThrow();
/// <summary>
/// Gets the current authenticated user's username.
/// Returns null if user is not authenticated.
/// </summary>
/// <remarks>Warning! Username's can contain .. and /, do not use folders or filenames explicitly with the Username</remarks>
string? GetUsername();
/// <summary>
/// The Roles associated with the Authenticated user
/// </summary>
IReadOnlyList<string> Roles { get; }
/// <summary>
/// Returns true if the current user is authenticated.
/// </summary>
bool IsAuthenticated { get; }
/// <summary>
/// Gets the authentication method used (JWT, Auth Key, OIDC).
/// </summary>
AuthenticationType GetAuthenticationType();
bool HasRole(string role);
bool HasAnyRole(params string[] roles);
bool HasAllRoles(params string[] roles);
}