KISS.HttpClientAuthentication
2.0.2
See the version list below for details.
dotnet add package KISS.HttpClientAuthentication --version 2.0.2
NuGet\Install-Package KISS.HttpClientAuthentication -Version 2.0.2
<PackageReference Include="KISS.HttpClientAuthentication" Version="2.0.2" />
<PackageVersion Include="KISS.HttpClientAuthentication" Version="2.0.2" />
<PackageReference Include="KISS.HttpClientAuthentication" />
paket add KISS.HttpClientAuthentication --version 2.0.2
#r "nuget: KISS.HttpClientAuthentication, 2.0.2"
#:package KISS.HttpClientAuthentication@2.0.2
#addin nuget:?package=KISS.HttpClientAuthentication&version=2.0.2
#tool nuget:?package=KISS.HttpClientAuthentication&version=2.0.2
KISS.HttpClientAuthentication NuGet package
ABOUT
This NuGet package enables configuring authentication for HttpClients using the ASP.NET Core Configuration system.
The package currently supports the following authentication methods:
- Api key
- Basic
- OAuth2
- Client credentials
Please note: The .NET Standard 2.0 and .NET 6 targeted packages references the LTS version 6 of the dependent NuGet packages. The reason for this is that while it is possible to run .NET 7 NuGet packages on .NET 6, it is known that some of them may introduce unexpected behavior. It is recommended (especially from the ASP.NET Core team) limit usage of .NET 7 based NuGet packages on .NET 6 runtime.
USAGE
Add the NuGet package KISS.HttpClientAuthentication to your project and whenever a
AddHttpClient injection is done that needs authentication chain a call to
AddAuthenticatedHttpMessageHandler for the AddHttpClient request and set the configuration accordingly.
There are two different AddAuthenticatedHttpMessageHandler extension methods. One without any parameter
and one with a string configSection parameter. The first one will use the IHttpClientBuilder.Name
as the name of the configuration to read from the ASP.NET Core Configuration system, while the latter gives
you the opportunity to specify a specific configuration setting.
Configuration
Various authentication methods are supported by the following configuration settings.
None
No authentication.
"<Section name>": {
"AuthenticationProvider": "None"
}
Api Key
Authentication using API key, both Header and Value must be set.
"<section name>": {
"AuthenticationProvider": "ApiKey",
"ApiKey": {
"Header": "<API KEY HEADER>",
"Value": "<API KEY VALUE>"
}
}
Basic
Authentication using username/password authentication, both Username and Password must be set.
"<section name>": {
"AuthenticationProvider": "Basic",
"Basic": {
"Username": "<username>",
"Password": "<password>"
}
}
OAuth 2
Authentication using OAuth2.
Client credentials
Using OAuth2 client credentials, all settings except DisableTokenCache and Scope is required.
"<section name>": {
"AuthenticationProvider": "OAuth2",
"OAuth2": {
"AuthorizationEndpoint": "<OAuth2 token endpoint>",
"DisableTokenCache": false,
"GrantType": "ClientCredentials",
"Scope": "<Optional scopes separated by space>",
"ClientCredentials": {
"ClientId": "<Unique client id>",
"ClientSecret": "<Secret connected to the client id>"
}
}
}
Examples
Example 1 - Uses the name of the type that is used in AddHttpClient
MyClass.cs
public class MyClass
{
}
// When configuring Dependency Injection
services.AddHttpClient<MyClass>().AddAuthenticatedHttpMessageHandler();
appsettings.json
{
"MyClass": {
// This configuration is used since the class name is MyClass
}
}
Example 2 - Uses the configSection specified when calling AddAuthenticatedHttpMessageHandler
MyClass.cs
public class MyClass
{
}
// When configuring Dependency Injection
services.AddHttpClient<MyClass>().AddAuthenticatedHttpMessageHandler("MyConfiguration");
appsettings.json
{
"MyConfiguration": {
// This configuration is used since the HttpClient Name is MyConfiguration
}
}
Example 3 - Uses the name specified when calling AddHttpClient
// When configuring Dependency Injection
services.AddHttpClient("MyClient").AddAuthenticatedHttpMessageHandler();
appsettings.json
{
"MyClient": {
// This configuration is used since the configSection is set to MyConfiguration
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. 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 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 | 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.Extensions.Caching.Memory (>= 6.0.2 && < 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0 && < 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0 && < 7.0.0)
- Microsoft.Extensions.Http (>= 6.0.0 && < 7.0.0)
- System.Text.Json (>= 8.0.5)
-
net6.0
- Microsoft.Extensions.Caching.Memory (>= 6.0.2 && < 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 6.0.0 && < 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0 && < 7.0.0)
- Microsoft.Extensions.Http (>= 6.0.0 && < 7.0.0)
- System.Text.Json (>= 8.0.5)
-
net8.0
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.1)
- System.Text.Json (>= 8.0.5)
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 |
|---|---|---|
| 3.1.0 | 247 | 11/25/2025 |
| 3.0.0 | 809 | 1/14/2025 |
| 3.0.0-preview.250114.1 | 77 | 1/14/2025 |
| 2.0.2 | 405 | 10/15/2024 |
| 2.0.1 | 235 | 10/9/2024 |
| 2.0.0 | 379 | 6/4/2024 |
| 2.0.0-preview.240604.1 | 99 | 6/4/2024 |
| 1.0.0 | 225 | 9/1/2023 |