From d1bcf54dd4de03d3c6fd2a06b43b48966c3298a8 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Wed, 12 Nov 2025 15:48:39 +0100 Subject: [PATCH] Add new endpoint, update dependencies, and improve robustness Updated `Program.cs` to add a new `api/me` endpoint for retrieving user information and removed `.WithOpenApi()` from the `refresh` endpoint. Updated `Net8JwtBearerSample.csproj` to allow a version range for `Microsoft.AspNetCore.OpenApi` and ensure compatibility with future versions. Refactored `SimpleAuthentication.Swashbuckle.csproj` and `SimpleAuthentication.csproj` to replace project references with package references, including `SimpleAuthenticationTools.Abstractions` and `Swashbuckle.AspNetCore.SwaggerGen`. Improved `AuthenticationOperationFilter.cs` by initializing `operation.Responses` to prevent null reference issues when adding status codes. These changes enhance functionality, improve dependency management, and ensure compatibility with newer library versions. --- samples/MinimalApis/JwtBearerSample/Program.cs | 3 +-- .../Net8JwtBearerSample/Net8JwtBearerSample.csproj | 2 +- .../SimpleAuthentication.Swashbuckle.csproj | 13 +++++-------- .../Swagger/AuthenticationOperationFilter.cs | 1 + .../SimpleAuthentication.csproj | 8 ++++---- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/samples/MinimalApis/JwtBearerSample/Program.cs b/samples/MinimalApis/JwtBearerSample/Program.cs index e66b998..1aade6a 100644 --- a/samples/MinimalApis/JwtBearerSample/Program.cs +++ b/samples/MinimalApis/JwtBearerSample/Program.cs @@ -103,8 +103,7 @@ { var newToken = await jwtBearerService.RefreshTokenAsync(token, validateLifetime, expiration); return TypedResults.Ok(new LoginResponse(newToken)); -}) -.WithOpenApi(); +}); app.MapGet("api/me", (ClaimsPrincipal user) => { diff --git a/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj b/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj index 54fc3da..9e6cfe8 100644 --- a/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj +++ b/samples/MinimalApis/Net8JwtBearerSample/Net8JwtBearerSample.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj b/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj index ac43c14..11d5be7 100644 --- a/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj +++ b/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj @@ -31,6 +31,11 @@ + + + + + True @@ -39,12 +44,4 @@ - - - - - - - - diff --git a/src/SimpleAuthentication.Swashbuckle/Swagger/AuthenticationOperationFilter.cs b/src/SimpleAuthentication.Swashbuckle/Swagger/AuthenticationOperationFilter.cs index d23df59..27739a0 100644 --- a/src/SimpleAuthentication.Swashbuckle/Swagger/AuthenticationOperationFilter.cs +++ b/src/SimpleAuthentication.Swashbuckle/Swagger/AuthenticationOperationFilter.cs @@ -22,6 +22,7 @@ public async Task ApplyAsync(OpenApiOperation operation, OperationFilterContext if ((requireAuthenticatedUser || requireAuthorization) && !allowAnonymous) { + operation.Responses ??= []; operation.Responses.TryAdd(StatusCodes.Status401Unauthorized.ToString(), OpenApiHelpers.CreateResponse(HttpStatusCode.Unauthorized.ToString())); operation.Responses.TryAdd(StatusCodes.Status403Forbidden.ToString(), OpenApiHelpers.CreateResponse(HttpStatusCode.Forbidden.ToString())); } diff --git a/src/SimpleAuthentication/SimpleAuthentication.csproj b/src/SimpleAuthentication/SimpleAuthentication.csproj index d7457d8..6e60cc4 100644 --- a/src/SimpleAuthentication/SimpleAuthentication.csproj +++ b/src/SimpleAuthentication/SimpleAuthentication.csproj @@ -38,6 +38,10 @@ + + + + True @@ -46,8 +50,4 @@ - - - -