using System.Threading.Tasks;
using Jellyfin.Database.Implementations.Entities;
using MediaBrowser.Controller.Authentication;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.ShareLinks.Services;
///
/// The authentication provider assigned to ShareLinks guest accounts. It refuses
/// every interactive sign-in, so a guest account cannot be used on the normal
/// login page even if its name and password were to leak. Guest sessions are
/// minted server side through ISessionManager.AuthenticateDirect, which
/// does not enforce a password and so never reaches a provider at all.
///
public sealed class GuestAuthenticationProvider : IAuthenticationProvider
{
private readonly ILogger _logger;
/// Initializes a new instance of the class.
public GuestAuthenticationProvider(ILogger logger)
{
_logger = logger;
}
///
/// Gets the value Jellyfin stores on a user to select this provider. Jellyfin
/// matches it against the provider's full type name.
///
public static string ProviderId => typeof(GuestAuthenticationProvider).FullName!;
///
public string Name => "ShareLinks guest accounts (blocks sign-in)";
///
public bool IsEnabled => true;
///
public Task Authenticate(string username, string password)
{
_logger.LogWarning("ShareLinks: refused an interactive sign-in attempt for guest account {UserName}.", username);
return Task.FromException(
new AuthenticationException("ShareLinks guest accounts cannot sign in interactively."));
}
///
/// Reports the account as having a password so nothing offers it as a
/// passwordless login.
///
public bool HasPassword(User user) => true;
///
public Task ChangePassword(User user, string newPassword) => Task.CompletedTask;
}