Goodtocode.SecuredHttpClient 1.1.7

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

Goodtocode.SecuredHttpClient

NuGet CI/CD

A secure, resilient HTTP client registration and access token management library for .NET and Blazor. Easily add OAuth2-protected HttpClients to your application with support for both Client Credentials and Authorization Code PKCE flows.

Features

  • Register HttpClients that automatically acquire and attach OAuth2 access tokens
  • Supports Client Credentials and Authorization Code PKCE flows
  • Built-in token caching and refresh
  • Pluggable token providers via IAccessTokenProvider
  • Resilience (retry with jitter) for HTTP requests
  • Extension methods for adding bearer tokens to requests
  • Simple integration with Blazor, ASP.NET Core, and .NET DI

Installation

Install via NuGet:

dotnet add package Goodtocode.SecuredHttpClient

Quick Start

1. Register a Secured HttpClient (Blazor/ASP.NET Core)

Client Credentials Flow
services.AddClientCredentialHttpClient(
    configuration, // IConfiguration
    clientName: "MyApiClient",
    baseAddress: new Uri("https://api.example.com"),
    maxRetry: 5 // optional
);
Authorization Code PKCE Flow
services.AddAuthCodePkceHttpClient(
    configuration, // IConfiguration
    clientName: "MyApiClient",
    baseAddress: new Uri("https://api.example.com"),
    maxRetry: 5 // optional
);
Custom Registration for Blazor RCL
public static IServiceCollection AddAccessTokenHttpClient(
    this IServiceCollection services,
    Action<ResilientHttpClientOptions> configureOptions)
{
    var options = new ResilientHttpClientOptions();
    configureOptions(options);

    if (options.BaseAddress == null)
        throw new ArgumentNullException(nameof(configureOptions), "BaseAddress must be provided.");
    if (string.IsNullOrWhiteSpace(options.ClientName))
        throw new ArgumentNullException(nameof(configureOptions), "ClientName must be provided.");

    services.AddOptions<AuthCodePkceOptions>()
        .ValidateDataAnnotations()
        .ValidateOnStart();
    services.AddScoped<IAccessTokenProvider, DownstreamApiAccessTokenProvider>();
    services.AddScoped<TokenHandler>();

    services.AddHttpClient(options.ClientName, clientOptions =>
    {
        clientOptions.DefaultRequestHeaders.Clear();
        clientOptions.BaseAddress = options.BaseAddress;
    })
    .AddHttpMessageHandler<TokenHandler>()
    .AddStandardResilienceHandler(resilienceOptions =>
    {
        resilienceOptions.Retry.UseJitter = true;
        resilienceOptions.Retry.MaxRetryAttempts = options.MaxRetry;
    });

    return services;
}

2. Add Bearer Token to HttpClient (Manual)

using Goodtocode.SecuredHttpClient.Extensions;

httpClient.AddBearerToken("your-access-token");

Options

  • ClientCredentialOptions: For client credentials flow (ClientId, ClientSecret, TokenUrl, Scope)
  • AuthCodePkceOptions: For PKCE flow (ClientId, CodeVerifier, RedirectUri, TokenUrl, Scope)
  • ResilientHttpClientOptions: For base address, client name, and retry settings

How It Works

  • Token providers implement IAccessTokenProvider and handle token acquisition and caching
  • TokenHandler automatically attaches the access token to outgoing requests
  • Resilience is provided via retry policies with jitter

License

MIT

Contact

Version History

Version Date Changes
1.1.0 2026-01-22 Bump from .NET 9 to .NET 10
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos 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
1.1.7 88 1/23/2026
1.1.4 36 1/21/2026