mirror of
https://github.com/bitwarden/server
synced 2026-01-01 08:03:23 +00:00
remove the redis grant store (#3757)
This commit is contained in:
@@ -7,7 +7,6 @@ using Bit.SharedWeb.Utilities;
|
||||
using Duende.IdentityServer.ResponseHandling;
|
||||
using Duende.IdentityServer.Services;
|
||||
using Duende.IdentityServer.Stores;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace Bit.Identity.Utilities;
|
||||
|
||||
@@ -54,56 +53,18 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
if (CoreHelpers.SettingHasValue(globalSettings.IdentityServer.CosmosConnectionString))
|
||||
{
|
||||
services.AddSingleton<IPersistedGrantStore>(sp => BuildCosmosGrantStore(sp, globalSettings));
|
||||
}
|
||||
else if (CoreHelpers.SettingHasValue(globalSettings.IdentityServer.RedisConnectionString))
|
||||
{
|
||||
services.AddSingleton<IPersistedGrantStore>(sp => BuildRedisGrantStore(sp, globalSettings));
|
||||
services.AddSingleton<IPersistedGrantStore>(sp =>
|
||||
new PersistedGrantStore(sp.GetRequiredKeyedService<IGrantRepository>("cosmos"),
|
||||
g => new Core.Auth.Models.Data.GrantItem(g)));
|
||||
}
|
||||
else
|
||||
{
|
||||
services.AddTransient<IPersistedGrantStore>(sp => BuildSqlGrantStore(sp));
|
||||
services.AddTransient<IPersistedGrantStore>(sp =>
|
||||
new PersistedGrantStore(sp.GetRequiredService<IGrantRepository>(),
|
||||
g => new Core.Auth.Entities.Grant(g)));
|
||||
}
|
||||
|
||||
services.AddTransient<ICorsPolicyService, CustomCorsPolicyService>();
|
||||
return identityServerBuilder;
|
||||
}
|
||||
|
||||
private static PersistedGrantStore BuildCosmosGrantStore(IServiceProvider sp, GlobalSettings globalSettings)
|
||||
{
|
||||
if (!CoreHelpers.SettingHasValue(globalSettings.IdentityServer.CosmosConnectionString))
|
||||
{
|
||||
throw new ArgumentException("No cosmos config string available.");
|
||||
}
|
||||
return new PersistedGrantStore(
|
||||
// TODO: Perhaps we want to evaluate moving this repo to DI as a keyed service singleton in .NET 8
|
||||
new Core.Auth.Repositories.Cosmos.GrantRepository(globalSettings),
|
||||
g => new Core.Auth.Models.Data.GrantItem(g),
|
||||
fallbackGrantStore: BuildRedisGrantStore(sp, globalSettings, true));
|
||||
}
|
||||
|
||||
private static RedisPersistedGrantStore BuildRedisGrantStore(IServiceProvider sp,
|
||||
GlobalSettings globalSettings, bool allowNull = false)
|
||||
{
|
||||
if (!CoreHelpers.SettingHasValue(globalSettings.IdentityServer.RedisConnectionString))
|
||||
{
|
||||
if (allowNull)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
throw new ArgumentException("No redis config string available.");
|
||||
}
|
||||
|
||||
return new RedisPersistedGrantStore(
|
||||
// TODO: .NET 8 create a keyed service for this connection multiplexer and even PersistedGrantStore
|
||||
ConnectionMultiplexer.Connect(globalSettings.IdentityServer.RedisConnectionString),
|
||||
sp.GetRequiredService<ILogger<RedisPersistedGrantStore>>(),
|
||||
fallbackGrantStore: BuildSqlGrantStore(sp));
|
||||
}
|
||||
|
||||
private static PersistedGrantStore BuildSqlGrantStore(IServiceProvider sp)
|
||||
{
|
||||
return new PersistedGrantStore(sp.GetRequiredService<IGrantRepository>(),
|
||||
g => new Core.Auth.Entities.Grant(g));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user