up
Some checks failed
Concelier Attestation Tests / attestation-tests (push) Has been cancelled
Policy Simulation / policy-simulate (push) Has been cancelled
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled

This commit is contained in:
StellaOps Bot
2025-12-13 09:37:15 +02:00
parent e00f6365da
commit 6e45066e37
349 changed files with 17160 additions and 1867 deletions

View File

@@ -0,0 +1,43 @@
using StellaOps.Messaging.Abstractions;
namespace StellaOps.Auth.Security.Dpop;
/// <summary>
/// DPoP replay cache backed by <see cref="IIdempotencyStore"/>.
/// Supports any transport (InMemory, Valkey, PostgreSQL) via factory injection.
/// </summary>
public sealed class MessagingDpopReplayCache : IDpopReplayCache
{
private readonly IIdempotencyStore _store;
private readonly TimeProvider _timeProvider;
public MessagingDpopReplayCache(
IIdempotencyStoreFactory storeFactory,
TimeProvider? timeProvider = null)
{
ArgumentNullException.ThrowIfNull(storeFactory);
_store = storeFactory.Create("dpop:replay");
_timeProvider = timeProvider ?? TimeProvider.System;
}
public async ValueTask<bool> TryStoreAsync(
string jwtId,
DateTimeOffset expiresAt,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(jwtId);
var now = _timeProvider.GetUtcNow();
var ttl = expiresAt - now;
if (ttl <= TimeSpan.Zero)
{
// Already expired, treat as valid to store (won't conflict)
return true;
}
var result = await _store.TryClaimAsync(jwtId, jwtId, ttl, cancellationToken).ConfigureAwait(false);
return result.IsFirstClaim;
}
}