summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-02-23 21:42:36 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-02-23 21:42:36 -0800
commit06a2c8d400126e160b1f9218ea766d1f453175bd (patch)
tree6201fd3ca5fc4face620c6dc846094f0a398a335 /src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs
parente555d8a7660c90fe07f521bcaf9d6ea06453ae13 (diff)
downloadDotNetOpenAuth-06a2c8d400126e160b1f9218ea766d1f453175bd.zip
DotNetOpenAuth-06a2c8d400126e160b1f9218ea766d1f453175bd.tar.gz
DotNetOpenAuth-06a2c8d400126e160b1f9218ea766d1f453175bd.tar.bz2
Adds DelegatingHandler implementations for OAuth 1 consumers that sign outgoing requests.
Diffstat (limited to 'src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs')
-rw-r--r--src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs
index 10f2c54..a2b9e7e 100644
--- a/src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs
+++ b/src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs
@@ -11,6 +11,9 @@ namespace DotNetOpenAuth.OAuth {
using System.Diagnostics.Contracts;
using System.Linq;
using System.Net;
+#if CLR4
+ using System.Net.Http;
+#endif
using DotNetOpenAuth.Configuration;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.Messaging.Bindings;
@@ -103,6 +106,27 @@ namespace DotNetOpenAuth.OAuth {
return grantAccess.AccessToken;
}
+#if CLR4
+
+ /// <summary>
+ /// Creates an HTTP handler that automatically applies an OAuth 1 access token and signature to outbound HTTP requests.
+ /// The result of this method can be supplied to the <see cref="HttpClient(HttpMessageHandler)"/> constructor.
+ /// </summary>
+ /// <param name="accessToken">The access token to use to authorize each outbound HTTP message.</param>
+ /// <param name="innerHandler">The inner HTTP handler to use. The default uses <see cref="HttpClientHandler"/> as the inner handler.</param>
+ /// <returns>An <see cref="HttpMessageHandler"/> instance.</returns>
+ public DelegatingHandler CreateAuthorizingHandler(string accessToken, HttpMessageHandler innerHandler = null) {
+ Requires.NotNullOrEmpty(accessToken, "accessToken");
+ return new OAuth1HmacSha1HttpMessageHandler(innerHandler ?? new HttpClientHandler()) {
+ ConsumerKey = this.TokenManager.ConsumerKey,
+ ConsumerSecret = this.TokenManager.ConsumerSecret,
+ AccessToken = accessToken,
+ AccessTokenSecret = this.TokenManager.GetTokenSecret(accessToken),
+ };
+ }
+
+#endif
+
/// <summary>
/// Creates a web request prepared with OAuth authorization
/// that may be further tailored by adding parameters by the caller.