//----------------------------------------------------------------------- // // Copyright (c) Microsoft. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.AspNet.Clients { using System; using System.Collections.Generic; using System.Net; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth; using DotNetOpenAuth.OAuth.ChannelElements; using DotNetOpenAuth.OAuth.Messages; /// /// The dot net open auth web consumer. /// public class DotNetOpenAuthWebConsumer : IOAuthWebWorker, IDisposable { #region Constants and Fields /// /// The _web consumer. /// private readonly WebConsumer _webConsumer; #endregion #region Constructors and Destructors /// /// Initializes a new instance of the class. /// /// /// The service description. /// /// /// The token manager. /// /// /// /// /// public DotNetOpenAuthWebConsumer(ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager) { Requires.NotNull(serviceDescription, "serviceDescription"); Requires.NotNull(tokenManager, "tokenManager"); this._webConsumer = new WebConsumer(serviceDescription, tokenManager); } #endregion #region Public Methods and Operators /// /// The prepare authorized request. /// /// /// The profile endpoint. /// /// /// The access token. /// /// /// public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint profileEndpoint, string accessToken) { return this._webConsumer.PrepareAuthorizedRequest(profileEndpoint, accessToken); } /// /// The process user authorization. /// /// /// public AuthorizedTokenResponse ProcessUserAuthorization() { return this._webConsumer.ProcessUserAuthorization(); } /// /// The request authentication. /// /// /// The callback. /// public void RequestAuthentication(Uri callback) { var redirectParameters = new Dictionary { { "force_login", "false" } }; UserAuthorizationRequest request = this._webConsumer.PrepareRequestUserAuthorization( callback, null, redirectParameters); this._webConsumer.Channel.PrepareResponse(request).Send(); } #endregion #region IDisposable members /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// /// 2 public void Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } #endregion /// /// Releases unmanaged and - optionally - managed resources /// /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool disposing) { if (disposing) { this._webConsumer.Dispose(); } } } }