summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-02-21 07:39:17 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-02-21 07:39:17 -0800
commit82a38e5b7875b2ef48b16206e8019a02f90fee9a (patch)
tree990f4226358a31495486ac8684092fa1fe703a84 /src
parent681fc4d8a1d27d45648116c383e8f13fd0d2c12d (diff)
downloadDotNetOpenAuth-82a38e5b7875b2ef48b16206e8019a02f90fee9a.zip
DotNetOpenAuth-82a38e5b7875b2ef48b16206e8019a02f90fee9a.tar.gz
DotNetOpenAuth-82a38e5b7875b2ef48b16206e8019a02f90fee9a.tar.bz2
Adds the OAuth 1 consumer PLAINTEXT signing message handler.
Diffstat (limited to 'src')
-rw-r--r--src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj1
-rw-r--r--src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs38
-rw-r--r--src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1PlainTextMessageHandler.cs59
3 files changed, 79 insertions, 19 deletions
diff --git a/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj b/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj
index 8c2cb18..922b860 100644
--- a/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj
+++ b/src/DotNetOpenAuth.OAuth.Consumer/DotNetOpenAuth.OAuth.Consumer.csproj
@@ -27,6 +27,7 @@
<Compile Include="OAuth\DesktopConsumer.cs" />
<Compile Include="OAuth\OAuth1HmacSha1HttpMessageHandler.cs" />
<Compile Include="OAuth\OAuth1HttpMessageHandlerBase.cs" />
+ <Compile Include="OAuth\OAuth1PlainTextMessageHandler.cs" />
<Compile Include="OAuth\OAuth1RsaSha1HttpMessageHandler.cs" />
<Compile Include="OAuth\WebConsumer.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
diff --git a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs
index 44706be..84db4be 100644
--- a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs
+++ b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs
@@ -183,6 +183,25 @@ namespace DotNetOpenAuth.OAuth {
protected abstract string SignatureMethod { get; }
/// <summary>
+ /// Gets the OAuth 1.0 signature to apply to the specified request.
+ /// </summary>
+ /// <param name="request">The outbound HTTP request.</param>
+ /// <param name="oauthParameters">The oauth parameters.</param>
+ /// <returns>
+ /// The value for the "oauth_signature" parameter.
+ /// </returns>
+ protected virtual string GetSignature(HttpRequestMessage request, NameValueCollection oauthParameters) {
+ Requires.NotNull(request, "request");
+ Requires.NotNull(oauthParameters, "oauthParameters");
+
+ string signatureBaseString = this.ConstructSignatureBaseString(request, oauthParameters);
+ byte[] signatureBaseStringBytes = Encoding.ASCII.GetBytes(signatureBaseString);
+ byte[] signatureBytes = this.Sign(signatureBaseStringBytes);
+ string signatureString = Convert.ToBase64String(signatureBytes);
+ return signatureString;
+ }
+
+ /// <summary>
/// Gets the "ConsumerSecret&amp;AccessTokenSecret" string, allowing either property to be empty or null.
/// </summary>
/// <returns>The concatenated string.</returns>
@@ -334,24 +353,5 @@ namespace DotNetOpenAuth.OAuth {
return normalizedParameterString.ToString();
}
-
- /// <summary>
- /// Gets the OAuth 1.0 signature to apply to the specified request.
- /// </summary>
- /// <param name="request">The outbound HTTP request.</param>
- /// <param name="oauthParameters">The oauth parameters.</param>
- /// <returns>
- /// The value for the "oauth_signature" parameter.
- /// </returns>
- private string GetSignature(HttpRequestMessage request, NameValueCollection oauthParameters) {
- Requires.NotNull(request, "request");
- Requires.NotNull(oauthParameters, "oauthParameters");
-
- string signatureBaseString = this.ConstructSignatureBaseString(request, oauthParameters);
- byte[] signatureBaseStringBytes = Encoding.ASCII.GetBytes(signatureBaseString);
- byte[] signatureBytes = this.Sign(signatureBaseStringBytes);
- string signatureString = Convert.ToBase64String(signatureBytes);
- return signatureString;
- }
}
}
diff --git a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1PlainTextMessageHandler.cs b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1PlainTextMessageHandler.cs
new file mode 100644
index 0000000..3cf14cd
--- /dev/null
+++ b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1PlainTextMessageHandler.cs
@@ -0,0 +1,59 @@
+//-----------------------------------------------------------------------
+// <copyright file="OAuth1PlainTextMessageHandler.cs" company="Andrew Arnott">
+// Copyright (c) Andrew Arnott. All rights reserved.
+// </copyright>
+//-----------------------------------------------------------------------
+
+namespace DotNetOpenAuth.OAuth {
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.Specialized;
+ using System.Linq;
+ using System.Text;
+ using System.Threading.Tasks;
+ using DotNetOpenAuth.Messaging;
+
+ /// <summary>
+ /// A delegating HTTP handler that signs outgoing HTTP requests
+ /// with the PLAINTEXT signature.
+ /// </summary>
+ public class OAuth1PlainTextMessageHandler : OAuth1HttpMessageHandlerBase {
+ /// <summary>
+ /// Calculates the signature for the specified buffer.
+ /// </summary>
+ /// <param name="signedPayload">The payload to calculate the signature for.</param>
+ /// <returns>
+ /// The signature.
+ /// </returns>
+ /// <exception cref="System.NotImplementedException"></exception>
+ protected override byte[] Sign(byte[] signedPayload) {
+ throw new NotImplementedException();
+ }
+
+ /// <summary>
+ /// Gets the OAuth 1.0 signature to apply to the specified request.
+ /// </summary>
+ /// <param name="request">The outbound HTTP request.</param>
+ /// <param name="oauthParameters">The oauth parameters.</param>
+ /// <returns>
+ /// The value for the "oauth_signature" parameter.
+ /// </returns>
+ protected override string GetSignature(System.Net.Http.HttpRequestMessage request, NameValueCollection oauthParameters) {
+ var builder = new StringBuilder();
+ builder.Append(MessagingUtilities.EscapeUriDataStringRfc3986(this.ConsumerSecret));
+ builder.Append("&");
+ builder.Append(MessagingUtilities.EscapeUriDataStringRfc3986(this.AccessTokenSecret));
+ return builder.ToString();
+ }
+
+ /// <summary>
+ /// Gets the signature method to include in the oauth_signature_method parameter.
+ /// </summary>
+ /// <value>
+ /// The signature method.
+ /// </value>
+ protected override string SignatureMethod {
+ get { return "PLAINTEXT"; }
+ }
+ }
+}