Intility.Extensions.HttpClientAuthorization 1.0.3

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Intility.Extensions.HttpClientAuthorization --version 1.0.3
                    
NuGet\Install-Package Intility.Extensions.HttpClientAuthorization -Version 1.0.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="Intility.Extensions.HttpClientAuthorization" Version="1.0.3" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Intility.Extensions.HttpClientAuthorization" Version="1.0.3" />
                    
Directory.Packages.props
<PackageReference Include="Intility.Extensions.HttpClientAuthorization" />
                    
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 Intility.Extensions.HttpClientAuthorization --version 1.0.3
                    
#r "nuget: Intility.Extensions.HttpClientAuthorization, 1.0.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 Intility.Extensions.HttpClientAuthorization@1.0.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=Intility.Extensions.HttpClientAuthorization&version=1.0.3
                    
Install as a Cake Addin
#tool nuget:?package=Intility.Extensions.HttpClientAuthorization&version=1.0.3
                    
Install as a Cake Tool

Intility.Extensions.HttpClientAuthorization

A .NET library providing HTTP client extensions for delegated authentication scenarios with automatic token acquisition, rotation, and header renewal.

Motivation

Microsoft's secure app model relies on delegated access, complicating service-to-service authentication. Administrators must manage interactive sign-ins and token (access and refresh) rotation. This library automates:

  • Access token acquisition via device-code flow
  • Transparent token and header renewal
  • Secure caching and key protection

Installation

Install via NuGet:

dotnet add package Intility.Extensions.HttpClientAuthorization

Configuration

Define your HTTP clients in appsettings.json:

{
  "Clients": {
    "PartnerCenter": {
      "TenantId": "<YOUR_TENANT_ID>",
      "ClientId": "<CLIENT_WITH_DELEGATED_PERMISSIONS>",
      "Scopes": ["https://api.partnercenter.microsoft.com/user_impersonation"]
    }
  }
}

Register and configure your clients in Program.cs or Startup.cs:

services
    .AddHttpClient<IPartnerService, PartnerService>()
    .AddClientAuthentication(auth =>
        auth.UseDeviceCodeDelegation(options =>
            Configuration.GetSection("Clients:PartnerCenter").Bind(options)));

This registers a typed client (PartnerService) and injects an HttpClient preconfigured with the device-code authentication handler.

Note: Authentication prompts appear via ASP.NET Core logging (e.g., console output).

Dependencies

Token persistence and protection rely on ASP.NET Core components:

Usage

Authentication is handled transparently in the HTTP pipeline. Use injected HttpClient instances as usual.

Example: PartnerService

public interface IPartnerService
{
    Task<string> GetCustomers();
}

public class PartnerService(HttpClient _httpClient) : IPartnerService
{
    public async Task<string> GetCustomers()
    {
        var response = await _httpClient.GetAsync("https://api.partnercenter.microsoft.com/v1/customers");
        response.EnsureSuccessStatusCode();

        return await response.Content.ReadAsStringAsync();
    }
}

Samples

See the samples/ directory for complete implementations.

Contributing

We welcome contributions from engineers within our organization to enhance and expand the capabilities of the Intility.Extensions.HttpClientAuthorization library. Please follow the guidelines below to ensure a smooth contribution process:

Branch Protection

The main branch is protected. All contributions must go through a pull request (PR) process. Edits made directly to the main branch will get blocked.

Workflow for Contributions

  1. Create a Feature Branch: Clone the repository and create a new branch from main to house your feature or fix. Use descriptive names for your branches, preferably related to the issue or enhancement you are working on.

  2. Commit Changes Using Conventional Commits: When committing changes, adhere to conventional commit standards to make changelog generation straightforward. This helps in automating the release process.

  3. Open a Pull Request: Once your changes are ready, open a PR back to the main branch. Ensure your PR includes relevant descriptions, references to any issues, and testing documentation where applicable.

  4. Automated Build and Test: Upon submitting a PR, GitHub Actions will automatically trigger the Build and Test workflow (.github/workflows/pr.yaml). It's imperative to ensure that all checks pass successfully before considering a merge.

  5. Review and Merge: After the PR is approved and merges into main, it initiates a subsequent release pipeline. This pipeline creates a release PR with a generated changelog, based on your conventional commits, and a prerelease (timestamped) package on nuget.org.

  6. Updating Release PR: If multiple feature branches are merged into main, the release PR will automatically update with additional changelog entries, reflecting the cumulative changes and updated prerelease packages.

  7. Verification: At this stage, you have the opportunity to verify the functionality and reliability of the prerelease package. Thorough testing and validation should be carried out to ensure the package performs as expected in a production-like environment.

  8. Release: Once satisfied with the prerelease, merge the generated release PR. This will result in a semantic version tag and trigger the Release Package workflow (.github/workflows/release.yaml) which publishes a proper NuGet release.

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 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 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 netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  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
2025.5.7-preview-1 147 5/7/2025
1.0.3 558 5/7/2025
1.0.2 145 5/7/2025
1.0.1-preview-9 140 5/6/2025
1.0.0-preview-9 137 5/6/2025
1.0.0-preview-8 136 5/6/2025
1.0.0-preview-7 135 5/6/2025
1.0.0-preview-6 143 5/6/2025
1.0.0-preview-5 141 5/5/2025
1.0.0-preview-4 135 5/5/2025
1.0.0-preview-3 140 5/5/2025