Bundle: redb-identity / src/redb.Identity.Resource.Dpop (src.redb.Identity.Resource.Dpop.txt), 2 files Snapshot: 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 Index: https://redbase.app/src/dev-2026-12-06/redb-identity/_index.txt ==== Path: redb-identity/src/redb.Identity.Resource.Dpop/DpopResourceTokenValidator.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.Resource.Dpop/DpopResourceTokenValidator.cs ---- using System.Security.Cryptography; using System.Text; using System.Text.Json; using Microsoft.IdentityModel.JsonWebTokens; using Microsoft.IdentityModel.Tokens; using redb.Identity.Core.Services; namespace redb.Identity.Resource.Dpop; /// /// Z4 P2.3 (RFC 9449 §7): Resource Server side validator for DPoP-bound access tokens. /// /// Verifies that: /// /// The supplied DPoP proof is structurally valid (signature, htm, htu, iat, jti). /// The proof's ath claim equals base64url(SHA-256(access_token)). /// The proof's JWK thumbprint matches the access-token's cnf.jkt claim /// (issued by the AS via + the cnf-binding handler). /// /// The caller owns access-token signature/audience/expiry validation — typically delegated to /// OpenIddict.Validation or JsonWebTokenHandler — and passes the already-validated /// JWT here for the DPoP-specific checks. /// /// public sealed class DpopResourceTokenValidator { private static readonly JsonWebTokenHandler s_handler = new(); private readonly DpopProofValidator _proofValidator; public DpopResourceTokenValidator(DpopProofValidator proofValidator) { _proofValidator = proofValidator ?? throw new ArgumentNullException(nameof(proofValidator)); } /// /// Validates a DPoP-bound access-token request. /// /// The bearer-form access token (without the DPoP scheme prefix). /// The raw DPoP request header value. /// HTTP method of the protected request (e.g. GET). /// Absolute URL of the protected request, query stripped per RFC 9449 §4.2. /// Cancellation token. public async Task ValidateAsync( string accessToken, string dpopProof, string httpMethod, string httpUri, CancellationToken ct = default) { if (string.IsNullOrEmpty(accessToken)) return DpopResourceValidationResult.Fail("invalid_token", "Missing access token."); if (string.IsNullOrEmpty(dpopProof)) return DpopResourceValidationResult.Fail("invalid_token", "Missing DPoP proof header."); // Compute the expected `ath` claim per RFC 9449 §4.2: base64url(SHA-256(access_token)). var ath = ComputeAth(accessToken); var proofResult = await _proofValidator.ValidateAsync( proof: dpopProof, httpMethod: httpMethod, httpUri: httpUri, expectedAth: ath, ct: ct).ConfigureAwait(false); if (!proofResult.IsValid) return DpopResourceValidationResult.Fail( proofResult.Error ?? "invalid_token", proofResult.ErrorDescription ?? "DPoP proof validation failed."); // Pull cnf.jkt from the access token. We do not re-validate the JWT here — caller's job — // but we do need the confirmation claim. Read the payload via JsonWebTokenHandler. if (!s_handler.CanReadToken(accessToken)) return DpopResourceValidationResult.Fail("invalid_token", "Access token is not a JWT."); var jwt = s_handler.ReadJsonWebToken(accessToken); if (!jwt.TryGetPayloadValue("cnf", out var cnfElement) || cnfElement.ValueKind != JsonValueKind.Object || !cnfElement.TryGetProperty("jkt", out var jktElement) || jktElement.ValueKind != JsonValueKind.String) { return DpopResourceValidationResult.Fail("invalid_token", "Access token is not DPoP-bound (missing cnf.jkt)."); } var boundJkt = jktElement.GetString()!; if (!string.Equals(boundJkt, proofResult.Jkt, StringComparison.Ordinal)) { return DpopResourceValidationResult.Fail("invalid_token", "DPoP proof key thumbprint does not match the access token cnf.jkt."); } return DpopResourceValidationResult.Success(boundJkt); } /// /// Builds the WWW-Authenticate challenge per RFC 9449 §7.1. /// /// OAuth-style error code (e.g. invalid_token, insufficient_scope). /// Optional human-readable detail (escaped per RFC 6749 §5.2). /// Optional space-separated list of accepted DPoP algs. /// Optional server-issued nonce to require in the next proof. public static string BuildChallengeHeader( string? error = null, string? errorDescription = null, string? allowedAlgs = "ES256 RS256", string? nonce = null) { var sb = new StringBuilder("DPoP"); var hasParams = false; void Append(string key, string? val) { if (string.IsNullOrEmpty(val)) return; sb.Append(hasParams ? ", " : " "); sb.Append(key).Append("=\"").Append(val.Replace("\"", "")).Append('"'); hasParams = true; } Append("error", error); Append("error_description", errorDescription); Append("algs", allowedAlgs); Append("nonce", nonce); return sb.ToString(); } /// /// Computes the access token hash claim (ath) per RFC 9449 §4.2: base64url-encoded /// SHA-256 of the ASCII bytes of the access token. /// public static string ComputeAth(string accessToken) { var hash = SHA256.HashData(Encoding.ASCII.GetBytes(accessToken)); return Base64UrlEncoder.Encode(hash); } } /// Result of a Resource-Server DPoP-bound token validation. public readonly record struct DpopResourceValidationResult( bool IsValid, string? Jkt, string? Error, string? ErrorDescription) { public static DpopResourceValidationResult Success(string jkt) => new(true, jkt, null, null); public static DpopResourceValidationResult Fail(string error, string description) => new(false, null, error, description); } Path: redb-identity/src/redb.Identity.Resource.Dpop/redb.Identity.Resource.Dpop.csproj 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.Resource.Dpop/redb.Identity.Resource.Dpop.csproj ---- redb.Identity.Resource.Dpop redb.Identity.Resource.Dpop Z4 P2 (RFC 9449 §7) — Resource Server side DPoP-bound access-token validator. Validates the inbound `Authorization: DPoP <token>` header together with a fresh DPoP proof, checking: • the proof is structurally valid (htm, htu, iat, jti, signature, embedded JWK), • the proof's `ath` claim equals base64url(SHA-256(access_token)), • the proof's JWK thumbprint matches the access-token's `cnf.jkt` confirmation claim. Issuer-side leg (token endpoint, /authorize binding, replay-store, server-issued nonce challenge) lives in redb.Identity.Core.