MinApiLib.Oidc.Http
1.0.0
dotnet add package MinApiLib.Oidc.Http --version 1.0.0
NuGet\Install-Package MinApiLib.Oidc.Http -Version 1.0.0
<PackageReference Include="MinApiLib.Oidc.Http" Version="1.0.0" />
<PackageVersion Include="MinApiLib.Oidc.Http" Version="1.0.0" />
<PackageReference Include="MinApiLib.Oidc.Http" />
paket add MinApiLib.Oidc.Http --version 1.0.0
#r "nuget: MinApiLib.Oidc.Http, 1.0.0"
#:package MinApiLib.Oidc.Http@1.0.0
#addin nuget:?package=MinApiLib.Oidc.Http&version=1.0.0
#tool nuget:?package=MinApiLib.Oidc.Http&version=1.0.0
MinApiLib.Oidc.Http
Access tokens for HttpClient, without ASP.NET Core. Add a handler to an HTTP client and each request carries the
client's own access token (client credentials grant), either a bearer token or a DPoP-bound token
(RFC 9449) with a new proof for each request.
It works with any OAuth 2.0 server, not only MinApiLib.Oidc.Server. It
depends on Microsoft.Extensions.Http, Microsoft.IdentityModel.Protocols.OpenIdConnect and
MinApiLib.Oidc.DPoP, and targets net10.0 and net11.0, so it fits workers,
console applications and web applications alike.
For the tokens of a user signed in with OpenID Connect in ASP.NET Core, use MinApiLib.Oidc.Authentication, which builds on this package.
Client credentials
builder.Services.AddClientCredentialsTokens("orders", options =>
{
options.Authority = "https://login.example.com";
options.ClientId = "worker";
options.ClientSecret = "secret";
options.Scope = "orders.read";
options.UseDPoP = true; // false, the default: bearer tokens
});
builder.Services.AddHttpClient("orders", client => client.BaseAddress = new Uri("https://orders.example.com"))
.AddClientCredentialsTokenHandler("orders");
var orders = await httpClientFactory.CreateClient("orders").GetFromJsonAsync<Order[]>("/orders");
The handler finds the token endpoint in the discovery document, or uses TokenEndpoint if you set it. It asks for a
token on the first request and reuses it until a minute before it expires (RenewBeforeExpiration). Concurrent
requests share one token request. With UseDPoP, the client creates an EC P-256 key in memory, or uses
DPoPJsonWebKey if you set it, and every token request and API call carries a proof of it.
IClientCredentialsTokenManager gives you the token directly:
await tokens.GetAccessTokenAsync("orders").
What the handlers do with each request
| Token | Request |
|---|---|
| Bearer | Authorization: Bearer <token> |
| DPoP | Authorization: DPoP <token> and DPoP: <proof>: a new proof for the method and URL, with the token hash (ath) |
When the token endpoint or the API answers use_dpop_nonce with a DPoP-Nonce header (RFC 9449, sections 8 and 9),
the handler sends the request once more with the nonce in the proof. It keeps the nonce of each server for the next
proofs. When the API answers 401 for another reason, the handler gets a new token and sends the request once more.
Resending works with content that can be read twice, such as StringContent, ByteArrayContent or JsonContent, but
not with StreamContent.
If the server answers token_type: Bearer to a DPoP request, because it does not support DPoP, the token is sent as a
bearer token.
Errors of the token endpoint throw AccessTokenException, with the OAuth Error and ErrorDescription.
Your own handlers
The handlers derive from AccessTokenHandler, which does all of the above; a derived class only says where the token
comes from. TokenEndpointClient posts token requests with a proof and the nonce retry. Register both with
services.AddTokenEndpointClient():
sealed class VaultTokenHandler(IVault vault, DPoPNonceStore nonces, TimeProvider time, ILogger<VaultTokenHandler> logger)
: AccessTokenHandler(nonces, time, logger)
{
protected override Task<AccessToken> GetAccessTokenAsync(bool forceRenewal, CancellationToken cancellationToken)
=> vault.GetTokenAsync(forceRenewal, cancellationToken);
}
HTTP clients
Token requests and discovery use the HttpClient named OidcHttpDefaults.HttpClientName. Configure it with
services.AddHttpClient(OidcHttpDefaults.HttpClientName) to add a proxy or a client certificate.
Samples
The worker sample calls the API with its own token, as a bearer token and as a DPoP-bound token.
License
Apache License 2.0, like MinApiLib.Oidc.Server. The repository's NOTICE holds the attribution.
| Product | Versions 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. net11.0 is compatible. |
-
net10.0
- Microsoft.Extensions.Http (>= 10.0.15)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.23.0)
- MinApiLib.Oidc.DPoP (>= 1.0.0)
-
net11.0
- Microsoft.Extensions.Http (>= 11.0.0)
- Microsoft.IdentityModel.Protocols.OpenIdConnect (>= 8.23.0)
- MinApiLib.Oidc.DPoP (>= 1.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on MinApiLib.Oidc.Http:
| Package | Downloads |
|---|---|
|
MinApiLib.Oidc.Authentication
The signed-in user's access tokens for HttpClient in ASP.NET Core: keeps the tokens of an OpenID Connect scheme in the session, refreshes them and sends them as bearer tokens or DPoP-bound (RFC 9449), with the authorization code bound to the key (dpop_jkt). Works with any OpenID Connect server. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 48 | 11/17/2026 |