summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj6
-rw-r--r--src/DotNetOpenAuth/Messaging/DataBag.cs146
-rw-r--r--src/DotNetOpenAuth/Messaging/IDataBagFormatter.cs (renamed from src/DotNetOpenAuth/OAuth2/ChannelElements/IDataBagFormatter.cs)3
-rw-r--r--src/DotNetOpenAuth/Messaging/TimestampEncoder.cs (renamed from src/DotNetOpenAuth/OAuth2/ChannelElements/TimestampEncoder.cs)2
-rw-r--r--src/DotNetOpenAuth/OAuth2/ChannelElements/DataBag.cs63
5 files changed, 151 insertions, 69 deletions
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 574bd53..cbd3b43 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -356,7 +356,7 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="OAuth2\ChannelElements\AuthServerBindingElementBase.cs" />
<Compile Include="OAuth2\ChannelElements\GrantTypeEncoder.cs" />
<Compile Include="OAuth2\ChannelElements\EndUserAuthorizationResponseTypeEncoder.cs" />
- <Compile Include="OAuth2\ChannelElements\IDataBagFormatter.cs" />
+ <Compile Include="Messaging\IDataBagFormatter.cs" />
<Compile Include="OAuth2\ChannelElements\OAuth2ChannelBase.cs" />
<Compile Include="OAuth2\ChannelElements\OAuth2ClientChannel.cs" />
<Compile Include="OAuth2\ChannelElements\ScopeEncoder.cs" />
@@ -366,8 +366,8 @@ http://opensource.org/licenses/ms-pl.html
<Compile Include="OAuth2\ChannelElements\OAuth2ResourceServerChannel.cs" />
<Compile Include="Messaging\StandardMessageFactoryChannel.cs" />
<Compile Include="OAuth2\ChannelElements\RefreshToken.cs" />
- <Compile Include="OAuth2\ChannelElements\DataBag.cs" />
- <Compile Include="OAuth2\ChannelElements\TimestampEncoder.cs" />
+ <Compile Include="Messaging\DataBag.cs" />
+ <Compile Include="Messaging\TimestampEncoder.cs" />
<Compile Include="OAuth2\ChannelElements\AuthorizationCode.cs" />
<Compile Include="OAuth2\ChannelElements\AuthorizationCodeBindingElement.cs" />
<Compile Include="OAuth2\ChannelElements\AuthServerAllFlowsBindingElement.cs" />
diff --git a/src/DotNetOpenAuth/Messaging/DataBag.cs b/src/DotNetOpenAuth/Messaging/DataBag.cs
new file mode 100644
index 0000000..91ccc13
--- /dev/null
+++ b/src/DotNetOpenAuth/Messaging/DataBag.cs
@@ -0,0 +1,146 @@
+//-----------------------------------------------------------------------
+// <copyright file="DataBag.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.Messaging {
+ using System;
+ using System.Collections.Generic;
+ using System.Diagnostics.Contracts;
+
+ /// <summary>
+ /// A collection of message parts that will be serialized into a single string,
+ /// to be set into a larger message.
+ /// </summary>
+ internal abstract class DataBag : IMessage {
+ /// <summary>
+ /// The default version for DataBags.
+ /// </summary>
+ private static readonly Version DefaultVersion = new Version(1, 0);
+
+ /// <summary>
+ /// The backing field for the <see cref="IMessage.Version"/> property.
+ /// </summary>
+ private Version version;
+
+ /// <summary>
+ /// A dictionary to contain extra message data.
+ /// </summary>
+ private Dictionary<string, string> extraData = new Dictionary<string, string>();
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="DataBag"/> class.
+ /// </summary>
+ protected DataBag()
+ : this(DefaultVersion) {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="DataBag"/> class.
+ /// </summary>
+ /// <param name="version">The DataBag version.</param>
+ protected DataBag(Version version) {
+ Contract.Requires(version != null);
+ this.version = version;
+ }
+
+ #region IMessage Properties
+
+ /// <summary>
+ /// Gets the version of the protocol or extension this message is prepared to implement.
+ /// </summary>
+ /// <remarks>
+ /// Implementations of this interface should ensure that this property never returns null.
+ /// </remarks>
+ Version IMessage.Version {
+ get { return this.version; }
+ }
+
+ /// <summary>
+ /// Gets the extra, non-standard Protocol parameters included in the message.
+ /// </summary>
+ /// <value></value>
+ /// <remarks>
+ /// Implementations of this interface should ensure that this property never returns null.
+ /// </remarks>
+ public IDictionary<string, string> ExtraData {
+ get { return this.extraData; }
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Gets or sets the nonce.
+ /// </summary>
+ /// <value>The nonce.</value>
+ [MessagePart]
+ internal byte[] Nonce { get; set; }
+
+ /// <summary>
+ /// Gets or sets the UTC creation date of this token.
+ /// </summary>
+ /// <value>The UTC creation date.</value>
+ [MessagePart("timestamp", IsRequired = true, Encoder = typeof(TimestampEncoder))]
+ internal DateTime UtcCreationDate { get; set; }
+
+ /// <summary>
+ /// Gets or sets the signature.
+ /// </summary>
+ /// <value>The signature.</value>
+ [MessagePart("sig")]
+ internal byte[] Signature { get; set; }
+
+ /// <summary>
+ /// Gets or sets the message that delivered this DataBag instance to this host.
+ /// </summary>
+ protected internal IProtocolMessage ContainingMessage { get; set; }
+
+ /// <summary>
+ /// Gets the type of this instance.
+ /// </summary>
+ /// <value>The type of the bag.</value>
+ /// <remarks>
+ /// This ensures that one token cannot be misused as another kind of token.
+ /// </remarks>
+ [MessagePart("t", IsRequired = true, AllowEmpty = false)]
+ private string BagType {
+ get { return this.GetType().Name; }
+ }
+
+ #region IMessage Methods
+
+ /// <summary>
+ /// Checks the message state for conformity to the protocol specification
+ /// and throws an exception if the message is invalid.
+ /// </summary>
+ /// <remarks>
+ /// <para>Some messages have required fields, or combinations of fields that must relate to each other
+ /// in specialized ways. After deserializing a message, this method checks the state of the
+ /// message to see if it conforms to the protocol.</para>
+ /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
+ /// outside this scope of this particular message.</para>
+ /// </remarks>
+ /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
+ void IMessage.EnsureValidMessage() {
+ this.EnsureValidMessage();
+ }
+
+ #endregion
+
+ /// <summary>
+ /// Checks the message state for conformity to the protocol specification
+ /// and throws an exception if the message is invalid.
+ /// </summary>
+ /// <remarks>
+ /// <para>Some messages have required fields, or combinations of fields that must relate to each other
+ /// in specialized ways. After deserializing a message, this method checks the state of the
+ /// message to see if it conforms to the protocol.</para>
+ /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
+ /// outside this scope of this particular message.</para>
+ /// </remarks>
+ /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
+ protected virtual void EnsureValidMessage() {
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/IDataBagFormatter.cs b/src/DotNetOpenAuth/Messaging/IDataBagFormatter.cs
index 0289821..529c331 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/IDataBagFormatter.cs
+++ b/src/DotNetOpenAuth/Messaging/IDataBagFormatter.cs
@@ -4,10 +4,9 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
+namespace DotNetOpenAuth.Messaging {
using System;
using System.Diagnostics.Contracts;
- using DotNetOpenAuth.Messaging;
/// <summary>
/// A serializer for <see cref="DataBag"/>-derived types
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/TimestampEncoder.cs b/src/DotNetOpenAuth/Messaging/TimestampEncoder.cs
index 7c6aafb..93df88b 100644
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/TimestampEncoder.cs
+++ b/src/DotNetOpenAuth/Messaging/TimestampEncoder.cs
@@ -4,7 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
+namespace DotNetOpenAuth.Messaging {
using System;
using System.Globalization;
using DotNetOpenAuth.Messaging.Reflection;
diff --git a/src/DotNetOpenAuth/OAuth2/ChannelElements/DataBag.cs b/src/DotNetOpenAuth/OAuth2/ChannelElements/DataBag.cs
deleted file mode 100644
index 4a96659..0000000
--- a/src/DotNetOpenAuth/OAuth2/ChannelElements/DataBag.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="DataBag.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OAuth2.ChannelElements {
- using System;
-
- using DotNetOpenAuth.Messaging;
- using DotNetOpenAuth.OAuth2.Messages;
-
- /// <summary>
- /// A collection of message parts that will be serialized into a single string,
- /// to be set into a larger message.
- /// </summary>
- internal abstract class DataBag : MessageBase {
- /// <summary>
- /// Initializes a new instance of the <see cref="DataBag"/> class.
- /// </summary>
- protected DataBag()
- : base(Protocol.Default.Version) {
- }
-
- /// <summary>
- /// Gets or sets the nonce.
- /// </summary>
- /// <value>The nonce.</value>
- [MessagePart]
- internal byte[] Nonce { get; set; }
-
- /// <summary>
- /// Gets or sets the UTC creation date of this token.
- /// </summary>
- /// <value>The UTC creation date.</value>
- [MessagePart("timestamp", IsRequired = true, Encoder = typeof(TimestampEncoder))]
- internal DateTime UtcCreationDate { get; set; }
-
- /// <summary>
- /// Gets or sets the signature.
- /// </summary>
- /// <value>The signature.</value>
- [MessagePart("sig")]
- internal byte[] Signature { get; set; }
-
- /// <summary>
- /// Gets or sets the message that delivered this DataBag instance to this host.
- /// </summary>
- protected internal IProtocolMessage ContainingMessage { get; set; }
-
- /// <summary>
- /// Gets the type of this instance.
- /// </summary>
- /// <value>The type of the bag.</value>
- /// <remarks>
- /// This ensures that one token cannot be misused as another kind of token.
- /// </remarks>
- [MessagePart("t", IsRequired = true, AllowEmpty = false)]
- private string BagType {
- get { return this.GetType().Name; }
- }
- }
-}