ApricotFramework.Authentication 0.1.0

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

ApricotFramework.Authentication

NuGet NuGet NuGet CI License

Both directions of a microservice's authentication from one settings section: JWT bearer validation for the requests it serves, and OAuth 2.0 client credentials tokens for the services it calls — discovered, cached until shortly before they expire, and coalesced so a cold start makes one token request rather than one per caller.

ApricotFramework.Authentication is the zero-dependency core, and works in a console or worker host without ASP.NET Core.

Install

dotnet add package ApricotFramework.Authentication.AspNetCore
dotnet add package ApricotFramework.Authentication.ErrorDefinitions   # to answer with problem+json

Usage

// Inbound validation and the outbound client, from one section.
builder.Services.AddJwtBearerAuthentication(builder.Configuration);
builder.Services.AddAuthorization();
builder.Services.AddAuthenticationErrorDefinitions();
{
  "Authentication": {
    "Authority": "https://idp.example.com",
    "ValidAudiences": [ "orders-api" ],
    "Client": {
      // The secret comes from the environment, as Authentication__Client__ClientSecret.
      "ClientId": "orders-service",
      "Scopes": [ "billing.read" ]
    }
  }
}
[HttpGet("{id}")]
[BearerAuthorize]
public async Task<Order> Get(string id, CancellationToken cancellationToken)
{
    // Works for a person and for a service alike: Subject is null for a machine token, because a
    // client credentials grant has no resource owner to name.
    var caller = this.HttpContext.GetPrincipal();

    return await this.authenticator.DoAuthenticatedAsync(
        (token, ct) => this.billing.GetAsync(id, token, ct),
        cancellationToken: cancellationToken);
}

Note. A token this service could not obtain for an onward call never answers 401 or 403. The caller presented a good credential; it is this service that could not present one of its own, so it answers 503 when waiting may help and 500 when it will not.

Full documentation at projectapricot.dev.

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.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ApricotFramework.Authentication:

Package Downloads
ApricotFramework.Authentication.AspNetCore

ASP.NET Core integration for ApricotFramework.Authentication: JWT bearer validation configured from one settings section, a service-to-service client whose credentials come from the same section, and startup validation that rejects a resource server which could never accept a token.

ApricotFramework.Grpc.Client.Authentication

Presents this service's own access token on outbound gRPC calls, obtained through ApricotFramework.Authentication, and reports a failure to obtain one as a fault of this service rather than of whoever called it.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 142 8/19/2026