Skip to content

Add SignatureValidatorWithToken delegate with opt-in/decline pattern#3485

Closed
iNinja wants to merge 1 commit into
dev8xfrom
iinglese/signature-validator-delegate
Closed

Add SignatureValidatorWithToken delegate with opt-in/decline pattern#3485
iNinja wants to merge 1 commit into
dev8xfrom
iinglese/signature-validator-delegate

Conversation

@iNinja

@iNinja iNinja commented May 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces a new signature validation delegate that allows callers to either handle signature validation in full or decline, letting the handler fall through to its built-in logic.

This replaces the approach in the abandoned PR #3483, which risked recursive loops when the delegate needed to fall back to default validation.

New public API

SignatureValidationDelegateResult (readonly struct)

  • Success(SecurityToken token) — delegate handled validation successfully
  • NotHandled — delegate declines; handler proceeds with default logic
  • If the signature is invalid, the delegate throws (e.g. SecurityTokenInvalidSignatureException)

SignatureValidatorWithToken (delegate)

public delegate SignatureValidationDelegateResult SignatureValidatorWithToken(
    SecurityToken token,
    TokenValidationParameters validationParameters,
    BaseConfiguration configuration);

TokenValidationParameters.SignatureValidatorWithToken (property)

Behaviour

  1. Existing SignatureValidator / SignatureValidatorUsingConfiguration delegates retain absolute priority
  2. If neither is set, SignatureValidatorWithToken is evaluated
  3. If the new delegate returns NotHandled, the handler validates the signature using its default logic as if no delegate were set
  4. If the new delegate returns Success, the validated token is used directly

Additional fix

BaseConfiguration is now correctly forwarded to SignatureValidatorUsingConfiguration and IssuerSigningKeyValidator in the delegate code path (previously passed as null).

Tests

14 new tests covering:

  • Delegate handles / declines / throws
  • Old delegate priority
  • Configuration passthrough
  • Telemetry (success and failure)
  • Struct contract (NotHandled, Success, null guard)
  • Copy constructor propagation

All 671+ existing tests pass across all 6 TFMs (net462, net472, net6.0, net8.0, net9.0, net10.0).

Introduce a new signature validation delegate that allows callers to
either handle signature validation in full or decline, letting the
handler fall through to its built-in logic. This replaces the approach
in the abandoned PR #3483 which risked recursive loops.

New public API surface:
- SignatureValidationDelegateResult readonly struct (Success / NotHandled)
- SignatureValidatorWithToken delegate
- TokenValidationParameters.SignatureValidatorWithToken property

The new delegate runs after the existing SignatureValidator and
SignatureValidatorUsingConfiguration delegates (which retain priority).
When the new delegate returns NotHandled, the handler proceeds with
its default signature validation as if no delegate were set.

Also fixes configuration passthrough: BaseConfiguration is now
correctly forwarded to SignatureValidatorUsingConfiguration and
IssuerSigningKeyValidator in the delegate code path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@iNinja iNinja requested a review from a team as a code owner May 13, 2026 13:12
@iNinja

iNinja commented May 14, 2026

Copy link
Copy Markdown
Contributor Author

Abandoning in favour of the approach introduced in #3489

@iNinja iNinja closed this May 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant