//----------------------------------------------------------------------- // // Copyright (c) Andrew Arnott. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOAuth.Messages { using System; using System.Collections.Generic; using DotNetOAuth.ChannelElements; using DotNetOAuth.Messaging; using DotNetOAuth.Messaging.Bindings; /// /// A base class for all signed OAuth messages. /// public class SignedMessageBase : MessageBase, ITamperResistantOAuthMessage, IExpiringProtocolMessage, IReplayProtectedProtocolMessage { /// /// The reference date and time for calculating time stamps. /// private static readonly DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); /// /// The number of seconds since 1/1/1970, consistent with the OAuth timestamp requirement. /// [MessagePart("oauth_timestamp", IsRequired = true)] private long timestamp; /// /// Initializes a new instance of the class. /// /// A value indicating whether this message requires a direct or indirect transport. internal SignedMessageBase(MessageTransport transport) : base(MessageProtection.All, transport) { } /// /// Initializes a new instance of the class. /// /// A value indicating whether this message requires a direct or indirect transport. /// The URI that a directed message will be delivered to. internal SignedMessageBase(MessageTransport transport, MessageReceivingEndpoint recipient) : base(MessageProtection.All, transport, recipient) { } #region ITamperResistantOAuthMessage Members /// /// Gets or sets the signature method used to sign the request. /// [MessagePart("oauth_signature_method", IsRequired = true)] string ITamperResistantOAuthMessage.SignatureMethod { get; set; } /// /// Gets or sets the Token Secret used to sign the message. /// Only applicable to Consumer. /// public string TokenSecret { get; set; } /// /// Gets or sets the Consumer key. /// [MessagePart(Name = "oauth_consumer_key", IsRequired = true)] public string ConsumerKey { get; set; } /// /// Gets or sets the Consumer Secret used to sign the message. /// Only applicable to Consumer. /// public string ConsumerSecret { get; set; } /// /// Gets or sets the HTTP method that will be used to transmit the message. /// Only applicable to Consumer. /// string ITamperResistantOAuthMessage.HttpMethod { get; set; } #endregion #region ITamperResistantProtocolMessage Members /// /// Gets or sets the message signature. /// [MessagePart("oauth_signature", IsRequired = true)] string ITamperResistantProtocolMessage.Signature { get; set; } #endregion #region IExpiringProtocolMessage Members /// /// Gets or sets the OAuth timestamp of the message. /// DateTime IExpiringProtocolMessage.UtcCreationDate { get { return epoch + TimeSpan.FromSeconds(this.timestamp); } set { this.timestamp = (long)(value - epoch).TotalSeconds; } } #endregion #region IReplayProtectedProtocolMessage Members /// /// Gets or sets the message nonce used for replay detection. /// [MessagePart("oauth_nonce", IsRequired = true)] string IReplayProtectedProtocolMessage.Nonce { get; set; } #endregion /// /// Gets or sets the version of the protocol this message was created with. /// [MessagePart(Name = "oauth_version", IsRequired = false)] private string Version { get { return ((IProtocolMessage)this).ProtocolVersion.ToString(); } set { if (value != this.Version) { throw new ArgumentOutOfRangeException("value"); } } } } }