コード例 #1
0
        // IAuthenticationModule

        public Authorization Authenticate(string challenge, WebRequest webRequest, ICredentials credentials)
        {
            if (credentials == null || challenge == null)
            {
                return(null);
            }

            string header = challenge.Trim();

            if (header.ToLower().IndexOf("digest") == -1)
            {
                return(null);
            }

            HttpWebRequest request = webRequest as HttpWebRequest;

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

            DigestSession currDS = new DigestSession();

            if (!currDS.Parse(challenge))
            {
                return(null);
            }

            int           hashcode = request.Address.GetHashCode() ^ credentials.GetHashCode() ^ currDS.Nonce.GetHashCode();
            DigestSession ds       = (DigestSession)Cache[hashcode];
            bool          addDS    = (ds == null);

            if (addDS)
            {
                ds = currDS;
            }
            else if (!ds.Parse(challenge))
            {
                return(null);
            }

            if (addDS)
            {
                Cache.Add(hashcode, ds);
            }

            return(ds.Authenticate(webRequest, credentials));
        }
コード例 #2
0
        public Authorization PreAuthenticate(WebRequest webRequest, ICredentials credentials)
        {
            HttpWebRequest request = webRequest as HttpWebRequest;

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

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

            int           hashcode = request.Address.GetHashCode() ^ credentials.GetHashCode();
            DigestSession ds       = (DigestSession)Cache[hashcode];

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

            return(ds.Authenticate(webRequest, credentials));
        }