From 4f974a243591dc23cf4cd34a73f6149e165df50d Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Wed, 11 Nov 2026 12:36:46 +0100 Subject: [PATCH] Update to .NET 11 --- .../SimpleAuthentication.Swashbuckle.csproj | 17 +++++++-- .../Swagger/OpenApiHelpers.cs | 36 ++++++++++++++++++- .../OpenApi/OpenApiHelpers.cs | 32 ++++++++++++++++- .../PermissionAuthorizationPolicyProvider.cs | 10 ++++++ .../SimpleAuthentication.csproj | 12 ++++--- 5 files changed, 98 insertions(+), 9 deletions(-) diff --git a/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj b/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj index 1232416..04ce9b8 100644 --- a/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj +++ b/src/SimpleAuthentication.Swashbuckle/SimpleAuthentication.Swashbuckle.csproj @@ -1,7 +1,7 @@  - net8.0;net9.0;net10.0 + net8.0;net9.0;net10.0;net11.0 enable enable latest @@ -31,9 +31,20 @@ + + + + + + + + + + + + - - + diff --git a/src/SimpleAuthentication.Swashbuckle/Swagger/OpenApiHelpers.cs b/src/SimpleAuthentication.Swashbuckle/Swagger/OpenApiHelpers.cs index 5c51db9..5d14e45 100644 --- a/src/SimpleAuthentication.Swashbuckle/Swagger/OpenApiHelpers.cs +++ b/src/SimpleAuthentication.Swashbuckle/Swagger/OpenApiHelpers.cs @@ -1,4 +1,36 @@ -using System.Net.Mime; +#if NET11_0_OR_GREATER + +using System.Net.Mime; +using Microsoft.AspNetCore.Mvc; +using Microsoft.OpenApi; + +namespace SimpleAuthentication.Swagger; + +internal static class OpenApiHelpers +{ + public static OpenApiSecurityRequirement CreateSecurityRequirement(string name, OpenApiDocument document) + => new() + { + { new OpenApiSecuritySchemeReference(name, document), [] } + }; + + public static OpenApiResponse CreateResponse(string description) + => new() + { + Description = description, + Content = new Dictionary + { + [MediaTypeNames.Application.ProblemJson] = new OpenApiMediaType + { + Schema = new OpenApiSchemaReference(nameof(ProblemDetails)) + } + } + }; +} + +#else + +using System.Net.Mime; using Microsoft.AspNetCore.Mvc; using Microsoft.OpenApi; @@ -25,3 +57,5 @@ public static OpenApiResponse CreateResponse(string description) } }; } + +#endif \ No newline at end of file diff --git a/src/SimpleAuthentication/OpenApi/OpenApiHelpers.cs b/src/SimpleAuthentication/OpenApi/OpenApiHelpers.cs index be413df..9655f81 100644 --- a/src/SimpleAuthentication/OpenApi/OpenApiHelpers.cs +++ b/src/SimpleAuthentication/OpenApi/OpenApiHelpers.cs @@ -45,7 +45,7 @@ public static OpenApiResponse CreateResponse(string description) }; } -#elif NET10_0_OR_GREATER +#elif NET10_0 using System.Net.Mime; using Microsoft.AspNetCore.Mvc; @@ -75,4 +75,34 @@ public static OpenApiResponse CreateResponse(string description) }; } +#elif NET11_0_OR_GREATER + +using System.Net.Mime; +using Microsoft.AspNetCore.Mvc; +using Microsoft.OpenApi; + +namespace SimpleAuthentication.OpenApi; + +internal static class OpenApiHelpers +{ + public static OpenApiSecurityRequirement CreateSecurityRequirement(string name, OpenApiDocument document) + => new() + { + { new OpenApiSecuritySchemeReference(name, document), [] } + }; + + public static OpenApiResponse CreateResponse(string description) + => new() + { + Description = description, + Content = new Dictionary + { + [MediaTypeNames.Application.ProblemJson] = new OpenApiMediaType + { + Schema = new OpenApiSchemaReference(nameof(ProblemDetails)) + } + } + }; +} + #endif \ No newline at end of file diff --git a/src/SimpleAuthentication/Permissions/PermissionAuthorizationPolicyProvider.cs b/src/SimpleAuthentication/Permissions/PermissionAuthorizationPolicyProvider.cs index cc6c9a1..3f943f7 100644 --- a/src/SimpleAuthentication/Permissions/PermissionAuthorizationPolicyProvider.cs +++ b/src/SimpleAuthentication/Permissions/PermissionAuthorizationPolicyProvider.cs @@ -3,11 +3,21 @@ namespace SimpleAuthentication.Permissions; +/// +/// Resolves explicitly registered authorization policies and dynamically creates permission-based policies when no match is found. +/// +/// +/// An unknown policy name is treated as a permission name and converted into an +/// containing a for that permission. +/// internal class PermissionAuthorizationPolicyProvider(IOptions options) : DefaultAuthorizationPolicyProvider(options) { public override async Task GetPolicyAsync(string policyName) { + // Check if the policy is already registered in the options. var policy = await base.GetPolicyAsync(policyName); + + // If not, create a new policy with a PermissionRequirement for the given policy name. policy ??= new AuthorizationPolicyBuilder().AddRequirements(new PermissionRequirement(policyName)).Build(); return policy; diff --git a/src/SimpleAuthentication/SimpleAuthentication.csproj b/src/SimpleAuthentication/SimpleAuthentication.csproj index c4091ea..3b779b1 100644 --- a/src/SimpleAuthentication/SimpleAuthentication.csproj +++ b/src/SimpleAuthentication/SimpleAuthentication.csproj @@ -1,7 +1,7 @@  - net8.0;net9.0;net10.0 + net8.0;net9.0;net10.0;net11.0 enable enable latest @@ -31,15 +31,19 @@ - + - + + + + + - +