//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.OAuth { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OAuth; using DotNetOpenAuth.OAuth.ChannelElements; using DotNetOpenAuth.OAuth.Messages; /// /// Used by a desktop application to use OAuth to access the Service Provider on behalf of the User. /// /// /// The methods on this class are thread-safe. Provided the properties are set and not changed /// afterward, a single instance of this class may be used by an entire desktop application safely. /// public class DesktopConsumer : ConsumerBase { /// /// Initializes a new instance of the class. /// /// The endpoints and behavior of the Service Provider. /// The host's method of storing and recalling tokens and secrets. public DesktopConsumer(ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager) : base(serviceDescription, tokenManager) { } /// /// Begins an OAuth authorization request. /// /// Extra parameters to add to the request token message. Optional. /// Extra parameters to add to the redirect to Service Provider message. Optional. /// The request token that must be exchanged for an access token after the user has provided authorization. /// The URL to open a browser window to allow the user to provide authorization. [SuppressMessage("Microsoft.Design", "CA1021:AvoidOutParameters", MessageId = "2#", Justification = "Two results")] public Uri RequestUserAuthorization(IDictionary requestParameters, IDictionary redirectParameters, out string requestToken) { var message = this.PrepareRequestUserAuthorization(null, requestParameters, redirectParameters, out requestToken); OutgoingWebResponse response = this.Channel.PrepareResponse(message); return response.GetDirectUriRequest(this.Channel); } /// /// Exchanges a given request token for access token. /// /// The request token that the user has authorized. /// The access token assigned by the Service Provider. [Obsolete("Use the ProcessUserAuthorization method that takes a verifier parameter instead.")] public AuthorizedTokenResponse ProcessUserAuthorization(string requestToken) { return this.ProcessUserAuthorization(requestToken, null); } /// /// Exchanges a given request token for access token. /// /// The request token that the user has authorized. /// The verifier code typed in by the user. Must not be Null for OAuth 1.0a service providers and later. /// /// The access token assigned by the Service Provider. /// public new AuthorizedTokenResponse ProcessUserAuthorization(string requestToken, string verifier) { if (this.ServiceProvider.Version >= Protocol.V10a.Version) { ErrorUtilities.VerifyNonZeroLength(verifier, "verifier"); } return base.ProcessUserAuthorization(requestToken, verifier); } } }