An HttpClient service for IdentityServer4
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:
- Install the nuget package IdentityServer4.Contrib.HttpClientService
- Provide the options to request an access token in the
appsettings.json
- 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:
- Expand the IdentityServer4.Contrib.HttpClientService.CompleteSample with more functionality.
- Support
JsonSerializerSettings
forJsonConvert.DeserializeObject<TResponseBody>(apiResponse.BodyAsString)
in HttpClientService. - Support more than
ClientCredentialsOptions
andPasswordOptions
. - Set options for changing the x-header name
- 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!