diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2013-02-18 22:08:07 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2013-02-18 22:08:07 -0800 |
commit | 32270c7413e7a2c37a02341a0894e2447f6d74f7 (patch) | |
tree | 05f6cf8566c7b4a2661a01d08967e91f05778837 /src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs | |
parent | 549017cdf590ea4ce4d8ad55c013c33a506133a3 (diff) | |
download | DotNetOpenAuth-32270c7413e7a2c37a02341a0894e2447f6d74f7.zip DotNetOpenAuth-32270c7413e7a2c37a02341a0894e2447f6d74f7.tar.gz DotNetOpenAuth-32270c7413e7a2c37a02341a0894e2447f6d74f7.tar.bz2 |
Matured the OAuth 1 consumer signing handler a bit.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs')
-rw-r--r-- | src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs new file mode 100644 index 0000000..11de257 --- /dev/null +++ b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs @@ -0,0 +1,59 @@ +//----------------------------------------------------------------------- +// <copyright file="OAuth1HmacSha1HttpMessageHandler.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.OAuth { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net.Http; + using System.Security.Cryptography; + using System.Text; + using System.Threading.Tasks; + + /// <summary> + /// A delegating HTTP handler that signs outgoing HTTP requests + /// with an HMAC-SHA1 signature. + /// </summary> + public class OAuth1HmacSha1HttpMessageHandler : OAuth1HttpMessageHandlerBase { + /// <summary> + /// Initializes a new instance of the <see cref="OAuth1HmacSha1HttpMessageHandler"/> class. + /// </summary> + public OAuth1HmacSha1HttpMessageHandler() { + } + + /// <summary> + /// Initializes a new instance of the <see cref="OAuth1HmacSha1HttpMessageHandler"/> class. + /// </summary> + /// <param name="innerHandler">The inner handler which is responsible for processing the HTTP response messages.</param> + public OAuth1HmacSha1HttpMessageHandler(HttpMessageHandler innerHandler) + : base(innerHandler) { + } + + /// <summary> + /// Calculates the signature for the specified buffer. + /// </summary> + /// <param name="signedPayload">The payload to calculate the signature for.</param> + /// <returns> + /// The signature. + /// </returns> + protected override byte[] Sign(byte[] signedPayload) { + using (var algorithm = HMACSHA1.Create()) { + algorithm.Key = Encoding.ASCII.GetBytes(this.GetConsumerAndTokenSecretString()); + return algorithm.ComputeHash(signedPayload); + } + } + + /// <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 "HMAC-SHA1"; } + } + } +} |