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 for responses, all with a fluent interface design:

var responseObject = await _requestServiceFactory
	//Create a instance of the service
	.CreateHttpClientService()
	//Supports many ways of setting IdentityServer options
	.SetIdentityServerOptions("ClientCredentialsOptions")
	//GET and deserialize the response body to IEnumerable<Customers>
	.GetAsync<IEnumerable<Customers>>("https://api/customers");

Check the Getting started guide for more details!

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 request an access token in the 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.

More Details

Read the 'More Details' section for a more detailed explanation on some of the features of this library, like the SetIdentityServerOptions overloads, the ResponseObject and the TypeContent(TRequestBody, Encoding, string) class

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 ClientCredentialsOptions and PasswordOptions.
  4. Set options for changing the x-header name
  5. 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!

  • Improve this Doc
Back to top Generated by DocFX