From ea096d56a78b2936c93217aec00dfb8ca55703f0 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Thu, 16 Oct 2025 16:10:41 +0200 Subject: [PATCH] Update package versions and add null checks Updated SimpleAuthenticationTools.Abstractions package to version 3.1.4 in both SimpleAuthentication.Swashbuckle.csproj and SimpleAuthentication.csproj for potential bug fixes and improvements. Added null checks for Roles in ApiKeyAuthenticationHandler.cs and BasicAuthenticationHandler.cs to prevent runtime exceptions when iterating over potentially null collections. --- .../SimpleAuthentication.Swashbuckle.csproj | 2 +- .../ApiKey/ApiKeyAuthenticationHandler.cs | 7 +++++-- .../BasicAuthentication/BasicAuthenticationHandler.cs | 7 +++++-- src/SimpleAuthentication/SimpleAuthentication.csproj | 2 +- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj b/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj index 2d801a9..3210d6f 100644 --- a/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj +++ b/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj @@ -32,7 +32,7 @@ - + diff --git a/src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs b/src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs index 8f764c9..a3acb67 100644 --- a/src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs +++ b/src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs @@ -45,9 +45,12 @@ protected override async Task HandleAuthenticateAsync() if (apiKey is not null) { var claims = new List(); - foreach (var role in apiKey.Roles) + if (apiKey.Roles is not null) { - claims.Add(new(Options.RoleClaimType, role)); + foreach (var role in apiKey.Roles) + { + claims.Add(new(Options.RoleClaimType, role)); + } } return CreateAuthenticationSuccessResult(apiKey.UserName, claims); diff --git a/src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs b/src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs index 21bd814..f8e54c0 100644 --- a/src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs +++ b/src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs @@ -59,9 +59,12 @@ protected override async Task HandleAuthenticateAsync() if (credential is not null) { var claims = new List(); - foreach (var role in credential.Roles) + if (credential.Roles is not null) { - claims.Add(new(Options.RoleClaimType, role)); + foreach (var role in credential.Roles) + { + claims.Add(new(Options.RoleClaimType, role)); + } } return CreateAuthenticationSuccessResult(credential.UserName, claims); diff --git a/src/SimpleAuthentication/SimpleAuthentication.csproj b/src/SimpleAuthentication/SimpleAuthentication.csproj index 1234ed7..14d2622 100644 --- a/src/SimpleAuthentication/SimpleAuthentication.csproj +++ b/src/SimpleAuthentication/SimpleAuthentication.csproj @@ -35,7 +35,7 @@ - +