//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OpenId.Provider { using System; using System.Diagnostics.CodeAnalysis; using System.Threading; using System.Threading.Tasks; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId.Messages; using Validation; /// /// Provides access to a host Provider to read an incoming extension-only checkid request message, /// and supply extension responses or a cancellation message to the RP. /// [Serializable] internal class AnonymousRequest : HostProcessedRequest, IAnonymousRequest { /// /// The extension-response message to send, if the host site chooses to send it. /// private readonly IndirectSignedResponse positiveResponse; /// /// Initializes a new instance of the class. /// /// The provider that received the request. /// The incoming authentication request message. [SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Diagnostics.Contracts.__ContractsRuntime.Requires(System.Boolean,System.String,System.String)", Justification = "Code contracts"), SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "AuthenticationRequest", Justification = "Type name"), SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Code contracts require it.")] internal AnonymousRequest(OpenIdProvider provider, SignedResponseRequest request) : base(provider, request) { Requires.NotNull(provider, "provider"); Requires.That(!(request is CheckIdRequest), "request", "request cannot be CheckIdRequest"); this.positiveResponse = new IndirectSignedResponse(request); } #region HostProcessedRequest members /// /// Gets or sets the provider endpoint. /// /// /// The default value is the URL that the request came in on from the relying party. /// public override Uri ProviderEndpoint { get { return this.positiveResponse.ProviderEndpoint; } set { this.positiveResponse.ProviderEndpoint = value; } } #endregion #region IAnonymousRequest Members /// /// Gets or sets a value indicating whether the user approved sending any data to the relying party. /// /// true if approved; otherwise, false. public bool? IsApproved { get; set; } #endregion #region Request members /// /// Gets a value indicating whether the response is ready to be sent to the user agent. /// /// /// This property returns false if there are properties that must be set on this /// request instance before the response can be sent. /// public override bool IsResponseReady { get { return this.IsApproved.HasValue; } } /// /// Gets the response message, once is true. /// /// The cancellation token. /// The response message. protected override async Task GetResponseMessageAsync(CancellationToken cancellationToken) { if (this.IsApproved.HasValue) { return this.IsApproved.Value ? (IProtocolMessage)this.positiveResponse : await this.GetNegativeResponseAsync(); } else { return null; } } #endregion } }