Path: redb-identity/src/redb.Identity.Core/Routes/Processors/LiveJwksProcessor.cs
Snapshot: redb-identity, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-identity
Page: https://redbase.app/src/dev-2026-12-06/redb-identity/src/redb.Identity.Core/Routes/Processors/LiveJwksProcessor.cs
----
using System.Text.Json;
using Microsoft.IdentityModel.Tokens;
using redb.Identity.Core.Keys;
using redb.Route.Abstractions;
using redb.Route.Core;
namespace redb.Identity.Core.Routes.Processors;
///
/// JWKS endpoint that reads keys live from on every request,
/// bypassing the static OpenIddictServerOptions.SigningCredentials list (which is
/// frozen at process start). Wired in place of the default JwksEndpointProcessor
/// when is enabled,
/// so admin /signing-keys/rotate and /signing-keys/{kid}/retire reflect on
/// the JWKS immediately without any process restart.
///
/// Caveat: OpenIddict still picks the signing credential for NEW tokens from its frozen
/// options list. RPs cache the live JWKS (Cache-Control: max-age=3600) and will validate
/// in-flight tokens against whichever kid is present. New-token-kid follows new-key only
/// after the OpenIddict cache refreshes (process restart or future IOptionsMonitor wiring).
///
///
internal sealed class LiveJwksProcessor : IProcessor
{
private readonly ISigningKeyStore _store;
public LiveJwksProcessor(ISigningKeyStore store)
{
_store = store ?? throw new ArgumentNullException(nameof(store));
}
public async Task Process(IExchange exchange, CancellationToken ct = default)
{
var keys = await _store.GetAllAsync(ct).ConfigureAwait(false);
// Convert each stored SecurityKey to its public JWK form (no private material).
// Filter to signing-kind only; encryption keys live in a separate part of the spec
// (`use=enc`) and we currently advertise sign-only on this endpoint.
var jwks = new List