//----------------------------------------------------------------------- // // 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 { #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) { if (serviceDescription == null) { throw new ArgumentNullException("consumer"); } if (tokenManager == null) { throw new ArgumentNullException("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 } }