コード例 #1
0
        public static AuthenticationHeaderValue CreateBasicAuthHeader([NotNull] IBasicAuthCredentials credentials)
        {
            if (credentials == null)
            {
                throw new ArgumentNullException(nameof(credentials));
            }

            return(new AuthenticationHeaderValue("Basic", credentials.ToBase64String()));
        }
コード例 #2
0
        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));
        }