Files
jellyfin-plugin-sso/SSO-Auth/SsoAuthServiceRegistrator.cs
unkin-agent e71df7aa36
ci/woodpecker/pr/ci Pipeline was successful
bound the in-memory state store and guard store failures
Drop a rejected state instead of refreshing its TTL, and turn a store
outage into the plugin's error page rather than an unhandled 500.
2026-09-19 23:05:16 +10:00

45 lines
1.6 KiB
C#

using System;
using Jellyfin.Plugin.SSO_Auth.State;
using MediaBrowser.Controller;
using MediaBrowser.Controller.Plugins;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;
namespace Jellyfin.Plugin.SSO_Auth;
/// <summary>
/// Registers the plugin's services. The OAuth state store is backed by the shared cache the server
/// already connects to when one is configured, which is what lets a login start on one server instance
/// and be completed on another.
/// </summary>
public class SsoAuthServiceRegistrator : IPluginServiceRegistrator
{
/// <inheritdoc />
public void RegisterServices(IServiceCollection serviceCollection, IServerApplicationHost applicationHost)
{
ArgumentNullException.ThrowIfNull(serviceCollection);
serviceCollection.AddSingleton<ISsoStateStore>(sp =>
{
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger<SsoAuthServiceRegistrator>();
var multiplexer = sp.GetService<IConnectionMultiplexer>();
if (multiplexer is null)
{
logger.LogWarning(
"SSO OAuth state store: {Store}. Logins must start and finish on the same server instance.",
nameof(InMemorySsoStateStore));
return new InMemorySsoStateStore();
}
logger.LogInformation(
"SSO OAuth state store: {Store}. Logins are shared across server instances.",
nameof(RedisSsoStateStore));
return new RedisSsoStateStore(multiplexer);
});
}
}