internal static void AddDigestAuth(this WebRequest client,string userName,string password,AuthenticationInfo authInfo) { // by adamfowleruk // See Client Request at http://en.wikipedia.org/wiki/Digest_access_authentication string ncUse = padNC(authInfo.nc); authInfo.nc++; // incrememnt for subsequent requests string ha1raw = userName + ":" + authInfo.realm + ":" + password; string ha1 = CalculateMD5Hash(ha1raw); string ha2raw = client.Method + ":" + client.RequestUri.PathAndQuery; string ha2 = CalculateMD5Hash(ha2raw); string md5rraw = ha1 + ":" + authInfo.nonce + ":" + ncUse + ":" + authInfo.cnonce + ":" + authInfo.qop + ":" + ha2; string response = CalculateMD5Hash(md5rraw); string header = "Digest username=\"" + userName + "\", realm=\"" + authInfo.realm + "\", nonce=\"" + authInfo.nonce + "\", uri=\"" + client.RequestUri.PathAndQuery + "\", cnonce=\"" + authInfo.cnonce + "\", nc=" + ncUse + ", qop=\"" + authInfo.qop + "\", response=\"" + response + "\", opaque=\"" + authInfo.opaque + "\""; client.Headers [ServiceStack.Common.Web.HttpHeaders.Authorization] = header; }
internal static void AddDigestAuth(this WebRequest client, string userName, string password, AuthenticationInfo authInfo) { // by adamfowleruk // See Client Request at http://en.wikipedia.org/wiki/Digest_access_authentication string ncUse = padNC(authInfo.nc); authInfo.nc++; // incrememnt for subsequent requests string ha1raw = userName + ":" + authInfo.realm + ":" + password; string ha1 = CalculateMD5Hash(ha1raw); string ha2raw = client.Method + ":" + client.RequestUri.PathAndQuery; string ha2 = CalculateMD5Hash(ha2raw); string md5rraw = ha1 + ":" + authInfo.nonce + ":" + ncUse + ":" + authInfo.cnonce + ":" + authInfo.qop + ":" + ha2; string response = CalculateMD5Hash(md5rraw); string header = "Digest username=\"" + userName + "\", realm=\"" + authInfo.realm + "\", nonce=\"" + authInfo.nonce + "\", uri=\"" + client.RequestUri.PathAndQuery + "\", cnonce=\"" + authInfo.cnonce + "\", nc=" + ncUse + ", qop=\"" + authInfo.qop + "\", response=\"" + response + "\", opaque=\"" + authInfo.opaque + "\""; client.Headers [ServiceStack.Common.Web.HttpHeaders.Authorization] = header; }
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); } }
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); } }