HoneyDrunk.Auth.AspNetCore 0.2.0

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

HoneyDrunk.Auth.AspNetCore

NuGet License: MIT .NET 10

ASP.NET Core integration for HoneyDrunk.Auth - Middleware, identity accessors, and authorization endpoint helpers.

🌐 What Is This?

This package provides middleware and extensions for integrating HoneyDrunk.Auth with ASP.NET Core applications. It includes authentication middleware that automatically validates Bearer tokens, HttpContext-based identity accessors, and convenient authorization helpers for endpoints.

📦 Installation

dotnet add package HoneyDrunk.Auth.AspNetCore
<PackageReference Include="HoneyDrunk.Auth.AspNetCore" Version="0.1.0" />

🚀 Quick Start

1. Register Services

builder.Services.AddHoneyDrunkAuthAspNetCore();

2. Configure Middleware

app.UseGridContext();      // Grid context propagation
app.UseHoneyDrunkAuth();   // Authentication middleware

3. Access Identity

app.MapGet("/profile", (IAuthenticatedIdentityAccessor identity) =>
{
    if (!identity.IsAuthenticated)
        return Results.Unauthorized();

    return Results.Ok(new
    {
        identity.Identity!.SubjectId,
        identity.Identity.DisplayName,
        Roles = identity.Identity.GetClaimValues(AuthClaimTypes.Role)
    });
});

4. Authorize Requests

app.MapPost("/admin/action", async (HttpContext ctx) =>
{
    var request = new AuthorizationRequest(
        action: "admin",
        resource: "system",
        requiredRoles: ["admin"]);

    if (!await ctx.AuthorizeOrForbidAsync(request))
        return Results.Empty;  // 403 already sent

    // Authorized - perform action
    return Results.Ok();
});

🔧 Key Components

Middleware

Component Description
HoneyDrunkAuthMiddleware Validates Bearer tokens and sets identity on HttpContext
UseHoneyDrunkAuth() Extension method to add middleware to pipeline

Identity Access

Component Description
IAuthenticatedIdentityAccessor Interface to access current authenticated identity
HttpContextIdentityAccessor HttpContext-based implementation

Authorization Helpers

Method Description
AuthorizeAsync() Evaluates authorization, returns decision
AuthorizeOrForbidAsync() Evaluates authorization, sends 403 if denied
RequireAuthentication() Returns 401 if not authenticated

💡 Usage Examples

Check Authentication

app.MapGet("/me", (IAuthenticatedIdentityAccessor identity) =>
{
    if (!identity.IsAuthenticated)
        return Results.Unauthorized();

    return Results.Ok(new { identity.Identity!.SubjectId });
});

Role-Based Authorization

app.MapDelete("/users/{id}", async (HttpContext ctx, string id) =>
{
    var request = new AuthorizationRequest(
        action: "delete",
        resource: $"users/{id}",
        requiredRoles: ["admin"]);

    if (!await ctx.AuthorizeOrForbidAsync(request))
        return Results.Empty;

    // Delete user...
    return Results.NoContent();
});

Scope-Based Authorization

app.MapPost("/documents", async (HttpContext ctx) =>
{
    var request = new AuthorizationRequest(
        action: "create",
        resource: "documents",
        requiredScopes: ["documents:write"]);

    var decision = await ctx.AuthorizeAsync(request);
    
    if (!decision.IsAllowed)
    {
        return Results.Json(new
        {
            error = "Forbidden",
            reasons = decision.DenyReasons.Select(r => r.Message)
        }, statusCode: 403);
    }

    // Create document...
    return Results.Created("/documents/123", new { id = "123" });
});

Simple Authentication Check

app.MapGet("/protected", (HttpContext ctx) =>
{
    if (!ctx.RequireAuthentication())
        return Results.Empty;  // 401 already sent
    
    return Results.Ok("You are authenticated!");
});

🔀 Middleware Pipeline

The middleware should be placed after UseGridContext() for proper context propagation:

var app = builder.Build();

app.UseRouting();          // Route matching (if using controllers)
app.UseGridContext();      // Grid context propagation
app.UseHoneyDrunkAuth();   // Authentication middleware
app.UseAuthorization();    // Optional: ASP.NET Core authorization

app.MapControllers();
app.Run();

📋 What Gets Registered

When you call AddHoneyDrunkAuthAspNetCore():

Service Implementation Lifetime
ISigningKeyProvider VaultSigningKeyProvider Singleton
IAuthenticationProvider BearerTokenAuthenticationProvider Singleton
IAuthorizationPolicy DefaultAuthorizationPolicy Singleton
IStartupHook AuthStartupHook Singleton
IHealthContributor AuthHealthContributor Singleton
IReadinessContributor AuthReadinessContributor Singleton
IHttpContextAccessor HttpContextAccessor Singleton
IAuthenticatedIdentityAccessor HttpContextIdentityAccessor Singleton

📚 Dependencies

Package Purpose
HoneyDrunk.Auth Core authentication runtime
HoneyDrunk.Auth.Abstractions Core contracts
HoneyDrunk.Kernel Grid context and telemetry
Package Description
HoneyDrunk.Auth.Abstractions Core contracts (no dependencies)
HoneyDrunk.Auth Core runtime with JWT validation

📖 Documentation

⚖️ License

This project is licensed under the MIT License.


<div align="center">

Built with ❤️ by HoneyDrunk Studios

</div>

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 (1)

Showing the top 1 NuGet packages that depend on HoneyDrunk.Auth.AspNetCore:

Package Downloads
HoneyDrunk.Web.Rest.AspNetCore

ASP.NET Core integration for HoneyDrunk REST conventions. Provides middleware for correlation propagation, exception mapping, and request logging. Includes MVC filters for model validation, minimal API endpoint conventions, and JSON serialization defaults. Ensures consistent API responses across all services.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.2.0 110 2/14/2026
0.1.0 200 12/25/2025

v0.2.0: Updated HoneyDrunk.Kernel to 0.4.0 for scope-based GridContext support. Fixed XML doc cref on AddHoneyDrunkAuthAspNetCore.