1
//-----------------------------------------------------------------------
2 // <copyright file="ExtensionBase.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth
.OpenId
.Extensions
{
9 using System
.Collections
.Generic
;
12 using DotNetOpenAuth
.Messaging
;
13 using DotNetOpenAuth
.OpenId
.Messages
;
16 /// A handy base class for built-in extensions.
18 public class ExtensionBase
: IOpenIdMessageExtension
{
20 /// Backing store for the <see cref="IOpenIdMessageExtension.TypeUri"/> property.
22 private string typeUri
;
25 /// Backing store for the <see cref="IOpenIdMessageExtension.AdditionalSupportedTypeUris"/> property.
27 private IEnumerable
<string> additionalSupportedTypeUris
;
30 /// Backing store for the <see cref="IMessage.ExtraData"/> property.
32 private Dictionary
<string, string> extraData
= new Dictionary
<string, string>();
35 /// Initializes a new instance of the <see cref="ExtensionBase"/> class.
37 /// <param name="version">The version of the extension.</param>
38 /// <param name="typeUri">The type URI to use in the OpenID message.</param>
39 /// <param name="additionalSupportedTypeUris">The additional supported type URIs by which this extension might be recognized.</param>
40 protected ExtensionBase(Version version
, string typeUri
, IEnumerable
<string> additionalSupportedTypeUris
) {
41 this.Version
= version
;
42 this.typeUri
= typeUri
;
43 this.additionalSupportedTypeUris
= additionalSupportedTypeUris
;
46 #region IOpenIdProtocolMessageExtension Members
49 /// Gets the TypeURI the extension uses in the OpenID protocol and in XRDS advertisements.
51 string IOpenIdMessageExtension
.TypeUri
{
52 get { return this.typeUri; }
56 /// Gets the additional TypeURIs that are supported by this extension, in preferred order.
57 /// May be empty if none other than <see cref="IOpenIdMessageExtension.TypeUri"/> is supported, but
58 /// should not be null.
62 /// Useful for reading in messages with an older version of an extension.
63 /// The value in the <see cref="IOpenIdMessageExtension.TypeUri"/> property is always checked before
65 /// If you do support multiple versions of an extension using this method,
66 /// consider adding a CreateResponse method to your request extension class
67 /// so that the response can have the context it needs to remain compatible
68 /// given the version of the extension in the request message.
69 /// The <see cref="SimpleRegistration.ClaimsRequest.CreateResponse"/> for an example.
71 IEnumerable
<string> IOpenIdMessageExtension
.AdditionalSupportedTypeUris
{
72 get { return this.additionalSupportedTypeUris; }
77 #region IMessage Members
80 /// Gets the version of the protocol or extension this message is prepared to implement.
82 public Version Version { get; private set; }
85 /// Gets the extra, non-standard Protocol parameters included in the message.
88 /// Implementations of this interface should ensure that this property never returns null.
90 IDictionary
<string, string> IMessage
.ExtraData
{
91 get { return this.extraData; }
95 /// Checks the message state for conformity to the protocol specification
96 /// and throws an exception if the message is invalid.
99 /// <para>Some messages have required fields, or combinations of fields that must relate to each other
100 /// in specialized ways. After deserializing a message, this method checks the state of the
101 /// message to see if it conforms to the protocol.</para>
102 /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
103 /// outside this scope of this particular message.</para>
105 /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
106 void IMessage
.EnsureValidMessage() {
107 this.EnsureValidMessage();
113 /// Checks the message state for conformity to the protocol specification
114 /// and throws an exception if the message is invalid.
117 /// <para>Some messages have required fields, or combinations of fields that must relate to each other
118 /// in specialized ways. After deserializing a message, this method checks the state of the
119 /// message to see if it conforms to the protocol.</para>
120 /// <para>Note that this property should <i>not</i> check signatures or perform any state checks
121 /// outside this scope of this particular message.</para>
123 /// <exception cref="ProtocolException">Thrown if the message is invalid.</exception>
124 protected virtual void EnsureValidMessage() {