Пример #1
0
        Authorization InternalAuthenticate(HttpURLConnection request, ICredentials credentials)
        {
            if (request == null || credentials == null)
            {
                return(null);
            }

            NetworkCredential cred = credentials.GetCredential(new Uri(request.URL.ToString()), AuthenticationType.ToLowerInvariant());

            if (cred == null)
            {
                return(null);
            }

            if (String.IsNullOrEmpty(cred.UserName))
            {
                return(null);
            }

            string domain   = cred.Domain?.Trim();
            string response = String.Empty;

            // If domain is set, MS sends "domain\user:password".
            if (!String.IsNullOrEmpty(domain))
            {
                response = domain + "\\";
            }
            response += cred.UserName + ":" + cred.Password;

            return(new Authorization($"{AuthenticationType} {Convert.ToBase64String (Encoding.ASCII.GetBytes (response))}"));
        }