protected virtual void DoGetRequestToken() { // Fire the OnBeforeGetRequestToken event PreRequestEventArgs args = new PreRequestEventArgs( this.Service.RequestTokenUrl, this.Service.RequestTokenEndPoint.HttpMethod, this.CallbackUrl, new NameValueCollection()); if (this.OnBeforeGetRequestToken != null) { this.OnBeforeGetRequestToken(this, args); } OAuthParameters authParams = this.CreateOAuthParameters(args.AdditionalParameters); authParams.Callback = args.CallbackUrl == null ? Constants.OAuthOutOfBandCallback : args.CallbackUrl.AbsoluteUri; this.SignParameters(args.RequestUri, args.HttpMethod, authParams, null); // Create and sign the request HttpWebRequest request = this.CreateRequest( args.RequestUri, authParams, args.HttpMethod, args.HttpMethod == "POST" ? Constants.HttpPostUrlEncodedContentType : String.Empty, null); HttpWebResponse response = null; OAuthParameters responseParameters = null; // Get the service provider response try { response = (HttpWebResponse)request.GetResponse(); // Parse the parameters and re-throw any OAuthRequestException from the service provider responseParameters = OAuthParameters.Parse(response); OAuthRequestException.TryRethrow(responseParameters); } catch (WebException e) { // Parse the parameters and re-throw any OAuthRequestException from the service provider responseParameters = OAuthParameters.Parse(e.Response as HttpWebResponse); OAuthRequestException.TryRethrow(responseParameters); // If no OAuthRequestException, rethrow the WebException throw; } // Store the request token this.RequestToken = new OAuthToken( TokenType.Request, responseParameters.Token, responseParameters.TokenSecret, this.Service.Consumer); // Fire the OnReceiveRequestToken event RequestTokenReceivedEventArgs responseArgs = new RequestTokenReceivedEventArgs( this.RequestToken, responseParameters.AdditionalParameters); if (this.OnReceiveRequestToken != null) { this.OnReceiveRequestToken(this, responseArgs); } }
protected virtual void DoGetRequestToken() { // Fire the OnBeforeGetRequestToken event PreRequestEventArgs args = new PreRequestEventArgs( this.Service.RequestTokenUrl, this.Service.RequestTokenEndPoint.HttpMethod, this.CallbackUrl, new NameValueCollection()); if (this.OnBeforeGetRequestToken != null) this.OnBeforeGetRequestToken(this, args); OAuthParameters authParams = this.CreateOAuthParameters(args.AdditionalParameters); authParams.Callback = args.CallbackUrl == null ? Constants.OAuthOutOfBandCallback : args.CallbackUrl.AbsoluteUri; this.SignParameters(args.RequestUri, args.HttpMethod, authParams, null); // Create and sign the request HttpWebRequest request = this.CreateRequest( args.RequestUri, authParams, args.HttpMethod, args.HttpMethod == "POST" ? Constants.HttpPostUrlEncodedContentType : String.Empty, null); HttpWebResponse response = null; OAuthParameters responseParameters = null; // Get the service provider response try { response = (HttpWebResponse)request.GetResponse(); // Parse the parameters and re-throw any OAuthRequestException from the service provider responseParameters = OAuthParameters.Parse(response); OAuthRequestException.TryRethrow(responseParameters); } catch (WebException e) { // Parse the parameters and re-throw any OAuthRequestException from the service provider responseParameters = OAuthParameters.Parse(e.Response as HttpWebResponse); OAuthRequestException.TryRethrow(responseParameters); // If no OAuthRequestException, rethrow the WebException throw; } // Store the request token this.RequestToken = new OAuthToken( TokenType.Request, responseParameters.Token, responseParameters.TokenSecret, this.Service.Consumer); // Fire the OnReceiveRequestToken event RequestTokenReceivedEventArgs responseArgs = new RequestTokenReceivedEventArgs( this.RequestToken, responseParameters.AdditionalParameters); if (this.OnReceiveRequestToken != null) this.OnReceiveRequestToken(this, responseArgs); }