Hexalith.Security.WebServer 2.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package Hexalith.Security.WebServer --version 2.1.1
                    
NuGet\Install-Package Hexalith.Security.WebServer -Version 2.1.1
                    
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="Hexalith.Security.WebServer" Version="2.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hexalith.Security.WebServer" Version="2.1.1" />
                    
Directory.Packages.props
<PackageReference Include="Hexalith.Security.WebServer" />
                    
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 Hexalith.Security.WebServer --version 2.1.1
                    
#r "nuget: Hexalith.Security.WebServer, 2.1.1"
                    
#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.
#addin nuget:?package=Hexalith.Security.WebServer&version=2.1.1
                    
Install Hexalith.Security.WebServer as a Cake Addin
#tool nuget:?package=Hexalith.Security.WebServer&version=2.1.1
                    
Install Hexalith.Security.WebServer as a Cake Tool

Hexalith.Security

Overview

Hexalith.Security is a comprehensive security framework for .NET applications providing authentication, authorization, and identity management capabilities. Built with modern C# and Blazor, it offers a robust approach to implementing security in web applications, API servers, and microservices.

Build Status

License: MIT Discord

Coverity Scan Build Status Codacy Badge Quality Gate Status Security Rating Maintainability Rating Code Smells Lines of Code Technical Debt Reliability Rating Duplicated Lines (%) Vulnerabilities Bugs

Build status NuGet Latest

Architecture

The Hexalith.Security project follows a modular architecture with clear separation of concerns:

Core Components

  • Abstractions: Defines interfaces, models, and contracts for security features
  • Application: Business logic and services for security functionality
  • Infrastructure: Implementation of data access and external service integration
  • Presentation: UI components and pages for user interactions
  • Modules: Integration modules for different application types (WebApp, WebServer, ApiServer)

Integration with Hexalith Framework

The security module integrates with:

  • Hexalith.IdentityStores: For identity storage and management
  • Hexalith.Application: For application module integration
  • Hexalith.Infrastructure.DaprRuntime: For distributed application runtime support

Modules

WebApp Module (HexalithSecurityWebAppModule)

Client-side authentication and authorization for Blazor WebAssembly applications:

// Program.cs
var builder = WebAssemblyHostBuilder.CreateDefault(args);
// ...
HexalithSecurityWebAppModule.AddServices(builder.Services, builder.Configuration);

WebServer Module (HexalithSecurityWebServerModule)

Server-side authentication and authorization:

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Services.AddModule<HexalithSecurityWebServerModule>(builder.Configuration);

var app = builder.Build();
// ...
app.UseModule<HexalithSecurityWebServerModule>();
app.UseSecurity<HexalithSecurityWebServerModule>();

ApiServer Module (HexalithSecurityApiServerModule)

Security for API-focused applications:

// Program.cs
var builder = WebApplication.CreateBuilder(args);
// ...
builder.Services.AddModule<HexalithSecurityApiServerModule>(builder.Configuration);

Security Features

  • Authentication: ASP.NET Core Authentication, multiple schemes, Dapr-based authentication
  • Authorization: Policy-based, role-based access control
  • Predefined Security Roles: Owner, Contributor, Reader
  • Predefined Security Policies: For respective roles

Repository Structure

The repository is organized as follows:

  • src Is the source code directory of your project.
  • src/libraries Is the source code directory where you will add your Nuget package projects.
  • src/examples Contains example implementations of your projects.
  • src/servers Is the source code directory where you will add your Docker container projects.
  • src/aspire Is the source code directory where you will add your Aspire project.
  • test Contains test projects for your packages.
  • Hexalith.Builds Contains shared build configurations and tools.

Getting Started

Prerequisites

Installation

Add the Hexalith.Security NuGet package to your project:

dotnet add package Hexalith.Security

Configuration

Configure security settings in your appsettings.json:

{
  "Security": {
    "Disabled": false
  }
}

Examples

Protecting a Blazor Page

@page "/secure-page"
@attribute [Authorize]
<h1>Secure Page</h1>

<p>This page is only accessible to authenticated users.</p>

Using Role-Based Authorization

@page "/admin-page"
@attribute [Authorize(Roles = SecurityRoles.Owner)]
<h1>Admin Page</h1>

<p>This page is only accessible to users with the Owner role.</p>

Using Policy-Based Authorization

@page "/contributor-page"
@attribute [Authorize(Policy = SecurityPolicies.Contributors)]
<h1>Contributors Page</h1>

<p>This page is only accessible to users who can contribute.</p>

Best Practices

  1. Use predefined roles and policies whenever possible
  2. Implement the principle of least privilege by assigning minimum required permissions
  3. Validate authorization at both UI and API levels
  4. Configure proper authentication mechanisms based on your application type
  5. Use cascading authentication state in Blazor applications for optimal performance

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support and Community

For support, please open an issue on the GitHub repository.

Join our Discord community: Hexalith Discord

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.6 0 4/22/2025
2.1.5 0 4/22/2025
2.1.4 0 4/22/2025
2.1.3 0 4/22/2025
2.1.2 41 4/21/2025
2.1.1 40 4/21/2025
2.1.0 36 4/21/2025
2.0.1 40 4/21/2025
2.0.0 43 4/19/2025
1.54.6 142 3/19/2025
1.54.5 138 3/19/2025
1.53.4 138 3/18/2025
1.53.3 156 3/11/2025
1.53.0 92 2/28/2025
1.52.14 97 1/15/2025
1.52.10 97 1/10/2025
1.52.8 100 1/6/2025
1.52.7 89 1/6/2025
1.51.8 117 12/15/2024
1.51.7 81 12/15/2024
1.51.4 118 12/7/2024
1.1.1 45 4/19/2025
1.1.0 45 4/19/2025
1.0.41 149 11/25/2024
1.0.40 90 11/25/2024
1.0.0 50 4/19/2025