namespace OAuthServiceProvider.Code {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetOpenAuth.Messaging.Bindings;
///
/// A database-persisted nonce store.
///
public class DatabaseNonceStore : INonceStore {
///
/// Initializes a new instance of the class.
///
public DatabaseNonceStore() {
}
#region INonceStore Members
///
/// Stores a given nonce and timestamp.
///
/// The context, or namespace, within which the
/// must be unique.
/// The context SHOULD be treated as case-sensitive.
/// The value will never be null but may be the empty string.
/// A series of random characters.
/// The UTC timestamp that together with the nonce string make it unique
/// within the given .
/// The timestamp may also be used by the data store to clear out old nonces.
///
/// True if the context+nonce+timestamp (combination) was not previously in the database.
/// False if the nonce was stored previously with the same timestamp and context.
///
///
/// 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.
/// This maximum message age can be looked up via the
///
/// property, accessible via the
/// property.
///
public bool StoreNonce(string context, string nonce, DateTime timestampUtc) {
Global.DataContext.Nonces.InsertOnSubmit(new Nonce { Context = context, Code = nonce, Timestamp = timestampUtc });
try {
Global.DataContext.SubmitChanges();
return true;
} catch (System.Data.Linq.DuplicateKeyException) {
return false;
}
}
#endregion
}
}