Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -31,9 +31,20 @@
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="[10.3.1]" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="[10.3.1, 11.0.0)" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net11.0'">
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.14" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="10.2.3" />
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.15" />
</ItemGroup>

<ItemGroup>
Expand Down
36 changes: 35 additions & 1 deletion src/SimpleAuthentication.Swashbuckle/Swagger/OpenApiHelpers.cs
Original file line number Diff line number Diff line change
@@ -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<string, IOpenApiMediaType>
{
[MediaTypeNames.Application.ProblemJson] = new OpenApiMediaType
{
Schema = new OpenApiSchemaReference(nameof(ProblemDetails))
}
}
};
}

#else

using System.Net.Mime;
using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi;

Expand All @@ -25,3 +57,5 @@ public static OpenApiResponse CreateResponse(string description)
}
};
}

#endif
32 changes: 31 additions & 1 deletion src/SimpleAuthentication/OpenApi/OpenApiHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string, IOpenApiMediaType>
{
[MediaTypeNames.Application.ProblemJson] = new OpenApiMediaType
{
Schema = new OpenApiSchemaReference(nameof(ProblemDetails))
}
}
};
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@

namespace SimpleAuthentication.Permissions;

/// <summary>
/// Resolves explicitly registered authorization policies and dynamically creates permission-based policies when no match is found.
/// </summary>
/// <remarks>
/// An unknown policy name is treated as a permission name and converted into an <see cref="AuthorizationPolicy"/>
/// containing a <see cref="PermissionRequirement"/> for that permission.
/// </remarks>
internal class PermissionAuthorizationPolicyProvider(IOptions<AuthorizationOptions> options) : DefaultAuthorizationPolicyProvider(options)
{
public override async Task<AuthorizationPolicy?> 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;
Expand Down
12 changes: 8 additions & 4 deletions src/SimpleAuthentication/SimpleAuthentication.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0;net10.0;net11.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -31,15 +31,19 @@
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.20" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.23" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.12" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.15" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net11.0'">
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="11.0.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.14" />
<PackageReference Include="SimpleAuthenticationTools.Abstractions" Version="3.1.15" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading