using System;
using System.Diagnostics;
using System.Globalization;
using System.Text;
namespace Octokit.Internal
{
class BasicAuthenticator : IAuthenticationHandler
{
///
///Authenticate a request using the basic access authentication scheme
///
///The request to authenticate
///The credentials to attach to the request
///
///See the Basic Authentication documentation for more information.
///
public void Authenticate(IRequest request, Credentials credentials)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(credentials, nameof(credentials));
Ensure.ArgumentNotNull(credentials.Login, nameof(credentials.Login));
Debug.Assert(credentials.Password != null, "It should be impossible for the password to be null");
var header = string.Format(
CultureInfo.InvariantCulture,
"Basic {0}",
Convert.ToBase64String(Encoding.UTF8.GetBytes(
string.Format(CultureInfo.InvariantCulture, "{0}:{1}", credentials.Login, credentials.Password))));
request.Headers["Authorization"] = header;
}
}
}