void GetAuthorization() { if (ConnectionInformation.AuthenticationMethod == AuthenticationMethod.None) return; string authorizationLine = GetHeaderValue("Authorization"); if (string.IsNullOrEmpty(authorizationLine)) return; string[] split = authorizationLine.Split(' '); if (split.Length < 2) return; AuthenticationEventArgs e; switch (split[0]) { case "Basic": byte[] buffer = Convert.FromBase64String(split[1]); string[] userpass = Encoding.ASCII.GetString(buffer).Split(':'); e = new AuthenticationEventArgs(userpass[0], string.Empty, AuthenticationMethod.Basic); OnAuthenticateHandler(e); if (e.Accept && e.Password == userpass[1]) { ci.LogonUser = e.Login; ci.AuthPassword = e.Password; } break; case "Digest": if (split.Length < 3) { split = split[1].Split(',').Select(s => s.Trim()).ToArray(); } var digest = new DigestAuthenticationProcessor(split); digest.Method = httpMethod; e = new AuthenticationEventArgs(digest.Username, string.Empty, AuthenticationMethod.Digest); OnAuthenticateHandler(e); if (e.Accept && digest.CheckValid(e.Password)) { ci.LogonUser = e.Login; ci.AuthPassword = e.Password; } break; } }
string ComposeDigestAuthenticationRequest() { var digest = new DigestAuthenticationProcessor(ci.RemoteIpAddress.ToString(), GetHeaderValue("Host")); return digest.ComposeRequest(); }