//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Messages {
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
using DotNetOpenAuth.Messaging;
///
/// A common base class from which indirect response messages should derive.
///
[Serializable]
internal class IndirectResponseBase : RequestBase, IProtocolMessageWithExtensions {
///
/// Backing store for the property.
///
private IList extensions = new List();
///
/// Initializes a new instance of the class.
///
/// The request that caused this response message to be constructed.
/// The value of the openid.mode parameter.
protected IndirectResponseBase(SignedResponseRequest request, string mode)
: base(GetVersion(request), GetReturnTo(request), mode, MessageTransport.Indirect) {
Requires.NotNull(request, "request");
this.OriginatingRequest = request;
}
///
/// Initializes a new instance of the class
/// for unsolicited assertion scenarios.
///
/// The OpenID version supported at the Relying Party.
///
/// The URI at which the Relying Party receives OpenID indirect messages.
///
/// The value to use for the openid.mode parameter.
protected IndirectResponseBase(Version version, Uri relyingPartyReturnTo, string mode)
: base(version, relyingPartyReturnTo, mode, MessageTransport.Indirect) {
}
#region IProtocolMessageWithExtensions Members
///
/// Gets the list of extensions that are included with this message.
///
///
///
/// Implementations of this interface should ensure that this property never returns null.
///
public IList Extensions {
get { return this.extensions; }
}
#endregion
///
/// Gets the signed extensions on this message.
///
internal IEnumerable SignedExtensions {
get { return this.extensions.OfType().Where(ext => ext.IsSignedByRemoteParty); }
}
///
/// Gets the unsigned extensions on this message.
///
internal IEnumerable UnsignedExtensions {
get { return this.extensions.OfType().Where(ext => !ext.IsSignedByRemoteParty); }
}
///
/// Gets the originating request message, if applicable.
///
protected SignedResponseRequest OriginatingRequest { get; private set; }
///
/// Gets the property of a message.
///
/// The message to fetch the protocol version from.
/// The value of the property.
///
/// This method can be used by a constructor to throw an
/// instead of a .
///
internal static Version GetVersion(IProtocolMessage message) {
Requires.NotNull(message, "message");
return message.Version;
}
///
/// Gets the property of a message.
///
/// The message to fetch the ReturnTo from.
/// The value of the property.
///
/// This method can be used by a constructor to throw an
/// instead of a .
///
private static Uri GetReturnTo(SignedResponseRequest message) {
Requires.NotNull(message, "message");
ErrorUtilities.VerifyProtocol(message.ReturnTo != null, OpenIdStrings.ReturnToRequiredForResponse);
return message.ReturnTo;
}
}
}