//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOAuth.Messaging.Bindings { using System; using System.Collections.Generic; using System.Linq; using System.Text; using DotNetOAuth.Messaging.Bindings; /// /// An in-memory nonce store. Useful for single-server web applications. /// NOT for web farms. /// internal class NonceMemoryStore : INonceStore { /// /// The maximum age a message can be before it is discarded. /// /// /// This is useful for knowing how long used nonces must be retained. /// private readonly TimeSpan maximumMessageAge; /// /// Initializes a new instance of the class. /// /// The maximum age a message can be before it is discarded. internal NonceMemoryStore(TimeSpan maximumMessageAge) { this.maximumMessageAge = maximumMessageAge; } #region INonceStore Members /// /// Stores a given nonce and timestamp. /// /// /// A series of random characters. /// /// /// The timestamp that together with the nonce string make it unique. /// The timestamp may also be used by the data store to clear out old nonces. /// /// /// True if the nonce+timestamp (combination) was not previously in the database. /// False if the nonce was stored previously with the same timestamp. /// /// /// The nonce must be stored for no less than the maximum time window a message may /// be processed within before being discarded as an expired message. /// If the binding element is applicable to your channel, this expiration window /// is retrieved or set using the /// property. /// public bool StoreNonce(string nonce, DateTime timestamp) { if (timestamp.ToUniversalTime() + this.maximumMessageAge < DateTime.UtcNow) { // The expiration binding element should have taken care of this, but perhaps // it's at the boundary case. We should fail just to be safe. return false; } // TODO: implement actual nonce checking. Logger.Warn("Nonce checking not implemented yet."); return true; } #endregion } }