From 63546abe52e2370f74c568a22bbaefce34a4fa0e Mon Sep 17 00:00:00 2001 From: Paul Welter Date: Thu, 12 Dec 2024 14:23:43 -0600 Subject: [PATCH] add CancellationToken to ISecurityKeyValidator --- src/AspNetCore.SecurityKey/ISecurityKeyValidator.cs | 12 ++++++++---- src/AspNetCore.SecurityKey/SecurityKeyMiddleware.cs | 3 +-- src/AspNetCore.SecurityKey/SecurityKeyValidator.cs | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/AspNetCore.SecurityKey/ISecurityKeyValidator.cs b/src/AspNetCore.SecurityKey/ISecurityKeyValidator.cs index 7e60c41..bce0822 100644 --- a/src/AspNetCore.SecurityKey/ISecurityKeyValidator.cs +++ b/src/AspNetCore.SecurityKey/ISecurityKeyValidator.cs @@ -11,15 +11,19 @@ public interface ISecurityKeyValidator /// Validates the specified security API key. /// /// The security API key to validate. - /// true if security API key is valid; otherwise false - ValueTask Validate(string? value); + /// The cancellation token. + /// + /// true if security API key is valid; otherwise false + /// + ValueTask Validate(string? value, CancellationToken cancellationToken = default); /// /// Authenticate the specified security API key. /// /// The security API key to validate. + /// The cancellation token. /// - /// result of the authentication + /// result of the authentication /// - ValueTask Authenticate(string? value); + ValueTask Authenticate(string? value, CancellationToken cancellationToken = default); } diff --git a/src/AspNetCore.SecurityKey/SecurityKeyMiddleware.cs b/src/AspNetCore.SecurityKey/SecurityKeyMiddleware.cs index e9275c8..41a83f7 100644 --- a/src/AspNetCore.SecurityKey/SecurityKeyMiddleware.cs +++ b/src/AspNetCore.SecurityKey/SecurityKeyMiddleware.cs @@ -29,8 +29,7 @@ public SecurityKeyMiddleware( public async Task InvokeAsync(HttpContext context) { - if (context is null) - throw new ArgumentNullException(nameof(context)); + ArgumentNullException.ThrowIfNull(context); var securityKey = _securityKeyExtractor.GetKey(context); diff --git a/src/AspNetCore.SecurityKey/SecurityKeyValidator.cs b/src/AspNetCore.SecurityKey/SecurityKeyValidator.cs index 5ef5674..0fcf05d 100644 --- a/src/AspNetCore.SecurityKey/SecurityKeyValidator.cs +++ b/src/AspNetCore.SecurityKey/SecurityKeyValidator.cs @@ -42,7 +42,7 @@ public SecurityKeyValidator( } /// - public async ValueTask Authenticate(string? value) + public async ValueTask Authenticate(string? value, CancellationToken cancellationToken = default) { var isValid = await Validate(value); @@ -57,7 +57,7 @@ public async ValueTask Authenticate(string? value) } /// - public ValueTask Validate(string? value) + public ValueTask Validate(string? value, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(value)) return ValueTask.FromResult(false);