IdentityServer4.Contrib.HttpClientService 2.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package IdentityServer4.Contrib.HttpClientService --version 2.1.0
NuGet\Install-Package IdentityServer4.Contrib.HttpClientService -Version 2.1.0
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="IdentityServer4.Contrib.HttpClientService" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IdentityServer4.Contrib.HttpClientService --version 2.1.0
#r "nuget: IdentityServer4.Contrib.HttpClientService, 2.1.0"
#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.
// Install IdentityServer4.Contrib.HttpClientService as a Cake Addin
#addin nuget:?package=IdentityServer4.Contrib.HttpClientService&version=2.1.0

// Install IdentityServer4.Contrib.HttpClientService as a Cake Tool
#tool nuget:?package=IdentityServer4.Contrib.HttpClientService&version=2.1.0

An HttpClient service for IdentityServer4

Build Status Nuget

An HttpClient service that makes it easy to make authenticated HTTP requests to protected by IdentityServer4 resources. Complex types are automatically serialized for requests / deserialized form responses, all with a fluent interface design:

var responseObject = await _requestServiceFactory
                          //Create a instance of the service
                          .CreateHttpClientService()
                          //Also supports IOptions<>
                          .SetIdentityServerOptions("appsettings_section")
                          //GET and deserialize the response body to IEnumerable<Customers>
                          .GetAsync<IEnumerable<Customers>>("https://api/customers");

The variable responseObject contains multiple properties: from the entire HttpResponseMessage and HttpRequestMessage, to HttpStatusCode and HttpResponseHeaders. The most exciting feature though, is the TResponseBody BodyAsType property which will contain deserializabled complex types from JSON responses (in the example above the BodyAsType will be of type IEnumerable<Customers>). Check the ResponseObject<TResponseBody> in the docs.

Setting up complex request body for POST, PUT and PATCH requests is also very easy! Here are some examples:

var responseObject = await _requestServiceFactory
                          //Create a instance of the service
                          .CreateHttpClientService()
                          //.PostAsync<TRequestBody,TResponseBody>(URL, customer of type Customer1)
                          .PostAsync<Customer1,Customer2>("https://api/customers", customer);

You can also fine tune encoding and media-type by using the TypeContent(TRequestBody model, Encoding encoding, string mediaType) like this:

var responseObject = await _requestServiceFactory
                          //Create a instance of the service
                          .CreateHttpClientService()
                          //.PostAsync<TRequestBody,TResponseBody>(URL, customer of type Customer1)
                          .PostAsync<TypeContent<Customer1>,Customer2>("https://api/customers", new TypeContent(customer, Encoding.UTF8, "application/json"));

HTTP verbs supported are: GET, POST, PUT, DELETE, PATCH and HEAD. Read the Documentation for technical details, check the features sample or a more complete one.

Getting Started

Getting started with IdentityServer4.Contrib.HttpClientService is easy; you only need three things:

  1. Install the nuget package IdentityServer4.Contrib.HttpClientService
  2. Provide the options to authenticate in appsettings.json
  3. Register the service in Startup.cs

Read the entire Getting Started guide for a quick start. You can also take a look at the Documentation, check the features sample or a more complete one.

Contributing

Feedback and contibution is more than welcome, as there are many more things to do!

Just as a sample:

  1. Expand the IdentityServer4.Contrib.HttpClientService.CompleteSample with more functionality.
  2. Support JsonSerializerSettings for JsonConvert.DeserializeObject<TResponseBody>(apiResponse.BodyAsString) in HttpClientService.
  3. Support more than ClientCredentials.
  4. Add logging.

Many more are coming soon and all of them should be issues, so feel free to open one and let's start discussing solutions!

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. 
.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
2.3.6 2,348 7/6/2021
2.3.5 118,251 10/13/2020
2.3.4 767 8/3/2020
2.3.3 405 7/28/2020
2.3.1 414 7/28/2020
2.3.0 7,420 3/19/2020
2.2.2 444 3/16/2020
2.2.1 546 3/11/2020
2.2.0 439 3/11/2020
2.1.0 443 3/6/2020
2.0.0 439 3/5/2020
1.1.0 679 3/3/2020
1.0.1 611 3/2/2020
1.0.0 591 3/2/2020
0.0.1-alpha 588 3/2/2020