public void ParseChallange(string header) { this.Type = AuthenticationTypes.Unknown; this.Stale = false; this.Opaque = null; this.HA1Sess = null; this.NonceCount = 0; this.QualityOfProtections = null; if (this.ProtectedUris != null) { this.ProtectedUris.Clear(); } WWWAuthenticateHeaderParser wWWAuthenticateHeaderParser = new WWWAuthenticateHeaderParser(header); foreach (KeyValuePair current in wWWAuthenticateHeaderParser.Values) { string key = current.Key; switch (key) { case "basic": this.Type = AuthenticationTypes.Basic; break; case "digest": this.Type = AuthenticationTypes.Digest; break; case "realm": this.Realm = current.Value; break; case "domain": if (!string.IsNullOrEmpty(current.Value) && current.Value.Length != 0) { if (this.ProtectedUris == null) { this.ProtectedUris = new List <string>(); } int num2 = 0; string item = current.Value.Read(ref num2, ' ', true); do { this.ProtectedUris.Add(item); item = current.Value.Read(ref num2, ' ', true); }while (num2 < current.Value.Length); } break; case "nonce": this.Nonce = current.Value; break; case "qop": this.QualityOfProtections = current.Value; break; case "stale": this.Stale = bool.Parse(current.Value); break; case "opaque": this.Opaque = current.Value; break; case "algorithm": this.Algorithm = current.Value; break; } } }
/// <summary> /// Parses a WWW-Authenticate header's value to retrive all information. /// </summary> public void ParseChallange(string header) { // Reset some values to its defaults. this.Type = AuthenticationTypes.Unknown; this.Stale = false; this.Opaque = null; this.HA1Sess = null; this.NonceCount = 0; this.QualityOfProtections = null; if (this.ProtectedUris != null) { this.ProtectedUris.Clear(); } // Parse the header WWWAuthenticateHeaderParser qpl = new WWWAuthenticateHeaderParser(header); // Then process foreach (var qp in qpl.Values) { switch (qp.Key) { case "basic": this.Type = AuthenticationTypes.Basic; break; case "digest": this.Type = AuthenticationTypes.Digest; break; case "realm": this.Realm = qp.Value; break; case "domain": { if (string.IsNullOrEmpty(qp.Value) || qp.Value.Length == 0) { break; } if (this.ProtectedUris == null) { this.ProtectedUris = new List <string>(); } int idx = 0; string val = qp.Value.Read(ref idx, ' '); do { this.ProtectedUris.Add(val); val = qp.Value.Read(ref idx, ' '); } while (idx < qp.Value.Length); break; } case "nonce": this.Nonce = qp.Value; break; case "qop": this.QualityOfProtections = qp.Value; break; case "stale": this.Stale = bool.Parse(qp.Value); break; case "opaque": this.Opaque = qp.Value; break; case "algorithm": this.Algorithm = qp.Value; break; } } }
public void ParseChallange(string header) { Type = AuthenticationTypes.Unknown; Stale = false; Opaque = null; HA1Sess = null; NonceCount = 0; QualityOfProtections = null; if (ProtectedUris != null) { ProtectedUris.Clear(); } WWWAuthenticateHeaderParser wWWAuthenticateHeaderParser = new WWWAuthenticateHeaderParser(header); foreach (KeyValuePair value in wWWAuthenticateHeaderParser.Values) { switch (value.Key) { case "basic": Type = AuthenticationTypes.Basic; break; case "digest": Type = AuthenticationTypes.Digest; break; case "realm": Realm = value.Value; break; case "domain": if (!string.IsNullOrEmpty(value.Value) && value.Value.Length != 0) { if (ProtectedUris == null) { ProtectedUris = new List <string>(); } int pos = 0; string item = value.Value.Read(ref pos, ' '); do { ProtectedUris.Add(item); item = value.Value.Read(ref pos, ' '); }while (pos < value.Value.Length); } break; case "nonce": Nonce = value.Value; break; case "qop": QualityOfProtections = value.Value; break; case "stale": Stale = bool.Parse(value.Value); break; case "opaque": Opaque = value.Value; break; case "algorithm": Algorithm = value.Value; break; } } }