//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.Messages { using System; using System.Collections.Generic; using System.Diagnostics; using System.Diagnostics.Contracts; using System.Linq; using System.Text; using DotNetOpenAuth.Messaging; /// /// The base class that all successful association response messages derive from. /// /// /// Association response messages are described in OpenID 2.0 section 8.2. This type covers section 8.2.1. /// [DebuggerDisplay("OpenID {Version} associate response {AssociationHandle} {AssociationType} {SessionType}")] [ContractClass(typeof(AssociateSuccessfulResponseContract))] internal abstract class AssociateSuccessfulResponse : DirectResponseBase { /// /// Initializes a new instance of the class. /// /// The OpenID version of the response message. /// The originating request. internal AssociateSuccessfulResponse(Version responseVersion, AssociateRequest originatingRequest) : base(responseVersion, originatingRequest) { } /// /// Gets or sets the association handle is used as a key to refer to this association in subsequent messages. /// /// A string 255 characters or less in length. It MUST consist only of ASCII characters in the range 33-126 inclusive (printable non-whitespace characters). [MessagePart("assoc_handle", IsRequired = true, AllowEmpty = false)] internal string AssociationHandle { get; set; } /// /// 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("assoc_type", IsRequired = true, AllowEmpty = false)] internal string AssociationType { get; set; } /// /// Gets or sets the value of the "openid.session_type" parameter from the request. /// If the OP is unwilling or unable to support this association type, it MUST return an /// unsuccessful response (Unsuccessful Response Parameters). /// /// 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("session_type", IsRequired = false, AllowEmpty = true)] [MessagePart("session_type", IsRequired = true, AllowEmpty = false, MinVersion = "2.0")] internal string SessionType { get; set; } /// /// Gets or sets the lifetime, in seconds, of this association. The Relying Party MUST NOT use the association after this time has passed. /// /// An integer, represented in base 10 ASCII. [MessagePart("expires_in", IsRequired = true)] internal long ExpiresIn { 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(); if (this.Version.Major < 2) { ErrorUtilities.VerifyProtocol( string.IsNullOrEmpty(this.SessionType) || string.Equals(this.SessionType, this.Protocol.Args.SessionType.DH_SHA1, StringComparison.Ordinal), MessagingStrings.UnexpectedMessagePartValueForConstant, GetType().Name, Protocol.openid.session_type, this.Protocol.Args.SessionType.DH_SHA1, this.SessionType); } } } }