summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2013-03-26 11:19:06 -0700
commit3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb (patch)
treec15816c3d7f6e74334553f2ff98605ce1c22c538 /src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs
parent5e9014f36b2d53b8e419918675df636540ea24e2 (diff)
parente6f7409f4caceb7bc2a5b4ddbcb1a4097af340f2 (diff)
downloadDotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.zip
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.gz
DotNetOpenAuth-3d37ff45cab6838d80b22e6b782a0b9b4c2f4aeb.tar.bz2
Move to HttpClient throughout library.
Diffstat (limited to 'src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs')
-rw-r--r--src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs92
1 files changed, 43 insertions, 49 deletions
diff --git a/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs b/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs
index e216906..1b6318f 100644
--- a/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs
+++ b/src/DotNetOpenAuth.AspNet/Clients/OAuth/DotNetOpenAuthWebConsumer.cs
@@ -8,6 +8,10 @@ namespace DotNetOpenAuth.AspNet.Clients {
using System;
using System.Collections.Generic;
using System.Net;
+ using System.Net.Http;
+ using System.Threading;
+ using System.Threading.Tasks;
+ using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
@@ -17,13 +21,13 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// <summary>
/// The dot net open auth web consumer.
/// </summary>
- public class DotNetOpenAuthWebConsumer : IOAuthWebWorker, IDisposable {
+ public class DotNetOpenAuthWebConsumer : IOAuthWebWorker {
#region Constants and Fields
/// <summary>
/// The _web consumer.
/// </summary>
- private readonly WebConsumer webConsumer;
+ private readonly Consumer webConsumer;
#endregion
@@ -38,75 +42,65 @@ namespace DotNetOpenAuth.AspNet.Clients {
/// <param name="tokenManager">
/// The token manager.
/// </param>
- public DotNetOpenAuthWebConsumer(ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager) {
+ public DotNetOpenAuthWebConsumer(ServiceProviderDescription serviceDescription, string consumerKey, string consumerSecret) {
Requires.NotNull(serviceDescription, "serviceDescription");
- Requires.NotNull(tokenManager, "tokenManager");
- this.webConsumer = new WebConsumer(serviceDescription, tokenManager);
+ this.webConsumer = new Consumer {
+ ServiceProvider = serviceDescription,
+ ConsumerKey = consumerKey,
+ ConsumerSecret = consumerSecret,
+ TemporaryCredentialStorage = new CookieTemporaryCredentialStorage(),
+ };
}
#endregion
- #region Public Methods and Operators
-
/// <summary>
- /// The prepare authorized request.
+ /// Gets the DotNetOpenAuth <see cref="WebConsumer"/> instance that can be used to make OAuth 1.0 authorized HTTP requests.
/// </summary>
- /// <param name="profileEndpoint">
- /// The profile endpoint.
- /// </param>
- /// <param name="accessToken">
- /// The access token.
- /// </param>
- /// <returns>An HTTP request.</returns>
- public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint profileEndpoint, string accessToken) {
- return this.webConsumer.PrepareAuthorizedRequest(profileEndpoint, accessToken);
+ public Consumer Consumer {
+ get { return this.webConsumer; }
}
+ #region Public Methods and Operators
+
/// <summary>
- /// The process user authorization.
+ /// Creates an HTTP message handler that authorizes outgoing web requests.
/// </summary>
- /// <returns>The response message.</returns>
- public AuthorizedTokenResponse ProcessUserAuthorization() {
- return this.webConsumer.ProcessUserAuthorization();
+ /// <param name="accessToken">The access token.</param>
+ public HttpMessageHandler CreateMessageHandler(AccessToken accessToken) {
+ Requires.NotNullOrEmpty(accessToken.Token, "accessToken");
+
+ return this.Consumer.CreateMessageHandler(accessToken);
}
/// <summary>
- /// The request authentication.
+ /// The process user authorization.
/// </summary>
- /// <param name="callback">
- /// The callback.
- /// </param>
- public void RequestAuthentication(Uri callback) {
- var redirectParameters = new Dictionary<string, string>();
- UserAuthorizationRequest request = this.webConsumer.PrepareRequestUserAuthorization(
- callback, null, redirectParameters);
- this.webConsumer.Channel.PrepareResponse(request).Send();
- }
-
- #endregion
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The response message.
+ /// </returns>
+ public Task<AccessTokenResponse> ProcessUserAuthorizationAsync(HttpContextBase context = null, CancellationToken cancellationToken = default(CancellationToken)) {
+ if (context == null) {
+ context = new HttpContextWrapper(HttpContext.Current);
+ }
- #region IDisposable members
+ return this.webConsumer.ProcessUserAuthorizationAsync(context.Request.Url, cancellationToken: cancellationToken);
+ }
/// <summary>
- /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ /// The request authentication.
/// </summary>
- /// <filterpriority>2</filterpriority>
- public void Dispose() {
- this.Dispose(true);
- GC.SuppressFinalize(this);
+ /// <param name="callback">The callback.</param>
+ /// <param name="cancellationToken">The cancellation token.</param>
+ /// <returns>
+ /// The response message.
+ /// </returns>
+ public Task<Uri> RequestAuthenticationAsync(Uri callback, CancellationToken cancellationToken = default(CancellationToken)) {
+ return this.webConsumer.RequestUserAuthorizationAsync(callback, cancellationToken: cancellationToken);
}
#endregion
-
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void Dispose(bool disposing) {
- if (disposing) {
- this.webConsumer.Dispose();
- }
- }
}
}