Frank.Auth 7.3.3

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

Frank.Auth

NuGet Version

Resource- and handler-level authorization for Frank applications, integrating with ASP.NET Core's built-in authorization infrastructure.

Installation

dotnet add package Frank.Auth

Protecting Resources

Add authorization requirements directly to resource definitions:

open Frank.Builder
open Frank.Auth

// Require any authenticated user
let dashboard =
    resource "/dashboard" {
        name "Dashboard"
        requireAuth
        get (fun ctx -> ctx.Response.WriteAsync("Welcome to Dashboard"))
    }

// Require a specific claim
let adminPanel =
    resource "/admin" {
        name "Admin"
        requireClaim "role" "admin"
        get (fun ctx -> ctx.Response.WriteAsync("Admin Panel"))
    }

// Require a role
let engineering =
    resource "/engineering" {
        name "Engineering"
        requireRole "Engineering"
        get (fun ctx -> ctx.Response.WriteAsync("Engineering Portal"))
    }

// Reference a named policy
let reports =
    resource "/reports" {
        name "Reports"
        requirePolicy "CanViewReports"
        get (fun ctx -> ctx.Response.WriteAsync("Reports"))
    }

// Compose requirements (AND semantics — all must pass)
let sensitive =
    resource "/api/sensitive" {
        name "Sensitive"
        requireAuth
        requireClaim "scope" "admin"
        requireRole "Engineering"
        get (fun ctx -> ctx.Response.WriteAsync("Sensitive data"))
    }

Protecting Individual Methods

Add authorization requirements to a single handler instead of the whole resource, using the handler { } computation expression — the resource stays public except for the method that opts in:

// GET is public, DELETE requires the admin role
let widgets =
    resource "/widgets" {
        name "Widgets"
        get listWidgets
        delete (handler {
            requireRole "admin"
            handle (fun (ctx: HttpContext) -> ctx.Response.WriteAsync("deleted"))
        })
    }

Handler-level requirements compose with resource-level ones (AND semantics) — a resource marked requireAuth with a handler that adds requireRole "admin" needs both. To let one method opt back out entirely, use allowAnonymous:

// The resource requires authentication, but this one method stays public
let profile =
    resource "/profile" {
        name "Profile"
        requireAuth
        get (handler {
            allowAnonymous
            handle (fun (ctx: HttpContext) -> ctx.Response.WriteAsync("public summary"))
        })
        put updateProfile
    }

allowAnonymous is a full bypass, not a downgrade — via ASP.NET Core's own IAllowAnonymous semantics, it skips every authorization requirement on that handler, resource-level and handler-level alike, even ones declared alongside it.

Application Wiring

Configure authentication and authorization services using Frank's builder syntax:

[<EntryPoint>]
let main args =
    webHost args {
        useDefaults

        useAuthentication (fun auth ->
            // Configure your authentication scheme here
            auth)

        useAuthorization

        authorizationPolicy "CanViewReports" (fun policy ->
            policy.RequireClaim("scope", "reports:read") |> ignore)

        resource dashboard
        resource adminPanel
        resource reports
    }
    0

Authorization Patterns

Every require* pattern below works identically at the resource level (resource { requireRole ... }) and the handler level (handler { requireRole ... }), and composes with AND semantics when used at both levels on the same endpoint.

Pattern Operation Behavior
Authenticated user requireAuth 401 if unauthenticated, 200 if authenticated
Claim (single value) requireClaim "type" "value" 403 if claim missing or wrong value
Claim (multiple values) requireClaim "type" ["a"; "b"] 200 if user has any listed value (OR)
Role requireRole "Admin" 403 if user not in role
Named policy requirePolicy "PolicyName" Delegates to registered policy
Bypass (handler-level only) allowAnonymous Skips all authorization on that one handler — resource- and handler-level requirements alike
Multiple requirements Stack multiple require* AND semantics — all must pass
No requirements (default) Publicly accessible, zero overhead

Requires Frank. Pairs well with Frank.JsonHome, which reads the same authorization metadata to filter its discovery document per principal.

See the project repository for the complete guide and sample applications.

License

MIT

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 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

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
7.3.3 149 8/11/2026
7.3.2 133 8/10/2026
7.2.1 142 6/22/2026
7.2.0 170 2/10/2026
7.1.0 163 2/8/2026
7.0.0-build.0 106 2/6/2026

### New in 7.3.3 (Released 2026-08-10)
**Frank.Rdf - Async IBufferWriter Streaming**
- **New: `Doc.writeJsonLdAsync doc bufferWriter`** — async overload that writes JSON-LD expanded-form directly to an `IBufferWriter<byte>` (e.g. `HttpResponse.BodyWriter`/`PipeWriter`), without intermediate string allocation or copying. Encodes UTF8 directly to the buffer for maximum efficiency in response streaming. Completes after serialization and flushing to the buffer.
- **Recommended for response streaming:** `writeJsonLdAsync` is the preferred method when serving JSON-LD from a Frank handler over HTTP. Streaming directly to `PipeWriter` avoids `AllowSynchronousIO` requirements and eliminates intermediate buffering layers that `StreamWriter` would introduce.
- **Three serialization options now available:** Use `writeJsonLdAsync` for HTTP responses (most efficient), `writeJsonLd` for flexibility with any `TextWriter`, and `toJsonLd` for testing/debugging.
- **Sample updated:** `sample/Frank.Rdf.Sample` demonstrates `Doc.writeJsonLdAsync` streaming the `application/ld+json` representation directly to the response body via `negotiate { }` content negotiation.
- **Test coverage:** comprehensive test cases for `writeJsonLdAsync` including single and multi-subject documents, language-tagged strings, and round-trip parsing.