diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-05-01 09:32:41 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-05-01 09:32:41 -0700 |
commit | 19c0c6e59f7238969107e674824ad8d4b616800f (patch) | |
tree | 8780e7c351a8d5ae406b0aa5f1c13685cd8b852e /src | |
parent | 5c937f16690ad0ac6cefd0d84f64461b68b79921 (diff) | |
download | DotNetOpenAuth-19c0c6e59f7238969107e674824ad8d4b616800f.zip DotNetOpenAuth-19c0c6e59f7238969107e674824ad8d4b616800f.tar.gz DotNetOpenAuth-19c0c6e59f7238969107e674824ad8d4b616800f.tar.bz2 |
Simplified two calls into one call to send an OAuth-authorized request with extra data.v3.0.2.9122
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/OAuth/ConsumerBase.cs | 70 |
1 files changed, 49 insertions, 21 deletions
diff --git a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs index 5395a6a..2c15a89 100644 --- a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs +++ b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs @@ -73,7 +73,35 @@ namespace DotNetOpenAuth.OAuth { /// <param name="accessToken">The access token that permits access to the protected resource.</param> /// <returns>The initialized WebRequest object.</returns> public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint endpoint, string accessToken) { + Contract.Requires(endpoint != null); + Contract.Requires(!String.IsNullOrEmpty(accessToken)); + ErrorUtilities.VerifyArgumentNotNull(endpoint, "endpoint"); + ErrorUtilities.VerifyNonZeroLength(accessToken, "accessToken"); + + return PrepareAuthorizedRequest(endpoint, accessToken, EmptyDictionary<string, string>.Instance); + } + + /// <summary> + /// Creates a web request prepared with OAuth authorization + /// that may be further tailored by adding parameters by the caller. + /// </summary> + /// <param name="endpoint">The URL and method on the Service Provider to send the request to.</param> + /// <param name="accessToken">The access token that permits access to the protected resource.</param> + /// <param name="extraData">Extra parameters to include in the message. Must not be null, but may be empty.</param> + /// <returns>The initialized WebRequest object.</returns> + public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint endpoint, string accessToken, IDictionary<string, string> extraData) { + Contract.Requires(endpoint != null); + Contract.Requires(!String.IsNullOrEmpty(accessToken)); + Contract.Requires(extraData != null); + ErrorUtilities.VerifyArgumentNotNull(endpoint, "endpoint"); + ErrorUtilities.VerifyNonZeroLength(accessToken, "accessToken"); + ErrorUtilities.VerifyArgumentNotNull(extraData, "extraData"); + IDirectedProtocolMessage message = this.CreateAuthorizingMessage(endpoint, accessToken); + foreach (var pair in extraData) { + message.ExtraData.Add(pair); + } + HttpWebRequest wr = this.OAuthChannel.InitializeRequest(message); return wr; } @@ -106,27 +134,6 @@ namespace DotNetOpenAuth.OAuth { /// <param name="endpoint">The URL and method on the Service Provider to send the request to.</param> /// <param name="accessToken">The access token that permits access to the protected resource.</param> /// <returns>The initialized WebRequest object.</returns> - public AccessProtectedResourceRequest CreateAuthorizingMessage(MessageReceivingEndpoint endpoint, string accessToken) { - Contract.Requires(endpoint != null); - Contract.Requires(!String.IsNullOrEmpty(accessToken)); - ErrorUtilities.VerifyArgumentNotNull(endpoint, "endpoint"); - ErrorUtilities.VerifyNonZeroLength(accessToken, "accessToken"); - - AccessProtectedResourceRequest message = new AccessProtectedResourceRequest(endpoint) { - AccessToken = accessToken, - ConsumerKey = this.ConsumerKey, - }; - - return message; - } - - /// <summary> - /// Creates a web request prepared with OAuth authorization - /// that may be further tailored by adding parameters by the caller. - /// </summary> - /// <param name="endpoint">The URL and method on the Service Provider to send the request to.</param> - /// <param name="accessToken">The access token that permits access to the protected resource.</param> - /// <returns>The initialized WebRequest object.</returns> /// <exception cref="WebException">Thrown if the request fails for any reason after it is sent to the Service Provider.</exception> public IncomingWebResponse PrepareAuthorizedRequestAndSend(MessageReceivingEndpoint endpoint, string accessToken) { IDirectedProtocolMessage message = this.CreateAuthorizingMessage(endpoint, accessToken); @@ -147,6 +154,27 @@ namespace DotNetOpenAuth.OAuth { #endregion /// <summary> + /// Creates a web request prepared with OAuth authorization + /// that may be further tailored by adding parameters by the caller. + /// </summary> + /// <param name="endpoint">The URL and method on the Service Provider to send the request to.</param> + /// <param name="accessToken">The access token that permits access to the protected resource.</param> + /// <returns>The initialized WebRequest object.</returns> + protected internal AccessProtectedResourceRequest CreateAuthorizingMessage(MessageReceivingEndpoint endpoint, string accessToken) { + Contract.Requires(endpoint != null); + Contract.Requires(!String.IsNullOrEmpty(accessToken)); + ErrorUtilities.VerifyArgumentNotNull(endpoint, "endpoint"); + ErrorUtilities.VerifyNonZeroLength(accessToken, "accessToken"); + + AccessProtectedResourceRequest message = new AccessProtectedResourceRequest(endpoint) { + AccessToken = accessToken, + ConsumerKey = this.ConsumerKey, + }; + + return message; + } + + /// <summary> /// Prepares an OAuth message that begins an authorization request that will /// redirect the user to the Service Provider to provide that authorization. /// </summary> |