private void DoGetRequestToken() { // Fire the OnBeforeGetRequestToken event PreRequestEventArgs args = new PreRequestEventArgs(Service.RequestTokenUrl, Service.RequestTokenEndPoint.HttpMethod, CallbackUrl); if (BeforeGetRequestToken != null) { BeforeGetRequestToken(this, args); } OAuthParameters authParams = CreateOAuthParameters(args.AdditionalParameters); authParams.Callback = args.CallbackUrl == null ? OAuthOutOfBandCallback : args.CallbackUrl.AbsoluteUri; SignParameters(args.RequestUri, args.HttpMethod, authParams, null); // Create and sign the request HttpWebRequest request = CreateRequest( args.RequestUri, authParams, args.HttpMethod, args.HttpMethod == "POST" ? HttpPostUrlEncodedContentType : String.Empty, null); OAuthParameters responseParameters; // Get the service provider response try { HttpWebResponse 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 RequestToken = new OAuthToken(TokenType.Request, responseParameters.Token, responseParameters.TokenSecret, Service.Consumer); // Fire the OnReceiveRequestToken event RequestTokenReceivedEventArgs responseArgs = new RequestTokenReceivedEventArgs(RequestToken); responseArgs.Parameters.Add(responseParameters.AdditionalParameters); if (ReceiveRequestToken != null) { ReceiveRequestToken(this, responseArgs); } }
private void DoGetRequestToken() { // Fire the OnBeforeGetRequestToken event PreRequestEventArgs args = new PreRequestEventArgs(Service.RequestTokenUrl, Service.RequestTokenEndPoint.HttpMethod, CallbackUrl); if (BeforeGetRequestToken != null) BeforeGetRequestToken(this, args); OAuthParameters authParams = CreateOAuthParameters(args.AdditionalParameters); authParams.Callback = args.CallbackUrl == null ? OAuthOutOfBandCallback : args.CallbackUrl.AbsoluteUri; SignParameters(args.RequestUri, args.HttpMethod, authParams, null); // Create and sign the request HttpWebRequest request = CreateRequest( args.RequestUri, authParams, args.HttpMethod, args.HttpMethod == "POST" ? HttpPostUrlEncodedContentType : String.Empty, null); OAuthParameters responseParameters; // Get the service provider response try { HttpWebResponse 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 RequestToken = new OAuthToken(TokenType.Request, responseParameters.Token, responseParameters.TokenSecret, Service.Consumer); // Fire the OnReceiveRequestToken event RequestTokenReceivedEventArgs responseArgs = new RequestTokenReceivedEventArgs(RequestToken); responseArgs.Parameters.Add(responseParameters.AdditionalParameters); if (ReceiveRequestToken != null) ReceiveRequestToken(this, responseArgs); }