summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs8
-rw-r--r--src/DotNetOpenAuth.Test/Mocks/TestChannel.cs11
-rw-r--r--src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs33
-rw-r--r--src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs4
-rw-r--r--src/DotNetOpenAuth/DotNetOpenAuth.csproj7
-rw-r--r--src/DotNetOpenAuth/Messaging/Channel.cs84
-rw-r--r--src/DotNetOpenAuth/Messaging/IWebRequestHandler.cs (renamed from src/DotNetOpenAuth/OAuth/ChannelElements/IWebRequestHandler.cs)4
-rw-r--r--src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs (renamed from src/DotNetOpenAuth/OAuth/ChannelElements/StandardWebRequestHandler.cs)2
-rw-r--r--src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs126
-rw-r--r--src/DotNetOpenAuth/OAuth/ConsumerBase.cs14
-rw-r--r--src/DotNetOpenAuth/OAuth/ServiceProvider.cs2
11 files changed, 130 insertions, 165 deletions
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs
index 8fbfaf9..9d4712c 100644
--- a/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/TestBadChannel.cs
@@ -7,8 +7,6 @@
namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Collections.Generic;
- using System.Linq;
- using System.Text;
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -39,11 +37,7 @@ namespace DotNetOpenAuth.Test.Mocks {
return base.ReadFromRequest(request);
}
- protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
- throw new NotImplementedException();
- }
-
- protected override IProtocolMessage ReadFromResponseInternal(System.IO.Stream responseStream) {
+ protected override IDictionary<string, string> ReadFromResponseInternal(Response response) {
throw new NotImplementedException();
}
diff --git a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs
index ebb5858..9c11589 100644
--- a/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs
+++ b/src/DotNetOpenAuth.Test/Mocks/TestChannel.cs
@@ -7,8 +7,7 @@
namespace DotNetOpenAuth.Test.Mocks {
using System;
using System.Collections.Generic;
- using System.Linq;
- using System.Text;
+ using System.Net;
using DotNetOpenAuth.Messaging;
internal class TestChannel : Channel {
@@ -20,12 +19,12 @@ namespace DotNetOpenAuth.Test.Mocks {
: base(messageTypeProvider, bindingElements) {
}
- protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
- throw new NotImplementedException("Request");
+ protected override IDictionary<string, string> ReadFromResponseInternal(Response response) {
+ throw new NotImplementedException("ReadFromResponseInternal");
}
- protected override IProtocolMessage ReadFromResponseInternal(System.IO.Stream responseStream) {
- throw new NotImplementedException("ReadFromResponse");
+ protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
+ throw new NotImplementedException("CreateHttpRequest");
}
protected override Response SendDirectMessageResponse(IProtocolMessage response) {
diff --git a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
index c5d3b14..fbbd6a6 100644
--- a/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
+++ b/src/DotNetOpenAuth.Test/OAuth/ChannelElements/OAuthChannelTests.cs
@@ -33,27 +33,23 @@ namespace DotNetOpenAuth.Test.ChannelElements {
this.webRequestHandler = new TestWebRequestHandler();
this.signingElement = new RsaSha1SigningBindingElement();
this.nonceStore = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge);
- this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider(), this.webRequestHandler);
- }
-
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void CtorNullHandler() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider(), null);
+ this.channel = new OAuthChannel(this.signingElement, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider());
+ this.channel.WebRequestHandler = this.webRequestHandler;
}
[TestMethod, ExpectedException(typeof(ArgumentException))]
public void CtorNullSigner() {
- new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider(), this.webRequestHandler);
+ new OAuthChannel(null, this.nonceStore, new InMemoryTokenManager(), new TestMessageTypeProvider());
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullStore() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageTypeProvider(), this.webRequestHandler);
+ new OAuthChannel(new RsaSha1SigningBindingElement(), null, new InMemoryTokenManager(), new TestMessageTypeProvider());
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
public void CtorNullTokenManager() {
- new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageTypeProvider(), this.webRequestHandler);
+ new OAuthChannel(new RsaSha1SigningBindingElement(), this.nonceStore, null, new TestMessageTypeProvider());
}
[TestMethod]
@@ -100,12 +96,6 @@ namespace DotNetOpenAuth.Test.ChannelElements {
Assert.AreEqual("http://hostb/pathB", body["Location"]);
}
- [TestMethod, ExpectedException(typeof(ArgumentNullException))]
- public void ReadFromResponseNull() {
- Channel_Accessor accessor = Channel_Accessor.AttachShadow(this.channel);
- accessor.ReadFromResponse(null);
- }
-
[TestMethod]
public void ReadFromResponse() {
var fields = new Dictionary<string, string> {
@@ -121,14 +111,11 @@ namespace DotNetOpenAuth.Test.ChannelElements {
writer.Flush();
ms.Seek(0, SeekOrigin.Begin);
Channel_Accessor channelAccessor = Channel_Accessor.AttachShadow(this.channel);
- IProtocolMessage message = channelAccessor.ReadFromResponse(ms);
- Assert.IsNotNull(message);
- Assert.IsInstanceOfType(message, typeof(TestMessage));
- TestMessage testMessage = (TestMessage)message;
- Assert.AreEqual(15, testMessage.Age);
- Assert.AreEqual("Andrew", testMessage.Name);
- Assert.AreEqual("http://hostb/pathB", testMessage.Location.AbsoluteUri);
- Assert.IsNull(testMessage.EmptyMember);
+ IDictionary<string, string> deserializedFields = channelAccessor.ReadFromResponseInternal(new Response { ResponseStream = ms });
+ Assert.AreEqual(fields.Count, deserializedFields.Count);
+ foreach (string key in fields.Keys) {
+ Assert.AreEqual(fields[key], deserializedFields[key]);
+ }
}
[TestMethod, ExpectedException(typeof(ArgumentNullException))]
diff --git a/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs b/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
index 9fae4a9..0fa474e 100644
--- a/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
+++ b/src/DotNetOpenAuth.Test/Scenarios/CoordinatingOAuthChannel.cs
@@ -11,7 +11,6 @@ namespace DotNetOpenAuth.Test.Scenarios {
using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
- using DotNetOpenAuth.Test.Mocks;
/// <summary>
/// A special channel used in test simulations to pass messages directly between two parties.
@@ -34,8 +33,7 @@ namespace DotNetOpenAuth.Test.Scenarios {
signingBindingElement,
new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge),
tokenManager,
- isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager),
- new TestWebRequestHandler()) {
+ isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager)) {
}
/// <summary>
diff --git a/src/DotNetOpenAuth/DotNetOpenAuth.csproj b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
index 40e265d..911b302 100644
--- a/src/DotNetOpenAuth/DotNetOpenAuth.csproj
+++ b/src/DotNetOpenAuth/DotNetOpenAuth.csproj
@@ -94,7 +94,7 @@
<Compile Include="Messaging\Bindings\NonceMemoryStore.cs" />
<Compile Include="OAuth\ChannelElements\SigningBindingElementBase.cs" />
<Compile Include="OAuth\WebConsumer.cs" />
- <Compile Include="OAuth\ChannelElements\IWebRequestHandler.cs" />
+ <Compile Include="Messaging\IWebRequestHandler.cs" />
<Compile Include="OAuth\ChannelElements\ITamperResistantOAuthMessage.cs" />
<Compile Include="OAuth\Messages\MessageBase.cs" />
<Compile Include="OAuth\Messages\AuthorizedTokenRequest.cs" />
@@ -144,6 +144,7 @@
<Compile Include="Messaging\MessageTransport.cs" />
<Compile Include="OAuth\ChannelElements\OAuthServiceProviderMessageTypeProvider.cs" />
<Compile Include="Messaging\ProtocolException.cs" />
+ <Compile Include="OpenId\ChannelElements\OpenIdChannel.cs" />
<Compile Include="OpenId\Messages\AssociateDiffieHellmanRequest.cs" />
<Compile Include="OpenId\Messages\AssociateDiffieHellmanResponse.cs" />
<Compile Include="OpenId\Messages\AssociateRequest.cs" />
@@ -161,7 +162,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="OAuth\Messages\UnauthorizedTokenRequest.cs" />
<Compile Include="OAuth\ChannelElements\RsaSha1SigningBindingElement.cs" />
- <Compile Include="OAuth\ChannelElements\StandardWebRequestHandler.cs" />
+ <Compile Include="Messaging\StandardWebRequestHandler.cs" />
<Compile Include="Messaging\MessageReceivingEndpoint.cs" />
<Compile Include="Util.cs" />
<Compile Include="OAuth\Protocol.cs" />
@@ -201,4 +202,4 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\tools\DotNetOpenAuth.Versioning.targets" />
-</Project>
+</Project> \ No newline at end of file
diff --git a/src/DotNetOpenAuth/Messaging/Channel.cs b/src/DotNetOpenAuth/Messaging/Channel.cs
index e1e1b06..c2ae6d1 100644
--- a/src/DotNetOpenAuth/Messaging/Channel.cs
+++ b/src/DotNetOpenAuth/Messaging/Channel.cs
@@ -77,6 +77,7 @@ namespace DotNetOpenAuth.Messaging {
}
this.messageTypeProvider = messageTypeProvider;
+ this.WebRequestHandler = new StandardWebRequestHandler();
this.bindingElements = new List<IChannelBindingElement>(ValidateAndPrepareBindingElements(bindingElements));
}
@@ -86,6 +87,16 @@ namespace DotNetOpenAuth.Messaging {
internal event EventHandler<ChannelEventArgs> Sending;
/// <summary>
+ /// Gets or sets an instance to a <see cref="IWebRequestHandler"/> that will be used when
+ /// submitting HTTP requests and waiting for responses.
+ /// </summary>
+ /// <remarks>
+ /// This defaults to a straightforward implementation, but can be set
+ /// to a mock object for testing purposes.
+ /// </remarks>
+ public IWebRequestHandler WebRequestHandler { get; set; }
+
+ /// <summary>
/// Gets the binding elements used by this channel, in the order they are applied to outgoing messages.
/// </summary>
/// <remarks>
@@ -302,13 +313,12 @@ namespace DotNetOpenAuth.Messaging {
this.PrepareMessageForSending(request);
Logger.DebugFormat("Sending request: {0}", request);
- IProtocolMessage response = this.RequestInternal(request);
- if (response != null) {
- Logger.DebugFormat("Received response: {0}", response);
- this.VerifyMessageAfterReceiving(response);
- }
+ var responseMessage = this.RequestInternal(request);
- return response;
+ Logger.DebugFormat("Received message response: {0}", responseMessage);
+ this.VerifyMessageAfterReceiving(responseMessage);
+
+ return responseMessage;
}
/// <summary>
@@ -343,6 +353,36 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
+ /// Submits a direct request message to some remote party and blocks waiting for an immediately reply.
+ /// </summary>
+ /// <param name="request">The request message.</param>
+ /// <returns>The response message, or null if the response did not carry a message.</returns>
+ /// <remarks>
+ /// Typically a deriving channel will override <see cref="CreateHttpRequest"/> to customize this method's
+ /// behavior. However in non-HTTP frameworks, such as unit test mocks, it may be appropriate to override
+ /// this method to eliminate all use of an HTTP transport.
+ /// </remarks>
+ protected virtual IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
+ HttpWebRequest webRequest = this.CreateHttpRequest(request);
+
+ Response response = this.WebRequestHandler.GetResponse(webRequest);
+ if (response.ResponseStream == null) {
+ return null;
+ }
+
+ var responseFields = this.ReadFromResponseInternal(response);
+ Type messageType = this.MessageTypeProvider.GetResponseMessageType(request, responseFields);
+ if (messageType == null) {
+ return null;
+ }
+
+ var responseSerialize = MessageSerializer.Get(messageType);
+ var responseMessage = responseSerialize.Deserialize(responseFields, null);
+
+ return responseMessage;
+ }
+
+ /// <summary>
/// Gets the protocol message that may be embedded in the given HTTP request.
/// </summary>
/// <param name="request">The request to search for an embedded message.</param>
@@ -484,18 +524,24 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
- /// Gets the protocol message that may be in the given HTTP response stream.
+ /// Gets the protocol message that may be in the given HTTP response.
/// </summary>
- /// <param name="responseStream">The response that is anticipated to contain an OAuth message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected abstract IProtocolMessage ReadFromResponseInternal(Stream responseStream);
+ /// <param name="response">The response that is anticipated to contain an protocol message.</param>
+ /// <returns>The deserialized message parts, if found. Null otherwise.</returns>
+ protected abstract IDictionary<string, string> ReadFromResponseInternal(Response response);
/// <summary>
- /// Sends a direct message to a remote party and waits for the response.
+ /// Prepares an HTTP request that carries a given message.
/// </summary>
/// <param name="request">The message to send.</param>
- /// <returns>The remote party's response.</returns>
- protected abstract IProtocolMessage RequestInternal(IDirectedProtocolMessage request);
+ /// <returns>The <see cref="HttpWebRequest"/> prepared to send the request.</returns>
+ /// <remarks>
+ /// This method must be overridden by a derived class, unless the <see cref="RequestInternal"/> method
+ /// is overridden and does not require this method.
+ /// </remarks>
+ protected virtual HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
+ throw new NotImplementedException();
+ }
/// <summary>
/// Queues a message for sending in the response stream where the fields
@@ -650,18 +696,6 @@ namespace DotNetOpenAuth.Messaging {
}
/// <summary>
- /// Gets the protocol message that may be in the given HTTP response stream.
- /// </summary>
- /// <param name="responseStream">The response that is anticipated to contain an OAuth message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- private IProtocolMessage ReadFromResponse(Stream responseStream) {
- IProtocolMessage message = this.ReadFromResponseInternal(responseStream);
- Logger.DebugFormat("Received message response: {0}", message);
- this.VerifyMessageAfterReceiving(message);
- return message;
- }
-
- /// <summary>
/// Verifies the integrity and applicability of an incoming message.
/// </summary>
/// <param name="message">The message just received.</param>
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/IWebRequestHandler.cs b/src/DotNetOpenAuth/Messaging/IWebRequestHandler.cs
index 9767875..b2c60be 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/IWebRequestHandler.cs
+++ b/src/DotNetOpenAuth/Messaging/IWebRequestHandler.cs
@@ -4,7 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.OAuth.ChannelElements {
+namespace DotNetOpenAuth.Messaging {
using System.IO;
using System.Net;
using DotNetOpenAuth.Messaging;
@@ -12,7 +12,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// <summary>
/// A contract for <see cref="HttpWebRequest"/> handling.
/// </summary>
- internal interface IWebRequestHandler {
+ public interface IWebRequestHandler {
/// <summary>
/// Prepares an <see cref="HttpWebRequest"/> that contains an POST entity for sending the entity.
/// </summary>
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/StandardWebRequestHandler.cs b/src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs
index 7b5463c..c27234c 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/StandardWebRequestHandler.cs
+++ b/src/DotNetOpenAuth/Messaging/StandardWebRequestHandler.cs
@@ -4,7 +4,7 @@
// </copyright>
//-----------------------------------------------------------------------
-namespace DotNetOpenAuth.OAuth.ChannelElements {
+namespace DotNetOpenAuth.Messaging {
using System;
using System.IO;
using System.Net;
diff --git a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
index b6f20d1..de4bddb 100644
--- a/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
+++ b/src/DotNetOpenAuth/OAuth/ChannelElements/OAuthChannel.cs
@@ -22,12 +22,6 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// </summary>
internal class OAuthChannel : Channel {
/// <summary>
- /// The object that will transmit <see cref="HttpWebRequest"/> instances
- /// and return their responses.
- /// </summary>
- private IWebRequestHandler webRequestHandler;
-
- /// <summary>
/// Initializes a new instance of the <see cref="OAuthChannel"/> class.
/// </summary>
/// <param name="signingBindingElement">The binding element to use for signing.</param>
@@ -39,8 +33,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
signingBindingElement,
store,
tokenManager,
- isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager),
- new StandardWebRequestHandler()) {
+ isConsumer ? (IMessageTypeProvider)new OAuthConsumerMessageTypeProvider() : new OAuthServiceProviderMessageTypeProvider(tokenManager)) {
}
/// <summary>
@@ -54,23 +47,15 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// Except for mock testing, this should always be one of
/// <see cref="OAuthConsumerMessageTypeProvider"/> or <see cref="OAuthServiceProviderMessageTypeProvider"/>.
/// </param>
- /// <param name="webRequestHandler">
- /// An instance to a <see cref="IWebRequestHandler"/> that will be used when submitting HTTP
- /// requests and waiting for responses.
- /// </param>
/// <remarks>
/// This overload for testing purposes only.
/// </remarks>
- internal OAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, ITokenManager tokenManager, IMessageTypeProvider messageTypeProvider, IWebRequestHandler webRequestHandler)
+ internal OAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, INonceStore store, ITokenManager tokenManager, IMessageTypeProvider messageTypeProvider)
: base(messageTypeProvider, new OAuthHttpMethodBindingElement(), signingBindingElement, new StandardExpirationBindingElement(), new StandardReplayProtectionBindingElement(store)) {
if (tokenManager == null) {
throw new ArgumentNullException("tokenManager");
}
- if (webRequestHandler == null) {
- throw new ArgumentNullException("webRequestHandler");
- }
- this.webRequestHandler = webRequestHandler;
this.TokenManager = tokenManager;
if (signingBindingElement.SignatureCallback != null) {
throw new ArgumentException(OAuthStrings.SigningElementAlreadyAssociatedWithChannel, "signingBindingElement");
@@ -133,7 +118,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
}
PrepareMessageForSending(request);
- return this.InitializeRequestInternal(request);
+ return this.CreateHttpRequest(request);
}
/// <summary>
@@ -187,43 +172,57 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
}
/// <summary>
- /// Gets the protocol message that may be in the given HTTP response stream.
+ /// Gets the protocol message that may be in the given HTTP response.
/// </summary>
- /// <param name="responseStream">The response that is anticipated to contain an OAuth message.</param>
- /// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected override IProtocolMessage ReadFromResponseInternal(Stream responseStream) {
- if (responseStream == null) {
- throw new ArgumentNullException("responseStream");
+ /// <param name="response">The response that is anticipated to contain an protocol message.</param>
+ /// <returns>
+ /// The deserialized message parts, if found. Null otherwise.
+ /// </returns>
+ protected override IDictionary<string, string> ReadFromResponseInternal(Response response) {
+ if (response == null) {
+ throw new ArgumentNullException("response");
}
- using (StreamReader reader = new StreamReader(responseStream)) {
- string response = reader.ReadToEnd();
- var fields = HttpUtility.ParseQueryString(response).ToDictionary();
- return Receive(fields, null);
- }
+ return HttpUtility.ParseQueryString(response.Body).ToDictionary();
}
/// <summary>
- /// Sends a direct message to a remote party and waits for the response.
+ /// Prepares an HTTP request that carries a given message.
/// </summary>
/// <param name="request">The message to send.</param>
- /// <returns>The remote party's response.</returns>
- protected override IProtocolMessage RequestInternal(IDirectedProtocolMessage request) {
- HttpWebRequest httpRequest = this.InitializeRequestInternal(request);
-
- Response response = this.webRequestHandler.GetResponse(httpRequest);
- if (response.ResponseStream == null) {
- return null;
+ /// <returns>
+ /// The <see cref="HttpRequest"/> prepared to send the request.
+ /// </returns>
+ protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
+ if (request == null) {
+ throw new ArgumentNullException("request");
}
- var responseFields = HttpUtility.ParseQueryString(response.Body).ToDictionary();
- Type messageType = this.MessageTypeProvider.GetResponseMessageType(request, responseFields);
- if (messageType == null) {
- return null;
+ if (request.Recipient == null) {
+ throw new ArgumentException(MessagingStrings.DirectedMessageMissingRecipient, "request");
+ }
+ IOAuthDirectedMessage oauthRequest = request as IOAuthDirectedMessage;
+ if (oauthRequest == null) {
+ throw new ArgumentException(
+ string.Format(
+ CultureInfo.CurrentCulture,
+ MessagingStrings.UnexpectedType,
+ typeof(IOAuthDirectedMessage),
+ request.GetType()));
}
- var responseSerialize = MessageSerializer.Get(messageType);
- var responseMessage = responseSerialize.Deserialize(responseFields, null);
- return responseMessage;
+ HttpWebRequest httpRequest;
+
+ HttpDeliveryMethods transmissionMethod = oauthRequest.HttpMethods;
+ if ((transmissionMethod & HttpDeliveryMethods.AuthorizationHeaderRequest) != 0) {
+ httpRequest = this.InitializeRequestAsAuthHeader(request);
+ } else if ((transmissionMethod & HttpDeliveryMethods.PostRequest) != 0) {
+ httpRequest = this.InitializeRequestAsPost(request);
+ } else if ((transmissionMethod & HttpDeliveryMethods.GetRequest) != 0) {
+ httpRequest = InitializeRequestAsGet(request);
+ } else {
+ throw new NotSupportedException();
+ }
+ return httpRequest;
}
/// <summary>
@@ -273,43 +272,6 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
}
/// <summary>
- /// Initializes a web request by attaching a message to it.
- /// </summary>
- /// <param name="request">The message to attach.</param>
- /// <returns>The initialized web request.</returns>
- private HttpWebRequest InitializeRequestInternal(IDirectedProtocolMessage request) {
- if (request == null) {
- throw new ArgumentNullException("request");
- }
- if (request.Recipient == null) {
- throw new ArgumentException(MessagingStrings.DirectedMessageMissingRecipient, "request");
- }
- IOAuthDirectedMessage oauthRequest = request as IOAuthDirectedMessage;
- if (oauthRequest == null) {
- throw new ArgumentException(
- string.Format(
- CultureInfo.CurrentCulture,
- MessagingStrings.UnexpectedType,
- typeof(IOAuthDirectedMessage),
- request.GetType()));
- }
-
- HttpWebRequest httpRequest;
-
- HttpDeliveryMethods transmissionMethod = oauthRequest.HttpMethods;
- if ((transmissionMethod & HttpDeliveryMethods.AuthorizationHeaderRequest) != 0) {
- httpRequest = this.InitializeRequestAsAuthHeader(request);
- } else if ((transmissionMethod & HttpDeliveryMethods.PostRequest) != 0) {
- httpRequest = this.InitializeRequestAsPost(request);
- } else if ((transmissionMethod & HttpDeliveryMethods.GetRequest) != 0) {
- httpRequest = InitializeRequestAsGet(request);
- } else {
- throw new NotSupportedException();
- }
- return httpRequest;
- }
-
- /// <summary>
/// Prepares to send a request to the Service Provider via the Authorization header.
/// </summary>
/// <param name="requestMessage">The message to be transmitted to the ServiceProvider.</param>
@@ -369,7 +331,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
httpRequest.ContentType = "application/x-www-form-urlencoded";
string requestBody = MessagingUtilities.CreateQueryString(fields);
httpRequest.ContentLength = requestBody.Length;
- using (TextWriter writer = this.webRequestHandler.GetRequestStream(httpRequest)) {
+ using (TextWriter writer = this.WebRequestHandler.GetRequestStream(httpRequest)) {
writer.Write(requestBody);
}
diff --git a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs
index 63c04ea..22e9bdc 100644
--- a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs
+++ b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs
@@ -31,10 +31,9 @@ namespace DotNetOpenAuth.OAuth {
throw new ArgumentNullException("tokenManager");
}
- this.WebRequestHandler = new StandardWebRequestHandler();
ITamperProtectionChannelBindingElement signingElement = serviceDescription.CreateTamperProtectionElement();
INonceStore store = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge);
- this.OAuthChannel = new OAuthChannel(signingElement, store, tokenManager, new OAuthConsumerMessageTypeProvider(), this.WebRequestHandler);
+ this.OAuthChannel = new OAuthChannel(signingElement, store, tokenManager, new OAuthConsumerMessageTypeProvider());
this.ServiceProvider = serviceDescription;
}
@@ -68,15 +67,6 @@ namespace DotNetOpenAuth.OAuth {
internal OAuthChannel OAuthChannel { get; set; }
/// <summary>
- /// Gets or sets the object that processes <see cref="HttpWebRequest"/>s.
- /// </summary>
- /// <remarks>
- /// This defaults to a straightforward implementation, but can be set
- /// to a mock object for testing purposes.
- /// </remarks>
- internal IWebRequestHandler WebRequestHandler { get; set; }
-
- /// <summary>
/// Creates a web request prepared with OAuth authorization
/// that may be further tailored by adding parameters by the caller.
/// </summary>
@@ -100,7 +90,7 @@ namespace DotNetOpenAuth.OAuth {
public Response PrepareAuthorizedRequestAndSend(MessageReceivingEndpoint endpoint, string accessToken) {
IDirectedProtocolMessage message = this.CreateAuthorizingMessage(endpoint, accessToken);
HttpWebRequest wr = this.OAuthChannel.InitializeRequest(message);
- return this.WebRequestHandler.GetResponse(wr);
+ return this.Channel.WebRequestHandler.GetResponse(wr);
}
/// <summary>
diff --git a/src/DotNetOpenAuth/OAuth/ServiceProvider.cs b/src/DotNetOpenAuth/OAuth/ServiceProvider.cs
index a303845..bbd7d4b 100644
--- a/src/DotNetOpenAuth/OAuth/ServiceProvider.cs
+++ b/src/DotNetOpenAuth/OAuth/ServiceProvider.cs
@@ -60,7 +60,7 @@ namespace DotNetOpenAuth.OAuth {
var signingElement = serviceDescription.CreateTamperProtectionElement();
INonceStore store = new NonceMemoryStore(StandardExpirationBindingElement.DefaultMaximumMessageAge);
this.ServiceDescription = serviceDescription;
- this.OAuthChannel = new OAuthChannel(signingElement, store, tokenManager, messageTypeProvider, new StandardWebRequestHandler());
+ this.OAuthChannel = new OAuthChannel(signingElement, store, tokenManager, messageTypeProvider);
this.TokenGenerator = new StandardTokenGenerator();
}