DotNetBrightener.Infrastructure.Security 2026.0.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package DotNetBrightener.Infrastructure.Security --version 2026.0.2
                    
NuGet\Install-Package DotNetBrightener.Infrastructure.Security -Version 2026.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotNetBrightener.Infrastructure.Security" Version="2026.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DotNetBrightener.Infrastructure.Security" Version="2026.0.2" />
                    
Directory.Packages.props
<PackageReference Include="DotNetBrightener.Infrastructure.Security" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DotNetBrightener.Infrastructure.Security --version 2026.0.2
                    
#r "nuget: DotNetBrightener.Infrastructure.Security, 2026.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package DotNetBrightener.Infrastructure.Security@2026.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=DotNetBrightener.Infrastructure.Security&version=2026.0.2
                    
Install as a Cake Addin
#tool nuget:?package=DotNetBrightener.Infrastructure.Security&version=2026.0.2
                    
Install as a Cake Tool

Security Infratructure Library

Copyright © 2017 - 2026 Vampire Coder (formerly DotnetBrightener)

Installation

Run this in command line:

dotnet add package DotNetBrightener.Infrastructure.Security

Or add the following to .csproj file

<PackageReference Include="DotNetBrightener.Infrastructure.Security" Version="2022.10.0" />

You should check the latest version from Nuget Site

Adding Permission System

  1. Register the Permission System to IServiceCollection
serviceCollection.AddPermissionAuthorization();
  1. Calling the following before application starts.
var app = builder.Build();

// call this before app.Run()
app.LoadAndValidatePermissions();

app.Run();

If you use legacy Startup.cs file then the app.LoadAndValidatePermissions() should be called in Configure() method

Authorization Extensions

  1. Authorize with IAuthorizationService
var authorizationResult = await IAuthorizationService.AuthorizePermissionAsync(user, permissionKey);
  1. Authorize with [PermissionAuthorize] attribute

public class SomeController: Controller 
{
    [PermissionAuthorize("<your_permission_key>")]
    public async Task<IActionResult> SomeAction() 
    {
        // your action implementation
    }   
}

Automatically Register Permissions

Given the following class for defining permissions


public class SomePermissionsList: AutomaticPermissionProvider
{
    /// <summary>
    ///     Description for Permission 1
    /// </summary>
    public const string Permission1 = "ThisIsKey.OfThePermission";

    /// <summary>
    ///     Description for Permission 2
    /// </summary>
    public const string Permission2 = "Permission.Permission2";
}

You can register the permissions defined in this class into service collection by doing the following:

// with SomePermissionsList is the type of permission provider
serviceCollection.RegisterPermissionProvider<SomePermissionsList>();

The app.LoadAndValidatePermissions() call above should automatically register the permissions you defined in the class provided

Minimal API Support

The library provides extension methods for Minimal API endpoints using RequirePermission() and RequireAnyPermission().

Basic Permission Authorization (ALL required)

User must have ALL specified permissions:

// Single permission
app.MapGet("/api/users", GetUsers)
   .RequirePermission("UserManagement.View");

// Multiple permissions (ALL required)
app.MapDelete("/api/users/{id}", DeleteUser)
   .RequirePermission("UserManagement.Delete", "UserManagement.View");

Any Permission Authorization (OR logic)

User must have at least ONE of the specified permissions:

// Any one permission is sufficient
app.MapGet("/api/reports", GetReports)
   .RequireAnyPermission("Reports.View", "Reports.ViewAll", "Admin.Access");

Resource-Based Authorization

For scenarios where authorization depends on a specific resource:

// Single permission with resource
app.MapGet("/api/documents/{id}", async (int id, IDocumentService docService) =>
{
    var document = await docService.GetById(id);
    return Results.Ok(document);
}).RequirePermission("Document.View", documentResource);

// Multiple permissions for resource (ALL required)
app.MapPut("/api/documents/{id}", UpdateDocument)
   .RequirePermissionForResource(documentResource, "Document.Edit", "Document.View");

// Any permission for resource (OR logic)
app.MapGet("/api/projects/{id}", GetProject)
   .RequireAnyPermissionForResource(projectResource, "Project.View", "Project.ViewAll", "Admin.Access");

Allow Anonymous

Use [AllowAnonymous] attribute on the endpoint delegate or .AllowAnonymous() to bypass permission checks:

app.MapGet("/api/public/info", GetPublicInfo)
   .AllowAnonymous();

Summary of Extension Methods

Method Logic Resource Support
RequirePermission(params string[]) ALL required No
RequirePermission(string, object) Single permission Yes
RequirePermissionForResource(object, params string[]) ALL required Yes
RequireAnyPermission(params string[]) Any one No
RequireAnyPermissionForResource(object, params string[]) Any one Yes
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (4)

Showing the top 4 NuGet packages that depend on DotNetBrightener.Infrastructure.Security:

Package Downloads
DotNetBrightener.Infrastructure.JwtAuthentication

Package Description

DotNetBrightener.Infrastructure.ApiKeyAuthentication

Package Description

DotNetBrightener.WebApp.CommonShared

Package Description

DotNetBrightener.MultiTenancy

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2026.0.3-preview-772 38 4/3/2026
2026.0.3-preview-770 66 4/2/2026
2026.0.3-preview-769 59 4/2/2026
2026.0.2 67 4/2/2026
2026.0.2-preview-v2026-0-1-755 130 3/27/2026
2026.0.2-preview-759 110 4/1/2026
2026.0.2-preview-758 129 3/29/2026
2026.0.2-preview-757 123 3/29/2026
2026.0.2-preview-756 121 3/27/2026
2026.0.2-preview-754 111 3/27/2026
2026.0.1 121 3/27/2026
2026.0.1-preview-752 118 3/26/2026
2026.0.1-preview-750 115 3/26/2026
2026.0.1-preview-749 116 3/25/2026
2026.0.1-preview-748 114 3/23/2026
2026.0.1-preview-746 91 3/22/2026
2026.0.1-preview-745 95 3/22/2026
2025.0.11-preview-771 65 4/2/2026
2025.0.11-preview-768 65 4/2/2026
2025.0.11-preview-762 71 4/2/2026
Loading failed

Basic infrastructure provided for authorizing User with given permission