Intility.Extensions.HttpClientAuthorization
1.0.3
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
<PackageReference Include="Intility.Extensions.HttpClientAuthorization" Version="1.0.3" />
<PackageVersion Include="Intility.Extensions.HttpClientAuthorization" Version="1.0.3" />
<PackageReference Include="Intility.Extensions.HttpClientAuthorization" />
paket add Intility.Extensions.HttpClientAuthorization --version 1.0.3
#r "nuget: Intility.Extensions.HttpClientAuthorization, 1.0.3"
#:package Intility.Extensions.HttpClientAuthorization@1.0.3
#addin nuget:?package=Intility.Extensions.HttpClientAuthorization&version=1.0.3
#tool nuget:?package=Intility.Extensions.HttpClientAuthorization&version=1.0.3
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:
- IDistributedCache: Default in-memory cache; recommend configuring a distributed provider as described in ASP.NET Core Distributed Cache documentation or otherwise lose tokens on service restarts.
- Data Protection: Encrypts cached tokens at rest. Configure data protection per ASP.NET Core Data Protection documentation.
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
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.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.
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.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.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.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.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.
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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Http.Polly (>= 9.0.4)
- Microsoft.Identity.Client (>= 4.71.1)
-
net8.0
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Http.Polly (>= 9.0.4)
- Microsoft.Identity.Client (>= 4.71.1)
-
net9.0
- Microsoft.AspNetCore.DataProtection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Caching.Abstractions (>= 9.0.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.4)
- Microsoft.Extensions.Http.Polly (>= 9.0.4)
- Microsoft.Identity.Client (>= 4.71.1)
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 |