Making.Security 1.0.4-preview

This is a prerelease version of Making.Security.
dotnet add package Making.Security --version 1.0.4-preview
                    
NuGet\Install-Package Making.Security -Version 1.0.4-preview
                    
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="Making.Security" Version="1.0.4-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Making.Security" Version="1.0.4-preview" />
                    
Directory.Packages.props
<PackageReference Include="Making.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 Making.Security --version 1.0.4-preview
                    
#r "nuget: Making.Security, 1.0.4-preview"
                    
#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 Making.Security@1.0.4-preview
                    
#: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=Making.Security&version=1.0.4-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Making.Security&version=1.0.4-preview&prerelease
                    
Install as a Cake Tool

Making.Security

Security utilities and extensions for the Making framework.

Overview

Making.Security provides essential security components and utilities for the Making framework. It includes current user management, claims handling, principal access, and security-related extensions for building secure applications.

Features

  • Current User Access: Easy access to current user information
  • Claims Management: Comprehensive claims handling and extraction
  • Principal Access: Current principal accessor for security context
  • Security Extensions: ClaimsIdentity extensions for common operations
  • User Context: Centralized user context management
  • Security Abstractions: Core security interfaces and contracts

Installation

dotnet add package Making.Security

Usage

Register Services

services.AddMakingSecurity();

Current User Access

public class UserService
{
    private readonly ICurrentUser _currentUser;
    
    public UserService(ICurrentUser currentUser)
    {
        _currentUser = currentUser;
    }
    
    public async Task<UserProfile> GetCurrentUserProfileAsync()
    {
        var userId = _currentUser.UserId;
        var userName = _currentUser.UserName;
        var email = _currentUser.Email;
        var roles = _currentUser.Roles;
        
        return new UserProfile
        {
            Id = userId,
            Name = userName,
            Email = email,
            Roles = roles
        };
    }
    
    public bool CanAccessResource(string resourceId)
    {
        return _currentUser.IsInRole("Admin") || 
               _currentUser.HasClaim("Resource", resourceId);
    }
}

Claims Extensions

public class AuthController : ControllerBase
{
    [HttpGet("profile")]
    public IActionResult GetProfile()
    {
        var identity = HttpContext.User.Identity as ClaimsIdentity;
        
        var userId = identity.GetUserId();
        var userName = identity.GetUserName();
        var email = identity.GetEmail();
        var roles = identity.GetRoles();
        
        return Ok(new
        {
            UserId = userId,
            UserName = userName,
            Email = email,
            Roles = roles
        });
    }
}

Custom Claims

public class CustomAuthService
{
    private readonly ICurrentPrincipalAccessor _principalAccessor;
    
    public CustomAuthService(ICurrentPrincipalAccessor principalAccessor)
    {
        _principalAccessor = principalAccessor;
    }
    
    public bool HasPermission(string permission)
    {
        var principal = _principalAccessor.Principal;
        return principal?.HasClaim(MakingClaimType.Permission, permission) ?? false;
    }
    
    public string GetTenantId()
    {
        var principal = _principalAccessor.Principal;
        return principal?.FindFirst(MakingClaimType.TenantId)?.Value;
    }
}

Making Claim Types

public static class MakingClaimType
{
    public const string UserId = "mark:userid";
    public const string UserName = "mark:username";
    public const string Email = "mark:email";
    public const string Role = "mark:role";
    public const string Permission = "mark:permission";
    public const string TenantId = "mark:tenantid";
}

Authorization Policies

public class Startup
{
    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMakingSecurity();
        
        services.AddAuthorization(options =>
        {
            options.AddPolicy("RequireAdminRole", policy =>
                policy.RequireClaim(MakingClaimType.Role, "Admin"));
                
            options.AddPolicy("RequireUserPermission", policy =>
                policy.RequireClaim(MakingClaimType.Permission, "user:read"));
        });
    }
}

[Authorize(Policy = "RequireAdminRole")]
public class AdminController : ControllerBase
{
    // Admin-only actions
}

Multi-Tenant Security

public class TenantService
{
    private readonly ICurrentUser _currentUser;
    
    public TenantService(ICurrentUser currentUser)
    {
        _currentUser = currentUser;
    }
    
    public async Task<List<Order>> GetOrdersAsync()
    {
        var tenantId = _currentUser.TenantId;
        
        // Filter orders by current user's tenant
        return await _orderRepository.GetByTenantAsync(tenantId);
    }
}

Requirements

  • .NET Standard 2.0+
  • ASP.NET Core
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • Making.Core

License

This project is part of the Making framework.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  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.  net10.0 was computed.  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 (2)

Showing the top 2 NuGet packages that depend on Making.Security:

Package Downloads
Making.Jwt

JWT authentication and authorization support for the Making framework

Making.EntityFrameworkCore

Entity Framework Core integration for the Making framework

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.4-preview 79 8/10/2025
1.0.1-preview 338 7/25/2025
1.0.0-preview 394 7/25/2025