/// <summary> /// Gets the access token from the remote server. /// </summary> protected override void GetAccessToken() { base.GetAccessToken(); var parameters = new NameValueCollection { { "client_id", this.ApplicationId }, { "client_secret", this.ApplicationSecret }, { "grant_type", "authorization_code" }, { "code", this.AuthorizationCode } }; if (!String.IsNullOrEmpty(this.ReturnUrl)) { parameters.Add("redirect_uri", this.ReturnUrl); } var result = OAuthUtility.ExecuteRequest ( "POST", this.AccessTokenUrl, parameters, null ); if (result.ContainsKey("error")) { this.AccessToken = new ErrorResult(result); } else { this.AccessToken = new OAuth2AccessToken(result); } }
/// <summary> /// Gets the access token from the remote server. /// </summary> protected override void GetAccessToken() { base.GetAccessToken(); this.Authorization.Parameters.Remove("oauth_signature"); this.Authorization["oauth_nonce"] = OAuthUtility.GetRandomKey(); this.Authorization["oauth_timestamp"] = OAuthUtility.GetTimeStamp(); this.Authorization["oauth_verifier"] = this.AuthorizationCode; this.Authorization["oauth_token"] = this.RequestToken.OAuthToken; this.Authorization.SetSignature ( "POST", new Uri(this.AccessTokenUrl), this.ApplicationSecret, this.Authorization["oauth_token"].ToString(), null ); base.AccessToken = new OAuthAccessToken ( OAuthUtility.ExecuteRequest ( "POST", this.AccessTokenUrl, null, this.Authorization.ToString() ) ); this.Authorization.Parameters.Remove("oauth_verifier"); }
/// <summary> /// Gets the request token from the remote server. /// </summary> public void GetRequestToken() { this.UpdateStamp(); if (!String.IsNullOrEmpty(this.ReturnUrl)) { this.Authorization["oauth_callback"] = String.Format ( "{0}{1}state={2}", this.ReturnUrl, (this.ReturnUrl.Contains("?") ? "&" : "?"), this.State ); } else { this.Authorization.Parameters.Remove("oauth_callback"); } this.Authorization.SetSignature("POST", new Uri(this.RequestTokenUrl), this.ApplicationSecret, "", null); //this.Authorization["oauth_signature"] = this.GetSignature("POST", new Uri(this.RequestTokenUrl), "", null); _RequestToken = new OAuthRequestToken ( OAuthUtility.ExecuteRequest ( "POST", this.RequestTokenUrl, null, this.Authorization.ToString() ), this.AuthorizeUrl, this.Parameters ); }
/// <summary> /// Performs an async request. /// </summary> /// <param name="method">HTTP Method: <b>POST</b> (default), <b>PUT</b>, <b>GET</b> or <b>DELETE</b>.</param> /// <param name="endpoint">URL to which will be sent to request.</param> /// <param name="parameters">Parameters to be passed to request.</param> /// <param name="authorization">Authorization header value.</param> /// <param name="headers">HTTP headers for request.</param> /// <param name="contentType">The value of the <b>Content-Type</b> HTTP header.</param> /// <param name="callback">A delegate that, if provided, is called when an async web request is completed.</param> /// <param name="accessToken">Access token to be used in the request.</param> /// <remarks> /// <para>Can not be used simultaneously <paramref name="accessToken"/> and <paramref name="authorization"/>. Use only one of these parameters.</para> /// </remarks> /// <returns>Returns an instance of the <see cref="RequestResult"/> class, which contains the result of the request.</returns> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="RequestException"></exception> /// <exception cref="ArgumentException"> /// <para>The exception occurs when the query parameters are specified at the same time <paramref name="authorization"/> and <paramref name="accessToken"/>.</para> /// </exception> public static void ExecuteRequestAsync(string method = "POST", string endpoint = null, HttpParameterCollection parameters = null, HttpAuthorization authorization = null, NameValueCollection headers = null, string contentType = null, AccessToken accessToken = null, ExecuteRequestAsyncCallback callback = null) { var t = new Thread (() => { RequestResult result = null; try { result = OAuthUtility.ExecuteRequest(method, endpoint, parameters, authorization, headers, contentType, accessToken); } catch (RequestException ex) { result = ex.RequestResult; } if (callback != null) { callback(result); } } ); t.IsBackground = true; t.Start(); }
/// <summary> /// Performs a request using a <b>DELETE</b> method. /// </summary> /// <param name="endpoint">URL to which will be sent to the request.</param> /// <param name="parameters">Parameters to be passed to the request.</param> /// <param name="authorization">Authorization header value.</param> /// <param name="headers">HTTP headers for the request.</param> /// <param name="accessToken">Access token to be used in the request.</param> /// <returns>Returns an instance of the <see cref="RequestResult"/> class, which contains the result of the request.</returns> /// <remarks> /// <para>Can not be used simultaneously <paramref name="accessToken"/> and <paramref name="authorization"/>. Use only one of these parameters.</para> /// </remarks> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="RequestException"></exception> /// <exception cref="ArgumentException"> /// <para>The exception occurs when the query parameters are specified at the same time <paramref name="authorization"/> and <paramref name="accessToken"/>.</para> /// </exception> public static RequestResult Delete(string endpoint = null, HttpParameterCollection parameters = null, HttpAuthorization authorization = null, NameValueCollection headers = null, AccessToken accessToken = null) { return(OAuthUtility.ExecuteRequest("DELETE", endpoint, parameters, authorization, headers, null, accessToken)); }
/// <summary> /// Performs a request using a <b>PUT</b> method. /// </summary> /// <param name="endpoint">URL to which will be sent to the request.</param> /// <param name="parameters">Parameters to be passed to the request.</param> /// <param name="authorization">Authorization header value.</param> /// <param name="headers">HTTP headers for the request.</param> /// <param name="contentType">The value of the <b>Content-Type</b> HTTP header.</param> /// <param name="accessToken">Access token to be used in the request.</param> /// <remarks> /// <para>Can not be used simultaneously <paramref name="accessToken"/> and <paramref name="authorization"/>. Use only one of these parameters.</para> /// </remarks> /// <returns>Returns an instance of the <see cref="RequestResult"/> class, which contains the result of the request.</returns> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="RequestException"></exception> /// <exception cref="ArgumentException"> /// <para>The exception occurs when the query parameters are specified at the same time <paramref name="authorization"/> and <paramref name="accessToken"/>.</para> /// </exception> public static RequestResult Put(string endpoint = null, HttpParameterCollection parameters = null, HttpAuthorization authorization = null, NameValueCollection headers = null, string contentType = null, AccessToken accessToken = null) { return(OAuthUtility.ExecuteRequest("PUT", endpoint, parameters, authorization, headers, contentType, accessToken)); }