//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; /// /// An OpenID direct request from Relying Party to Provider to initiate an association. /// [DebuggerDisplay("OpenID {Version} {Mode} {AssociationType} {SessionType}")] internal abstract class AssociateRequest : RequestBase { /// /// Initializes a new instance of the class. /// /// The OpenID version this message must comply with. /// The OpenID Provider endpoint. protected AssociateRequest(Version version, Uri providerEndpoint) : base(version, providerEndpoint, GetProtocolConstant(version, p => p.Args.Mode.associate), MessageTransport.Direct) { } /// /// Gets or sets the preferred association type. The association type defines the algorithm to be used to sign subsequent messages. /// /// Value: A valid association type from Section 8.3. [MessagePart("openid.assoc_type", IsRequired = true, AllowEmpty = false)] internal string AssociationType { get; set; } /// /// Gets or sets the preferred association session type. This defines the method used to encrypt the association's MAC key in transit. /// /// Value: A valid association session type from Section 8.4 (Association Session Types). /// Note: Unless using transport layer encryption, "no-encryption" MUST NOT be used. [MessagePart("openid.session_type", IsRequired = false, AllowEmpty = true)] [MessagePart("openid.session_type", IsRequired = true, AllowEmpty = false, MinVersion = "2.0")] internal string SessionType { get; set; } /// /// 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. public override void EnsureValidMessage() { base.EnsureValidMessage(); ErrorUtilities.VerifyProtocol( !string.Equals(this.SessionType, Protocol.Args.SessionType.NoEncryption, StringComparison.Ordinal) || this.Recipient.IsTransportSecure(), OpenIdStrings.NoEncryptionSessionRequiresHttps, this); } } }