summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2011-08-09 07:53:51 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2011-08-09 07:53:51 -0700
commitef6957d6bf7698252895214eac7cb01d91775d6c (patch)
tree2ff9b7e0b6576cfb714dd51ae9ffc565a6b867b4 /src/DotNetOpenAuth.OpenId.RelyingParty/OpenId
parente0f42d23e06b693f2fa898d4605fea09d18354c6 (diff)
downloadDotNetOpenAuth-ef6957d6bf7698252895214eac7cb01d91775d6c.zip
DotNetOpenAuth-ef6957d6bf7698252895214eac7cb01d91775d6c.tar.gz
DotNetOpenAuth-ef6957d6bf7698252895214eac7cb01d91775d6c.tar.bz2
Fixed up OpenIdInfoCardSelector button and the association response in the message factory.
Diffstat (limited to 'src/DotNetOpenAuth.OpenId.RelyingParty/OpenId')
-rw-r--r--src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyChannel.cs4
-rw-r--r--src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyMessageFactory.cs67
-rw-r--r--src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/RelyingParty/SelectorInfoCardButton.cs102
3 files changed, 69 insertions, 104 deletions
diff --git a/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyChannel.cs b/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyChannel.cs
index fc08b00..03266ec 100644
--- a/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyChannel.cs
+++ b/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyChannel.cs
@@ -26,7 +26,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements {
/// <param name="nonceStore">The nonce store to use.</param>
/// <param name="securitySettings">The security settings to apply.</param>
internal OpenIdRelyingPartyChannel(ICryptoKeyStore cryptoKeyStore, INonceStore nonceStore, RelyingPartySecuritySettings securitySettings)
- : this(cryptoKeyStore, nonceStore, new OpenIdMessageFactory(), securitySettings, false) {
+ : this(cryptoKeyStore, nonceStore, new OpenIdRelyingPartyMessageFactory(), securitySettings, false) {
Contract.Requires<ArgumentNullException>(securitySettings != null);
}
@@ -60,7 +60,7 @@ namespace DotNetOpenAuth.OpenId.ChannelElements {
internal static OpenIdChannel CreateNonVerifyingChannel() {
Contract.Ensures(Contract.Result<OpenIdChannel>() != null);
- return new OpenIdRelyingPartyChannel(null, null, new OpenIdMessageFactory(), new RelyingPartySecuritySettings(), true);
+ return new OpenIdRelyingPartyChannel(null, null, new OpenIdRelyingPartyMessageFactory(), new RelyingPartySecuritySettings(), true);
}
/// <summary>
diff --git a/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyMessageFactory.cs b/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyMessageFactory.cs
new file mode 100644
index 0000000..aaa375f
--- /dev/null
+++ b/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/ChannelElements/OpenIdRelyingPartyMessageFactory.cs
@@ -0,0 +1,67 @@
+namespace DotNetOpenAuth.OpenId.ChannelElements {
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using DotNetOpenAuth.Messaging;
+ using DotNetOpenAuth.OpenId.Messages;
+
+ internal class OpenIdRelyingPartyMessageFactory : OpenIdMessageFactory {
+ /// <summary>
+ /// Analyzes an incoming request message payload to discover what kind of
+ /// message is embedded in it and returns the type, or null if no match is found.
+ /// </summary>
+ /// <param name="request">The message that was sent as a request that resulted in the response.</param>
+ /// <param name="fields">The name/value pairs that make up the message payload.</param>
+ /// <returns>
+ /// A newly instantiated <see cref="IProtocolMessage"/>-derived object that this message can
+ /// deserialize to. Null if the request isn't recognized as a valid protocol message.
+ /// </returns>
+ public override IDirectResponseProtocolMessage GetNewResponseMessage(IDirectedProtocolMessage request, IDictionary<string, string> fields) {
+ DirectResponseBase message = null;
+
+ // Discern the OpenID version of the message.
+ Protocol protocol = Protocol.V11;
+ string ns;
+ if (fields.TryGetValue(Protocol.V20.openidnp.ns, out ns)) {
+ ErrorUtilities.VerifyProtocol(string.Equals(ns, Protocol.OpenId2Namespace, StringComparison.Ordinal), MessagingStrings.UnexpectedMessagePartValue, Protocol.V20.openidnp.ns, ns);
+ protocol = Protocol.V20;
+ }
+
+ // Handle error messages generally.
+ if (fields.ContainsKey(protocol.openidnp.error)) {
+ message = new DirectErrorResponse(protocol.Version, request);
+ }
+
+ var associateRequest = request as AssociateRequest;
+ if (associateRequest != null) {
+ if (protocol.Version.Major >= 2 && fields.ContainsKey(protocol.openidnp.error_code)) {
+ // This is a special recognized error case that we create a special message for.
+ message = new AssociateUnsuccessfulResponse(protocol.Version, associateRequest);
+ } else if (message == null) {
+ var associateDiffieHellmanRequest = request as AssociateDiffieHellmanRequest;
+ var associateUnencryptedRequest = request as AssociateUnencryptedRequest;
+
+ if (associateDiffieHellmanRequest != null) {
+ message = new AssociateDiffieHellmanRelyingPartyResponse(protocol.Version, associateDiffieHellmanRequest);
+ }
+
+ if (associateUnencryptedRequest != null) {
+ message = new AssociateUnencryptedResponse(protocol.Version, associateUnencryptedRequest);
+ }
+ }
+ }
+
+ var checkAuthenticationRequest = request as CheckAuthenticationRequest;
+ if (checkAuthenticationRequest != null && message == null) {
+ message = new CheckAuthenticationResponse(protocol.Version, checkAuthenticationRequest);
+ }
+
+ if (message != null) {
+ message.SetAsIncoming();
+ }
+
+ return message;
+ }
+ }
+}
diff --git a/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/RelyingParty/SelectorInfoCardButton.cs b/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/RelyingParty/SelectorInfoCardButton.cs
deleted file mode 100644
index c5dda1c..0000000
--- a/src/DotNetOpenAuth.OpenId.RelyingParty/OpenId/RelyingParty/SelectorInfoCardButton.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-//-----------------------------------------------------------------------
-// <copyright file="SelectorInfoCardButton.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOpenAuth.OpenId.RelyingParty {
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Diagnostics.Contracts;
- using System.Web.UI;
- using DotNetOpenAuth.InfoCard;
-
- /// <summary>
- /// A button that appears in the <see cref="OpenIdSelector"/> control that
- /// activates the Information Card selector on the browser, if one is available.
- /// </summary>
- public class SelectorInfoCardButton : SelectorButton, IDisposable {
- /// <summary>
- /// The backing field for the <see cref="InfoCardSelector"/> property.
- /// </summary>
- private InfoCardSelector infoCardSelector;
-
- /// <summary>
- /// Initializes a new instance of the <see cref="SelectorInfoCardButton"/> class.
- /// </summary>
- public SelectorInfoCardButton() {
- Reporting.RecordFeatureUse(this);
- }
-
- /// <summary>
- /// Gets or sets the InfoCard selector which may be displayed alongside the OP buttons.
- /// </summary>
- [PersistenceMode(PersistenceMode.InnerProperty)]
- public InfoCardSelector InfoCardSelector {
- get {
- if (this.infoCardSelector == null) {
- this.infoCardSelector = new InfoCardSelector();
- }
-
- return this.infoCardSelector;
- }
-
- set {
- Contract.Requires<ArgumentNullException>(value != null);
- if (this.infoCardSelector != null) {
- Logger.Library.WarnFormat("{0}.InfoCardSelector property is being set multiple times.", GetType().Name);
- }
-
- this.infoCardSelector = value;
- }
- }
-
- #region IDisposable Members
-
- /// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
- /// </summary>
- public void Dispose() {
- this.Dispose(true);
- GC.SuppressFinalize(this);
- }
-
- #endregion
-
- /// <summary>
- /// Ensures that this button has been initialized to a valid state.
- /// </summary>
- internal override void EnsureValid() {
- }
-
- /// <summary>
- /// Renders the leading attributes for the LI tag.
- /// </summary>
- /// <param name="writer">The writer.</param>
- protected internal override void RenderLeadingAttributes(HtmlTextWriter writer) {
- writer.AddAttribute(HtmlTextWriterAttribute.Class, "infocard");
- }
-
- /// <summary>
- /// Renders the content of the button.
- /// </summary>
- /// <param name="writer">The writer.</param>
- /// <param name="selector">The containing selector control.</param>
- protected internal override void RenderButtonContent(HtmlTextWriter writer, OpenIdSelector selector) {
- this.InfoCardSelector.RenderControl(writer);
- }
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void Dispose(bool disposing) {
- if (disposing) {
- if (this.infoCardSelector != null) {
- this.infoCardSelector.Dispose();
- }
- }
- }
- }
-}