internal static void AddAuthInfo(this WebRequest client, string userName, string password, AuthenticationInfo authInfo) { if ("basic".Equals(authInfo.method)) { client.AddBasicAuth(userName, password); // FIXME AddBasicAuth ignores the server provided Realm property. Potential Bug. } else if ("digest".Equals(authInfo.method)) { // do digest auth header using auth info // auth info saved in ServiceClientBase for subsequent requests client.AddDigestAuth(userName, password, authInfo); } }
private void HandleAuthException(Exception ex, WebRequest client) { if (ex is WebException webEx && webEx.Response != null) { var headers = ((HttpWebResponse)webEx.Response).Headers; var doAuthHeader = PclExportClient.Instance.GetHeader(headers, HttpHeaders.WwwAuthenticate, x => x.Contains("realm")); if (doAuthHeader == null) { client.AddBasicAuth(this.UserName, this.Password); } else { this.authInfo = new AuthenticationInfo(doAuthHeader); client.AddAuthInfo(this.UserName, this.Password, authInfo); } } }