//-----------------------------------------------------------------------
//
// 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.
///
/// An HTTP request.
public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint profileEndpoint, string accessToken) {
return this.webConsumer.PrepareAuthorizedRequest(profileEndpoint, accessToken);
}
///
/// The process user authorization.
///
/// The response message.
public AuthorizedTokenResponse ProcessUserAuthorization() {
return this.webConsumer.ProcessUserAuthorization();
}
///
/// The request authentication.
///
///
/// The callback.
///
public void RequestAuthentication(Uri callback) {
var redirectParameters = new Dictionary();
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();
}
}
}
}