Skip to content

Commit 3ccdc64

Browse files
committed
feat(sso-persisted-grants) [PM-23572]: Add cache key constant and remove explicit skip distributed cache on set for default configuration.
1 parent 04d1a16 commit 3ccdc64

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

bitwarden_license/src/Sso/IdentityServer/DistributedCachePersistedGrantStore.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Duende.IdentityServer.Models;
1+
using Bit.Sso.Utilities;
2+
using Duende.IdentityServer.Models;
23
using Duende.IdentityServer.Stores;
34
using ZiggyCreatures.Caching.Fusion;
45

@@ -23,7 +24,7 @@ public class DistributedCachePersistedGrantStore : IPersistedGrantStore
2324
private readonly IFusionCache _cache;
2425

2526
public DistributedCachePersistedGrantStore(
26-
[FromKeyedServices("sso-grants")] IFusionCache cache)
27+
[FromKeyedServices(PersistedGrantsDistributedCacheConstants.CacheKey)] IFusionCache cache)
2728
{
2829
_cache = cache;
2930
}
@@ -96,11 +97,6 @@ public async Task StoreAsync(PersistedGrant grant)
9697
await _cache.SetAsync(
9798
grant.Key,
9899
grant,
99-
new FusionCacheEntryOptions
100-
{
101-
Duration = duration,
102-
// Keep distributed cache enabled for multi-instance scenarios
103-
// When Redis isn't configured, FusionCache gracefully uses only L1 (in-memory)
104-
}.SetSkipDistributedCache(false, false));
100+
new FusionCacheEntryOptions { Duration = duration });
105101
}
106102
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace Bit.Sso.Utilities;
2+
3+
public static class PersistedGrantsDistributedCacheConstants
4+
{
5+
/// <summary>
6+
/// The SSO Persisted Grant cache key. Identifies the keyed service consumed by the SSO Persisted Grant Store as
7+
/// well as the cache key/namespace for grant storage.
8+
/// </summary>
9+
public const string CacheKey = "sso-grants";
10+
}

bitwarden_license/src/Sso/Utilities/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ public static IIdentityServerBuilder AddSsoIdentityServerServices(this IServiceC
7979
.AddIdentityServerCertificate(env, globalSettings);
8080

8181
// PM-23572
82-
// Register named FusionCache for SSO authorization code grants
82+
// Register named FusionCache for SSO authorization code grants.
8383
// Provides separation of concerns and automatic Redis/in-memory negotiation
8484
// .AddInMemoryCaching should still persist above; this handles configuration caching, etc.,
8585
// and is separate from this keyed service, which only serves grant negotiation.
86-
services.AddExtendedCache("sso-grants", globalSettings);
86+
services.AddExtendedCache(PersistedGrantsDistributedCacheConstants.CacheKey, globalSettings);
8787

8888
// Store authorization codes in distributed cache for horizontal scaling
8989
// Uses named FusionCache which gracefully degrades to in-memory when Redis isn't configured

0 commit comments

Comments
 (0)