public static AuthenticationHeaderValue CreateBasicAuthHeader([NotNull] IBasicAuthCredentials credentials) { if (credentials == null) { throw new ArgumentNullException(nameof(credentials)); } return(new AuthenticationHeaderValue("Basic", credentials.ToBase64String())); }
public static string ToBase64String([NotNull] this IBasicAuthCredentials credentials) { if (credentials == null) { throw new ArgumentNullException(nameof(credentials)); } var formattedString = $"{credentials.UserName}:{credentials.Password}"; var encodedBytes = Encoding.UTF8.GetBytes(formattedString); return(Convert.ToBase64String(encodedBytes)); }