Frank.Auth
7.3.3
dotnet add package Frank.Auth --version 7.3.3
NuGet\Install-Package Frank.Auth -Version 7.3.3
<PackageReference Include="Frank.Auth" Version="7.3.3" />
<PackageVersion Include="Frank.Auth" Version="7.3.3" />
<PackageReference Include="Frank.Auth" />
paket add Frank.Auth --version 7.3.3
#r "nuget: Frank.Auth, 7.3.3"
#:package Frank.Auth@7.3.3
#addin nuget:?package=Frank.Auth&version=7.3.3
#tool nuget:?package=Frank.Auth&version=7.3.3
Frank.Auth
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 |
Related Packages
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
| Product | Versions 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. |
-
net10.0
- Frank (>= 7.3.3)
- FSharp.Core (>= 10.1.302)
-
net8.0
- Frank (>= 7.3.3)
- FSharp.Core (>= 10.1.302)
-
net9.0
- Frank (>= 7.3.3)
- FSharp.Core (>= 10.1.302)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
### 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.