示例#1
0
 private bool Equals(RequestId other)
 {
     return this.Timestamp == other.Timestamp
         && string.Equals(this.Nonce, other.Nonce)
         && string.Equals(this.ConsumerKey, other.ConsumerKey)
         && string.Equals(this.Token, other.Token);
 }      
        // Checks whether the supplied nonce, timestamp and consumer key combination is unique within
        // the current window.
        protected virtual RequestId ValidateNonce(string nonce, long timestamp, string consumerKey, string token)
        {
            RequestId currentId = new RequestId(timestamp, nonce, consumerKey, token);

            bool foundClash = false;

            // Lock the request cache while we look for the current id
            lock (SyncRoot)
            {
                if (this.RequestCache.ContainsKey(currentId.Timestamp))
                {
                    // Get all requests with the same timestamp
                    IList<RequestId> requests = this.RequestCache[currentId.Timestamp];
                                        
                    foreach (RequestId request in requests)
                        if (request == currentId)
                        {
                            foundClash = true;
                            break;
                        }
                }

                // If we didn't find a clash, store the current id in the cache
                if (!foundClash)
                {
                    if (!this.RequestCache.ContainsKey(currentId.Timestamp))
                        this.RequestCache[currentId.Timestamp] = new List<RequestId>();

                    this.RequestCache[currentId.Timestamp].Add(currentId);
                }
            }

            // If we did find a clash, throw a nonce used OAuthRequestException
            if (foundClash)
                OAuthRequestException.ThrowNonceUsed(null);

            return currentId;
        }