1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
//-----------------------------------------------------------------------
// <copyright file="AnonymousRequest.cs" company="Andrew Arnott">
// Copyright (c) Andrew Arnott. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Provider {
using System;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.Contracts;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.Messages;
/// <summary>
/// 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.
/// </summary>
[Serializable]
internal class AnonymousRequest : HostProcessedRequest, IAnonymousRequest {
/// <summary>
/// The extension-response message to send, if the host site chooses to send it.
/// </summary>
private readonly IndirectSignedResponse positiveResponse;
/// <summary>
/// Initializes a new instance of the <see cref="AnonymousRequest"/> class.
/// </summary>
/// <param name="provider">The provider that received the request.</param>
/// <param name="request">The incoming authentication request message.</param>
[SuppressMessage("Microsoft.Performance", "CA1800:DoNotCastUnnecessarily", Justification = "Code contracts require it.")]
internal AnonymousRequest(OpenIdProvider provider, SignedResponseRequest request)
: base(provider, request) {
Contract.Requires(provider != null);
Contract.Requires(!(request is CheckIdRequest), "Instantiate " + typeof(AuthenticationRequest).Name + " to handle this kind of message.");
ErrorUtilities.VerifyInternal(!(request is CheckIdRequest), "Instantiate {0} to handle this kind of message.", typeof(AuthenticationRequest).Name);
this.positiveResponse = new IndirectSignedResponse(request);
}
#region HostProcessedRequest members
/// <summary>
/// Gets or sets the provider endpoint.
/// </summary>
/// <value>
/// The default value is the URL that the request came in on from the relying party.
/// </value>
public override Uri ProviderEndpoint {
get { return this.positiveResponse.ProviderEndpoint; }
set { this.positiveResponse.ProviderEndpoint = value; }
}
#endregion
#region IAnonymousRequest Members
/// <summary>
/// Gets or sets a value indicating whether the user approved sending any data to the relying party.
/// </summary>
/// <value><c>true</c> if approved; otherwise, <c>false</c>.</value>
public bool? IsApproved { get; set; }
#endregion
#region Request members
/// <summary>
/// Gets a value indicating whether the response is ready to be sent to the user agent.
/// </summary>
/// <remarks>
/// This property returns false if there are properties that must be set on this
/// request instance before the response can be sent.
/// </remarks>
public override bool IsResponseReady {
get { return this.IsApproved.HasValue; }
}
/// <summary>
/// Gets the response message, once <see cref="IsResponseReady"/> is <c>true</c>.
/// </summary>
protected override IProtocolMessage ResponseMessage {
get {
if (this.IsApproved.HasValue) {
return this.IsApproved.Value ? (IProtocolMessage)this.positiveResponse : this.NegativeResponse;
} else {
return null;
}
}
}
#endregion
}
}
|