summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/Channel.cs20
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/IMessageWithBinaryData.cs2
-rw-r--r--src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs18
-rw-r--r--src/DotNetOpenAuth.OAuth/DotNetOpenAuth.OAuth.csproj2
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/ITamperResistantOAuthMessage.cs4
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs72
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs6
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementBase.cs10
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementChain.cs10
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/Messages/AccessProtectedResourceRequest.cs8
-rw-r--r--src/DotNetOpenAuth.OAuth/OAuth/Messages/SignedMessageBase.cs5
-rw-r--r--src/DotNetOpenAuth.OAuth/packages.config1
12 files changed, 88 insertions, 70 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/Channel.cs b/src/DotNetOpenAuth.Core/Messaging/Channel.cs
index 9d55e78..7eadecd 100644
--- a/src/DotNetOpenAuth.Core/Messaging/Channel.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/Channel.cs
@@ -558,15 +558,17 @@ namespace DotNetOpenAuth.Messaging {
/// </summary>
/// <param name="httpMethod">The HTTP method.</param>
/// <returns><c>true</c> if the HTTP method is supposed to have an entity; <c>false</c> otherwise.</returns>
- protected static bool HttpMethodHasEntity(string httpMethod) {
- if (string.Equals(httpMethod, "GET", StringComparison.Ordinal) ||
- string.Equals(httpMethod, "HEAD", StringComparison.Ordinal) ||
- string.Equals(httpMethod, "DELETE", StringComparison.Ordinal) ||
- string.Equals(httpMethod, "OPTIONS", StringComparison.Ordinal)) {
+ protected static bool HttpMethodHasEntity(HttpMethod httpMethod) {
+ Requires.NotNull(httpMethod, "httpMethod");
+
+ if (httpMethod == HttpMethod.Get ||
+ httpMethod == HttpMethod.Head ||
+ httpMethod == HttpMethod.Delete ||
+ httpMethod == HttpMethod.Options) {
return false;
- } else if (string.Equals(httpMethod, "POST", StringComparison.Ordinal) ||
- string.Equals(httpMethod, "PUT", StringComparison.Ordinal) ||
- string.Equals(httpMethod, "PATCH", StringComparison.Ordinal)) {
+ } else if (httpMethod == HttpMethod.Post ||
+ httpMethod == HttpMethod.Put ||
+ string.Equals(httpMethod.Method, "PATCH", StringComparison.Ordinal)) {
return true;
} else {
throw ErrorUtilities.ThrowArgumentNamed("httpMethod", MessagingStrings.UnsupportedHttpVerb, httpMethod);
@@ -1041,7 +1043,7 @@ namespace DotNetOpenAuth.Messaging {
if (requestMessageWithBinaryData != null && requestMessageWithBinaryData.SendAsMultipart) {
var content = new MultipartFormDataContent();
foreach (var part in requestMessageWithBinaryData.BinaryData) {
- content.Add(part);
+ content.Add(part.Value, part.Key);
}
// When sending multi-part, all data gets send as multi-part -- even the non-binary data.
diff --git a/src/DotNetOpenAuth.Core/Messaging/IMessageWithBinaryData.cs b/src/DotNetOpenAuth.Core/Messaging/IMessageWithBinaryData.cs
index 074894c..bcf4d8d 100644
--- a/src/DotNetOpenAuth.Core/Messaging/IMessageWithBinaryData.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/IMessageWithBinaryData.cs
@@ -20,7 +20,7 @@ namespace DotNetOpenAuth.Messaging {
/// Gets the parts of the message that carry binary data.
/// </summary>
/// <value>A list of parts. Never null.</value>
- IList<HttpContent> BinaryData { get; }
+ IDictionary<string, HttpContent> BinaryData { get; }
/// <summary>
/// Gets a value indicating whether this message should be sent as multi-part POST.
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
index 2aee6ea..d9fedf2 100644
--- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
+++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs
@@ -1484,23 +1484,23 @@ namespace DotNetOpenAuth.Messaging {
/// </summary>
/// <param name="httpMethod">The HTTP method.</param>
/// <returns>An HTTP verb, such as GET, POST, PUT, DELETE, PATCH, or OPTION.</returns>
- internal static string GetHttpVerb(HttpDeliveryMethods httpMethod) {
+ internal static HttpMethod GetHttpVerb(HttpDeliveryMethods httpMethod) {
if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.GetRequest) {
- return "GET";
+ return HttpMethod.Get;
} else if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.PostRequest) {
- return "POST";
+ return HttpMethod.Post;
} else if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.PutRequest) {
- return "PUT";
+ return HttpMethod.Put;
} else if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.DeleteRequest) {
- return "DELETE";
+ return HttpMethod.Delete;
} else if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.HeadRequest) {
- return "HEAD";
+ return HttpMethod.Head;
} else if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.PatchRequest) {
- return "PATCH";
+ return new HttpMethod("PATCH");
} else if ((httpMethod & HttpDeliveryMethods.HttpVerbMask) == HttpDeliveryMethods.OptionsRequest) {
- return "OPTIONS";
+ return HttpMethod.Options;
} else if ((httpMethod & HttpDeliveryMethods.AuthorizationHeaderRequest) != 0) {
- return "GET"; // if AuthorizationHeaderRequest is specified without an explicit HTTP verb, assume GET.
+ return HttpMethod.Get; // if AuthorizationHeaderRequest is specified without an explicit HTTP verb, assume GET.
} else {
throw ErrorUtilities.ThrowArgumentNamed("httpMethod", MessagingStrings.UnsupportedHttpVerb, httpMethod);
}
diff --git a/src/DotNetOpenAuth.OAuth/DotNetOpenAuth.OAuth.csproj b/src/DotNetOpenAuth.OAuth/DotNetOpenAuth.OAuth.csproj
index 651b414..da914e6 100644
--- a/src/DotNetOpenAuth.OAuth/DotNetOpenAuth.OAuth.csproj
+++ b/src/DotNetOpenAuth.OAuth/DotNetOpenAuth.OAuth.csproj
@@ -84,6 +84,8 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
+ <Reference Include="System.Net.Http" />
+ <Reference Include="System.Net.Http.WebRequest" />
<Reference Include="Validation">
<HintPath>..\packages\Validation.2.0.1.12362\lib\portable-windows8+net40+sl5+windowsphone8\Validation.dll</HintPath>
<Private>True</Private>
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/ITamperResistantOAuthMessage.cs b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/ITamperResistantOAuthMessage.cs
index 9cb0a44..679b1dc 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/ITamperResistantOAuthMessage.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/ITamperResistantOAuthMessage.cs
@@ -7,6 +7,8 @@
namespace DotNetOpenAuth.OAuth.ChannelElements {
using System;
using System.Collections.Generic;
+ using System.Net.Http;
+
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
@@ -37,7 +39,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// <summary>
/// Gets or sets the HTTP method that will be used to transmit the message.
/// </summary>
- string HttpMethod { get; set; }
+ HttpMethod HttpMethod { get; set; }
/// <summary>
/// Gets or sets the URL of the intended receiver of this message.
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs
index 10d83d3..e69815d 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthChannel.cs
@@ -13,8 +13,12 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
using System.IO;
using System.Linq;
using System.Net;
+ using System.Net.Http;
+ using System.Net.Http.Headers;
using System.Net.Mime;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
@@ -22,6 +26,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
using DotNetOpenAuth.OAuth.Messages;
using Validation;
+ using HttpRequestHeaders = DotNetOpenAuth.Messaging.HttpRequestHeaders;
+
/// <summary>
/// An OAuth-specific implementation of the <see cref="Channel"/> class.
/// </summary>
@@ -37,8 +43,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// OAuthConsumerMessageFactory or OAuthServiceProviderMessageFactory.</param>
/// <param name="bindingElements">The binding elements.</param>
[SuppressMessage("Microsoft.Globalization", "CA1303:Do not pass literals as localized parameters", MessageId = "System.Diagnostics.Contracts.__ContractsRuntime.Requires<System.ArgumentNullException>(System.Boolean,System.String,System.String)", Justification = "Code contracts"), SuppressMessage("Microsoft.Naming", "CA2204:Literals should be spelled correctly", MessageId = "securitySettings", Justification = "Code contracts")]
- protected OAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, ITokenManager tokenManager, SecuritySettings securitySettings, IMessageFactory messageTypeProvider, IChannelBindingElement[] bindingElements)
- : base(messageTypeProvider, bindingElements) {
+ protected OAuthChannel(ITamperProtectionChannelBindingElement signingBindingElement, ITokenManager tokenManager, SecuritySettings securitySettings, IMessageFactory messageTypeProvider, IChannelBindingElement[] bindingElements, IHostFactories hostFactories = null)
+ : base(messageTypeProvider, bindingElements, hostFactories) {
Requires.NotNull(tokenManager, "tokenManager");
Requires.NotNull(securitySettings, "securitySettings");
Requires.NotNull(signingBindingElement, "signingBindingElement");
@@ -77,10 +83,10 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// </summary>
/// <param name="request">The message to attach.</param>
/// <returns>The initialized web request.</returns>
- internal HttpWebRequest InitializeRequest(IDirectedProtocolMessage request) {
+ internal async Task<HttpRequestMessage> InitializeRequestAsync(IDirectedProtocolMessage request, CancellationToken cancellationToken) {
Requires.NotNull(request, "request");
- ProcessOutgoingMessage(request);
+ await this.ProcessOutgoingMessageAsync(request, cancellationToken);
return this.CreateHttpRequest(request);
}
@@ -109,7 +115,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// </summary>
/// <param name="request">The HTTP request to search.</param>
/// <returns>The deserialized message, if one is found. Null otherwise.</returns>
- protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request) {
+ protected override IDirectedProtocolMessage ReadFromRequestCore(HttpRequestBase request, CancellationToken cancellationToken) {
// First search the Authorization header.
string authorization = request.Headers[HttpRequestHeaders.Authorization];
var fields = MessagingUtilities.ParseAuthorizationHeader(Protocol.AuthorizationHeaderScheme, authorization).ToDictionary();
@@ -154,7 +160,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
var signedMessage = message as ITamperResistantOAuthMessage;
if (signedMessage != null) {
signedMessage.Recipient = request.GetPublicFacingUrl();
- signedMessage.HttpMethod = request.HttpMethod;
+ signedMessage.HttpMethod = new HttpMethod(request.HttpMethod);
}
return message;
@@ -167,8 +173,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// <returns>
/// The deserialized message parts, if found. Null otherwise.
/// </returns>
- protected override IDictionary<string, string> ReadFromResponseCore(IncomingWebResponse response) {
- string body = response.GetResponseReader().ReadToEnd();
+ protected override async Task<IDictionary<string, string>> ReadFromResponseCoreAsync(HttpResponseMessage response) {
+ string body = await response.Content.ReadAsStringAsync();
return HttpUtility.ParseQueryString(body).ToDictionary();
}
@@ -179,8 +185,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// <returns>
/// The <see cref="HttpRequest"/> prepared to send the request.
/// </returns>
- protected override HttpWebRequest CreateHttpRequest(IDirectedProtocolMessage request) {
- HttpWebRequest httpRequest;
+ protected override HttpRequestMessage CreateHttpRequest(IDirectedProtocolMessage request) {
+ HttpRequestMessage httpRequest;
HttpDeliveryMethods transmissionMethod = request.HttpMethods;
if ((transmissionMethod & HttpDeliveryMethods.AuthorizationHeaderRequest) != 0) {
@@ -200,6 +206,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
} else {
throw new NotSupportedException();
}
+
return httpRequest;
}
@@ -212,16 +219,13 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// <remarks>
/// This method implements spec V1.0 section 5.3.
/// </remarks>
- protected override OutgoingWebResponse PrepareDirectResponse(IProtocolMessage response) {
+ protected override HttpResponseMessage PrepareDirectResponse(IProtocolMessage response) {
var messageAccessor = this.MessageDescriptions.GetAccessor(response);
var fields = messageAccessor.Serialize();
string responseBody = MessagingUtilities.CreateQueryString(fields);
- OutgoingWebResponse encodedResponse = new OutgoingWebResponse {
- Body = responseBody,
- OriginalMessage = response,
- Status = HttpStatusCode.OK,
- Headers = new System.Net.WebHeaderCollection(),
+ HttpResponseMessage encodedResponse = new HttpResponseMessage {
+ Content = new StringContent(responseBody),
};
ApplyMessageTemplate(response, encodedResponse);
@@ -256,7 +260,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// </summary>
/// <param name="message">The message.</param>
/// <returns>"POST", "GET" or some other similar http verb.</returns>
- private static string GetHttpMethod(IDirectedProtocolMessage message) {
+ private static HttpMethod GetHttpMethod(IDirectedProtocolMessage message) {
Requires.NotNull(message, "message");
var signedMessage = message as ITamperResistantOAuthMessage;
@@ -273,11 +277,9 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// <param name="requestMessage">The message to be transmitted to the ServiceProvider.</param>
/// <returns>The web request ready to send.</returns>
/// <remarks>
- /// <para>If the message has non-empty ExtraData in it, the request stream is sent to
- /// the server automatically. If it is empty, the request stream must be sent by the caller.</para>
- /// <para>This method implements OAuth 1.0 section 5.2, item #1 (described in section 5.4).</para>
+ /// This method implements OAuth 1.0 section 5.2, item #1 (described in section 5.4).
/// </remarks>
- private HttpWebRequest InitializeRequestAsAuthHeader(IDirectedProtocolMessage requestMessage) {
+ private HttpRequestMessage InitializeRequestAsAuthHeader(IDirectedProtocolMessage requestMessage) {
var dictionary = this.MessageDescriptions.GetAccessor(requestMessage);
// copy so as to not modify original
@@ -285,41 +287,41 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
foreach (string key in dictionary.DeclaredKeys) {
fields.Add(key, dictionary[key]);
}
+
if (this.Realm != null) {
fields.Add("realm", this.Realm.AbsoluteUri);
}
- HttpWebRequest httpRequest;
UriBuilder recipientBuilder = new UriBuilder(requestMessage.Recipient);
bool hasEntity = HttpMethodHasEntity(GetHttpMethod(requestMessage));
if (!hasEntity) {
MessagingUtilities.AppendQueryArgs(recipientBuilder, requestMessage.ExtraData);
}
- httpRequest = (HttpWebRequest)WebRequest.Create(recipientBuilder.Uri);
+
+ var httpRequest = new HttpRequestMessage(GetHttpMethod(requestMessage), recipientBuilder.Uri);
this.PrepareHttpWebRequest(httpRequest);
- httpRequest.Method = GetHttpMethod(requestMessage);
- httpRequest.Headers.Add(HttpRequestHeader.Authorization, MessagingUtilities.AssembleAuthorizationHeader(Protocol.AuthorizationHeaderScheme, fields));
+ httpRequest.Headers.Authorization = new AuthenticationHeaderValue(MessagingUtilities.AssembleAuthorizationHeader(Protocol.AuthorizationHeaderScheme, fields));
if (hasEntity) {
- // WARNING: We only set up the request stream for the caller if there is
- // extra data. If there isn't any extra data, the caller must do this themselves.
var requestMessageWithBinaryData = requestMessage as IMessageWithBinaryData;
if (requestMessageWithBinaryData != null && requestMessageWithBinaryData.SendAsMultipart) {
// Include the binary data in the multipart entity, and any standard text extra message data.
// The standard declared message parts are included in the authorization header.
- var multiPartFields = new List<MultipartPostPart>(requestMessageWithBinaryData.BinaryData);
- multiPartFields.AddRange(requestMessage.ExtraData.Select(field => MultipartPostPart.CreateFormPart(field.Key, field.Value)));
- this.SendParametersInEntityAsMultipart(httpRequest, multiPartFields);
+ var content = new MultipartFormDataContent();
+ httpRequest.Content = content;
+ foreach (var contentPart in requestMessageWithBinaryData.BinaryData) {
+ content.Add(contentPart.Value, contentPart.Key);
+ }
+
+ foreach (var extraData in requestMessage.ExtraData) {
+ content.Add(new StringContent(extraData.Value), extraData.Key);
+ }
} else {
ErrorUtilities.VerifyProtocol(requestMessageWithBinaryData == null || requestMessageWithBinaryData.BinaryData.Count == 0, MessagingStrings.BinaryDataRequiresMultipart);
if (requestMessage.ExtraData.Count > 0) {
- this.PrepareParametersForEntity(httpRequest, requestMessage.ExtraData);
- } else {
- // We'll assume the content length is zero since the caller may not have
- // anything. They're responsible to change it when the add the payload if they have one.
- httpRequest.ContentLength = 0;
+ httpRequest.Content = new FormUrlEncodedContent(requestMessage.ExtraData);
}
}
}
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs
index 98eb9b3..75de10b 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/OAuthHttpMethodBindingElement.cs
@@ -9,6 +9,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -37,7 +39,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// True if the <paramref name="message"/> applied to this binding element
/// and the operation was successful. False otherwise.
/// </returns>
- public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
+ public async Task<MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var oauthMessage = message as ITamperResistantOAuthMessage;
if (oauthMessage != null) {
@@ -67,7 +69,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// Thrown when the binding element rules indicate that this message is invalid and should
/// NOT be processed.
/// </exception>
- public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
+ public async Task<MessageProtections?> ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
return null;
}
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementBase.cs b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementBase.cs
index 780afdc..4316333 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementBase.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementBase.cs
@@ -12,6 +12,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
using System.Globalization;
using System.Linq;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
@@ -83,7 +85,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// The protections (if any) that this binding element applied to the message.
/// Null if this binding element did not even apply to this binding element.
/// </returns>
- public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
+ public async Task<MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var signedMessage = message as ITamperResistantOAuthMessage;
if (signedMessage != null && this.IsMessageApplicable(signedMessage)) {
if (this.SignatureCallback != null) {
@@ -110,7 +112,7 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// Null if this binding element did not even apply to this binding element.
/// </returns>
/// <exception cref="InvalidSignatureException">Thrown if the signature is invalid.</exception>
- public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
+ public async Task<MessageProtections?> ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
var signedMessage = message as ITamperResistantOAuthMessage;
if (signedMessage != null && this.IsMessageApplicable(signedMessage)) {
Logger.Bindings.DebugFormat("Verifying incoming {0} message signature of: {1}", message.GetType().Name, signedMessage.Signature);
@@ -151,13 +153,13 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling", Justification = "Unavoidable")]
internal static string ConstructSignatureBaseString(ITamperResistantOAuthMessage message, MessageDictionary messageDictionary) {
Requires.NotNull(message, "message");
- Requires.NotNullOrEmpty(message.HttpMethod, "message.HttpMethod");
+ Requires.NotNull(message.HttpMethod, "message.HttpMethod");
Requires.NotNull(messageDictionary, "messageDictionary");
ErrorUtilities.VerifyInternal(messageDictionary.Message == message, "Message references are not equal.");
List<string> signatureBaseStringElements = new List<string>(3);
- signatureBaseStringElements.Add(message.HttpMethod.ToUpperInvariant());
+ signatureBaseStringElements.Add(message.HttpMethod.ToString().ToUpperInvariant());
// For multipart POST messages, only include the message parts that are NOT
// in the POST entity (those parts that may appear in an OAuth authorization header).
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementChain.cs b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementChain.cs
index 2b25566..0b38a26 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementChain.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/ChannelElements/SigningBindingElementChain.cs
@@ -9,6 +9,8 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using System.Threading;
+ using System.Threading.Tasks;
using DotNetOpenAuth.Messaging;
using Validation;
@@ -90,10 +92,10 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// The protections (if any) that this binding element applied to the message.
/// Null if this binding element did not even apply to this binding element.
/// </returns>
- public MessageProtections? ProcessOutgoingMessage(IProtocolMessage message) {
+ public async Task<MessageProtections?> ProcessOutgoingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
foreach (IChannelBindingElement signer in this.signers) {
ErrorUtilities.VerifyInternal(signer.Channel != null, "A binding element's Channel property is unexpectedly null.");
- MessageProtections? result = signer.ProcessOutgoingMessage(message);
+ MessageProtections? result = await signer.ProcessOutgoingMessageAsync(message, cancellationToken);
if (result.HasValue) {
return result;
}
@@ -111,10 +113,10 @@ namespace DotNetOpenAuth.OAuth.ChannelElements {
/// The protections (if any) that this binding element applied to the message.
/// Null if this binding element did not even apply to this binding element.
/// </returns>
- public MessageProtections? ProcessIncomingMessage(IProtocolMessage message) {
+ public async Task<MessageProtections?> ProcessIncomingMessageAsync(IProtocolMessage message, CancellationToken cancellationToken) {
foreach (IChannelBindingElement signer in this.signers) {
ErrorUtilities.VerifyInternal(signer.Channel != null, "A binding element's Channel property is unexpectedly null.");
- MessageProtections? result = signer.ProcessIncomingMessage(message);
+ MessageProtections? result = await signer.ProcessIncomingMessageAsync(message, cancellationToken);
if (result.HasValue) {
return result;
}
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/Messages/AccessProtectedResourceRequest.cs b/src/DotNetOpenAuth.OAuth/OAuth/Messages/AccessProtectedResourceRequest.cs
index aeee649..77b1733 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/Messages/AccessProtectedResourceRequest.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/Messages/AccessProtectedResourceRequest.cs
@@ -8,6 +8,8 @@ namespace DotNetOpenAuth.OAuth.Messages {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+ using System.Net.Http;
+
using DotNetOpenAuth.Messaging;
/// <summary>
@@ -18,7 +20,7 @@ namespace DotNetOpenAuth.OAuth.Messages {
/// <summary>
/// A store for the binary data that is carried in the message.
/// </summary>
- private List<MultipartPostPart> binaryData = new List<MultipartPostPart>();
+ private Dictionary<string, HttpContent> binaryData = new Dictionary<string, HttpContent>();
/// <summary>
/// Initializes a new instance of the <see cref="AccessProtectedResourceRequest"/> class.
@@ -56,7 +58,7 @@ namespace DotNetOpenAuth.OAuth.Messages {
/// Gets the parts of the message that carry binary data.
/// </summary>
/// <value>A list of parts. Never null.</value>
- public IList<MultipartPostPart> BinaryData {
+ public IDictionary<string, HttpContent> BinaryData {
get { return this.binaryData; }
}
@@ -64,7 +66,7 @@ namespace DotNetOpenAuth.OAuth.Messages {
/// Gets a value indicating whether this message should be sent as multi-part POST.
/// </summary>
public bool SendAsMultipart {
- get { return this.HttpMethod == "POST" && this.BinaryData.Count > 0; }
+ get { return this.HttpMethod == HttpMethod.Post && this.BinaryData.Count > 0; }
}
#endregion
diff --git a/src/DotNetOpenAuth.OAuth/OAuth/Messages/SignedMessageBase.cs b/src/DotNetOpenAuth.OAuth/OAuth/Messages/SignedMessageBase.cs
index 6af75ec..7bc5b7d 100644
--- a/src/DotNetOpenAuth.OAuth/OAuth/Messages/SignedMessageBase.cs
+++ b/src/DotNetOpenAuth.OAuth/OAuth/Messages/SignedMessageBase.cs
@@ -8,6 +8,7 @@ namespace DotNetOpenAuth.OAuth.Messages {
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
+ using System.Net.Http;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
using DotNetOpenAuth.OAuth.ChannelElements;
@@ -75,7 +76,7 @@ namespace DotNetOpenAuth.OAuth.Messages {
/// <summary>
/// Gets or sets the HTTP method that will be used to transmit the message.
/// </summary>
- string ITamperResistantOAuthMessage.HttpMethod {
+ HttpMethod ITamperResistantOAuthMessage.HttpMethod {
get { return this.HttpMethod; }
set { this.HttpMethod = value; }
}
@@ -169,7 +170,7 @@ namespace DotNetOpenAuth.OAuth.Messages {
/// <summary>
/// Gets or sets the HTTP method that will be used to transmit the message.
/// </summary>
- protected string HttpMethod { get; set; }
+ protected HttpMethod HttpMethod { get; set; }
/// <summary>
/// Gets or sets the message signature.
diff --git a/src/DotNetOpenAuth.OAuth/packages.config b/src/DotNetOpenAuth.OAuth/packages.config
index 58890d8..1d93cf5 100644
--- a/src/DotNetOpenAuth.OAuth/packages.config
+++ b/src/DotNetOpenAuth.OAuth/packages.config
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
+ <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
<package id="Validation" version="2.0.1.12362" targetFramework="net45" />
</packages> \ No newline at end of file