Beispiel #1
0
 private bool Equals(RequestId other)
 {
     return timestamp == other.Timestamp &&
            String.Equals(nonce, other.Nonce) &&
            String.Equals(consumerKey, other.ConsumerKey) &&
            String.Equals(token, other.Token);
 }
        private 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) {
                IList<RequestId> requests;
                if (requestCache.TryGetValue(currentId.Timestamp, out requests)) {
                    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 (!requestCache.TryGetValue(currentId.Timestamp, out requests)) {
                        requests = new List<RequestId>();
                        requestCache.Add(currentId.Timestamp, requests);
                    }

                    requests.Add(currentId);
                }
            }

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

            return currentId;
        }