Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

namespace Duende.AccessTokenManagement;

public interface IClientCredentialsCacheDurationStore
{
/// <summary>
/// Gets the expiration duration for the specified client credentials cache key.
/// </summary>
/// <param name="cacheKey">The cache key identifying the client credentials.</param>
/// <returns>
/// A <see cref="TimeSpan"/> representing the duration until the cache entry expires.
/// </returns>
TimeSpan GetExpiration(ClientCredentialsCacheKey cacheKey);

/// <summary>
/// Sets the expiration for the specified client credentials cache key.
/// </summary>
/// <param name="cacheKey">The cache key identifying the client credentials.</param>
/// <param name="expiration">The expiration time to set for the cache entry.</param>
/// <returns>
/// A <see cref="TimeSpan"/> representing the duration until the cache entry expires after setting.
/// </returns>
TimeSpan SetExpiration(ClientCredentialsCacheKey cacheKey, DateTimeOffset expiration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Duende.AccessTokenManagement.Internal;
/// </summary>
internal sealed class ClientCredentialsCacheDurationStore(
IOptions<ClientCredentialsTokenManagementOptions> options,
TimeProvider time)
TimeProvider time) : IClientCredentialsCacheDurationStore
{
private readonly ClientCredentialsTokenManagementOptions _options = options.Value;
private readonly ConcurrentDictionary<ClientCredentialsCacheKey, TimeSpan> _cacheDurations = new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class ClientCredentialsTokenManager(
TimeProvider time,
IClientCredentialsTokenEndpoint client,
IClientCredentialsCacheKeyGenerator cacheKeyGenerator,
ClientCredentialsCacheDurationStore cacheDurationAutoTuningStore,
IClientCredentialsCacheDurationStore cacheDurationAutoTuningStore,
ILogger<ClientCredentialsTokenManager> logger
) : IClientCredentialsTokenManager
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static ClientCredentialsTokenManagementBuilder AddClientCredentialsTokenM
this IServiceCollection services)
{
services.TryAddTransient<IClientCredentialsTokenManager, ClientCredentialsTokenManager>();
services.TryAddSingleton<ClientCredentialsCacheDurationStore>();
services.TryAddSingleton<IClientCredentialsCacheDurationStore, ClientCredentialsCacheDurationStore>();
services.AddHybridCache();

// Add a default serializer for ClientCredentialsToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Duende.AccessTokenManagement.ForceTokenRenewal
Duende.AccessTokenManagement.HttpRequestContext
Duende.AccessTokenManagement.HybridCacheConstants
Duende.AccessTokenManagement.IClientAssertionService
Duende.AccessTokenManagement.IClientCredentialsCacheDurationStore
Duende.AccessTokenManagement.IClientCredentialsCacheKeyGenerator
Duende.AccessTokenManagement.IClientCredentialsTokenEndpoint
Duende.AccessTokenManagement.IClientCredentialsTokenManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
{
System.Threading.Tasks.Task<Duende.IdentityModel.Client.ClientAssertion?> GetClientAssertionAsync(Duende.AccessTokenManagement.ClientCredentialsClientName? clientName = default, Duende.AccessTokenManagement.TokenRequestParameters? parameters = null, System.Threading.CancellationToken ct = default);
}
public interface IClientCredentialsCacheDurationStore
{
System.TimeSpan GetExpiration(Duende.AccessTokenManagement.ClientCredentialsCacheKey cacheKey);
System.TimeSpan SetExpiration(Duende.AccessTokenManagement.ClientCredentialsCacheKey cacheKey, System.DateTimeOffset expiration);
}
public interface IClientCredentialsCacheKeyGenerator
{
Duende.AccessTokenManagement.ClientCredentialsCacheKey GenerateKey(Duende.AccessTokenManagement.ClientCredentialsClientName clientName, Duende.AccessTokenManagement.TokenRequestParameters? parameters = null);
Expand Down