using System; using System.Net.Http; namespace AMWD.Net.Api.Cloudflare.Auth { /// /// Implements the interface to authenticate using an API key and email address. /// public class ApiKeyAuthentication : IAuthentication { private readonly string _emailAddress; private readonly string _apiKey; /// /// Initializes a new instance of the class. /// /// The email address. /// The global API key. public ApiKeyAuthentication(string emailAddress, string apiKey) { emailAddress.ValidateCloudflareEmailAddress(); if (string.IsNullOrWhiteSpace(apiKey)) throw new ArgumentNullException(nameof(apiKey)); _emailAddress = emailAddress; _apiKey = apiKey; } /// public void AddHeader(HttpClient httpClient) { httpClient.DefaultRequestHeaders.Add("X-Auth-Email", _emailAddress); httpClient.DefaultRequestHeaders.Add("X-Auth-Key", _apiKey); } } }