//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.Extensions { using System; using System.Collections.Generic; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; /// /// A handy base class for built-in extensions. /// [Serializable] public class ExtensionBase : IOpenIdMessageExtension { /// /// Backing store for the property. /// private string typeUri; /// /// Backing store for the property. /// private IEnumerable additionalSupportedTypeUris; /// /// Backing store for the property. /// private Dictionary extraData = new Dictionary(); /// /// Initializes a new instance of the class. /// /// The version of the extension. /// The type URI to use in the OpenID message. /// The additional supported type URIs by which this extension might be recognized. May be null. protected ExtensionBase(Version version, string typeUri, IEnumerable additionalSupportedTypeUris) { this.Version = version; this.typeUri = typeUri; this.additionalSupportedTypeUris = additionalSupportedTypeUris ?? EmptyList.Instance; } #region IOpenIdProtocolMessageExtension Members /// /// Gets the TypeURI the extension uses in the OpenID protocol and in XRDS advertisements. /// string IOpenIdMessageExtension.TypeUri { get { return this.TypeUri; } } /// /// Gets the additional TypeURIs that are supported by this extension, in preferred order. /// May be empty if none other than is supported, but /// should not be null. /// /// /// Useful for reading in messages with an older version of an extension. /// The value in the property is always checked before /// trying this list. /// If you do support multiple versions of an extension using this method, /// consider adding a CreateResponse method to your request extension class /// so that the response can have the context it needs to remain compatible /// given the version of the extension in the request message. /// The for an example. /// IEnumerable IOpenIdMessageExtension.AdditionalSupportedTypeUris { get { return this.AdditionalSupportedTypeUris; } } /// /// Gets or sets a value indicating whether this extension was /// signed by the OpenID Provider. /// /// /// true if this instance is signed by the provider; otherwise, false. /// bool IOpenIdMessageExtension.IsSignedByRemoteParty { get { return this.IsSignedByRemoteParty; } set { this.IsSignedByRemoteParty = value; } } #endregion #region IMessage Properties /// /// Gets the version of the protocol or extension this message is prepared to implement. /// public Version Version { get; private set; } /// /// Gets the extra, non-standard Protocol parameters included in the message. /// /// /// Implementations of this interface should ensure that this property never returns null. /// IDictionary IMessage.ExtraData { get { return this.ExtraData; } } #endregion /// /// Gets the TypeURI the extension uses in the OpenID protocol and in XRDS advertisements. /// protected string TypeUri { get { return this.typeUri; } } /// /// Gets or sets a value indicating whether this extension was /// signed by the OpenID Provider. /// /// /// true if this instance is signed by the provider; otherwise, false. /// protected bool IsSignedByRemoteParty { get; set; } /// /// Gets the additional TypeURIs that are supported by this extension, in preferred order. /// May be empty if none other than is supported, but /// should not be null. /// /// /// /// Useful for reading in messages with an older version of an extension. /// The value in the property is always checked before /// trying this list. /// If you do support multiple versions of an extension using this method, /// consider adding a CreateResponse method to your request extension class /// so that the response can have the context it needs to remain compatible /// given the version of the extension in the request message. /// The for an example. /// protected IEnumerable AdditionalSupportedTypeUris { get { return this.additionalSupportedTypeUris; } } /// /// Gets the extra, non-standard Protocol parameters included in the message. /// /// /// /// Implementations of this interface should ensure that this property never returns null. /// protected IDictionary ExtraData { get { return this.extraData; } } #region IMessage Methods /// /// Checks the message state for conformity to the protocol specification /// and throws an exception if the message is invalid. /// /// /// 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. /// Note that this property should not check signatures or perform any state checks /// outside this scope of this particular message. /// /// Thrown if the message is invalid. void IMessage.EnsureValidMessage() { this.EnsureValidMessage(); } #endregion /// /// Checks the message state for conformity to the protocol specification /// and throws an exception if the message is invalid. /// /// /// 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. /// Note that this property should not check signatures or perform any state checks /// outside this scope of this particular message. /// /// Thrown if the message is invalid. protected virtual void EnsureValidMessage() { } } }