Exemplo n.º 1
0
        public Authorization Authenticate(string challenge, HttpURLConnection request, ICredentials credentials)
        {
            if (credentials == null || challenge == null)
            {
                return(null);
            }

            string header = challenge.Trim();

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

            var currDS = new AuthDigestSession();

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

            var uri              = new Uri(request.URL.ToString());
            int hashcode         = uri.GetHashCode() ^ credentials.GetHashCode() ^ currDS.Nonce.GetHashCode();
            AuthDigestSession ds = null;
            bool addDS           = false;

            if (!Cache.TryGetValue(hashcode, out ds) || ds == null)
            {
                addDS = true;
            }

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

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

            return(ds.Authenticate(request, credentials));
        }
Exemplo n.º 2
0
        public Authorization PreAuthenticate(HttpURLConnection request, ICredentials credentials)
        {
            if (request == null || credentials == null)
            {
                return(null);
            }

            var uri              = new Uri(request.URL.ToString());
            int hashcode         = uri.GetHashCode() ^ credentials.GetHashCode();
            AuthDigestSession ds = null;

            if (!Cache.TryGetValue(hashcode, out ds) || ds == null)
            {
                return(null);
            }

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