Skip to content

Commit ea096d5

Browse files
committed
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.
1 parent 96a8229 commit ea096d5

4 files changed

Lines changed: 12 additions & 6 deletions

File tree

src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</ItemGroup>
3333

3434
<ItemGroup>
35-
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.3" />
35+
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.4" />
3636
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="9.0.6" />
3737
</ItemGroup>
3838

src/SimpleAuthentication/ApiKey/ApiKeyAuthenticationHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
4545
if (apiKey is not null)
4646
{
4747
var claims = new List<Claim>();
48-
foreach (var role in apiKey.Roles)
48+
if (apiKey.Roles is not null)
4949
{
50-
claims.Add(new(Options.RoleClaimType, role));
50+
foreach (var role in apiKey.Roles)
51+
{
52+
claims.Add(new(Options.RoleClaimType, role));
53+
}
5154
}
5255

5356
return CreateAuthenticationSuccessResult(apiKey.UserName, claims);

src/SimpleAuthentication/BasicAuthentication/BasicAuthenticationHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ protected override async Task<AuthenticateResult> HandleAuthenticateAsync()
5959
if (credential is not null)
6060
{
6161
var claims = new List<Claim>();
62-
foreach (var role in credential.Roles)
62+
if (credential.Roles is not null)
6363
{
64-
claims.Add(new(Options.RoleClaimType, role));
64+
foreach (var role in credential.Roles)
65+
{
66+
claims.Add(new(Options.RoleClaimType, role));
67+
}
6568
}
6669

6770
return CreateAuthenticationSuccessResult(credential.UserName, claims);

src/SimpleAuthentication/SimpleAuthentication.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</ItemGroup>
3636

3737
<ItemGroup>
38-
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.3" />
38+
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.4" />
3939
</ItemGroup>
4040

4141
<ItemGroup>

0 commit comments

Comments
 (0)