Skip to content

Commit

Permalink
add CancellationToken to ISecurityKeyValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
pwelter34 committed Dec 12, 2024
1 parent 3f97600 commit 63546ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/AspNetCore.SecurityKey/ISecurityKeyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@ public interface ISecurityKeyValidator
/// Validates the specified security API key.
/// </summary>
/// <param name="value">The security API key to validate.</param>
/// <returns>true if security API key is valid; otherwise false</returns>
ValueTask<bool> Validate(string? value);
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// true if security API key is valid; otherwise false
/// </returns>
ValueTask<bool> Validate(string? value, CancellationToken cancellationToken = default);

/// <summary>
/// Authenticate the specified security API key.
/// </summary>
/// <param name="value">The security API key to validate.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>
/// <see cref="ClaimsIdentity"/> result of the authentication
/// <see cref="ClaimsIdentity" /> result of the authentication
/// </returns>
ValueTask<ClaimsIdentity> Authenticate(string? value);
ValueTask<ClaimsIdentity> Authenticate(string? value, CancellationToken cancellationToken = default);
}
3 changes: 1 addition & 2 deletions src/AspNetCore.SecurityKey/SecurityKeyMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/AspNetCore.SecurityKey/SecurityKeyValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public SecurityKeyValidator(
}

/// <inheritdoc />
public async ValueTask<ClaimsIdentity> Authenticate(string? value)
public async ValueTask<ClaimsIdentity> Authenticate(string? value, CancellationToken cancellationToken = default)
{
var isValid = await Validate(value);

Expand All @@ -57,7 +57,7 @@ public async ValueTask<ClaimsIdentity> Authenticate(string? value)
}

/// <inheritdoc />
public ValueTask<bool> Validate(string? value)
public ValueTask<bool> Validate(string? value, CancellationToken cancellationToken = default)
{
if (string.IsNullOrWhiteSpace(value))
return ValueTask.FromResult(false);
Expand Down

0 comments on commit 63546ab

Please sign in to comment.