Skip to content

Instantly share code, notes, and snippets.

Last active October 30, 2015 09:11
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Add Basic authentication header to DD4T Rest Provider
public class HttpClientAuthentication : DD4T.Providers.Rest.IHttpMessageHandlerFactory
public HttpMessageHandler CreatePipeline(HttpMessageHandler innerHandler)
return HttpClientFactory.CreatePipeline(innerHandler, new[] {
new BasicAuthenticationHandler()
public class BasicAuthenticationHandler : DelegatingHandler
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(
HttpRequestMessage request,
System.Threading.CancellationToken cancellationToken)
var credentials = string.Format("{0}:{1}", "myusername", "mypassword");
var byteArray = System.Text.Encoding.ASCII.GetBytes(credentials);
request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
return base.SendAsync(request, cancellationToken);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment