diff options
-rw-r--r-- | samples/OAuthConsumerWpf/MainWindow.xaml.cs | 17 | ||||
-rw-r--r-- | src/DotNetOpenAuth/Messaging/MessagingUtilities.cs | 16 |
2 files changed, 30 insertions, 3 deletions
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml.cs b/samples/OAuthConsumerWpf/MainWindow.xaml.cs index 45f2f6c..d84637e 100644 --- a/samples/OAuthConsumerWpf/MainWindow.xaml.cs +++ b/samples/OAuthConsumerWpf/MainWindow.xaml.cs @@ -210,10 +210,17 @@ authorizePopup.Owner = this; bool? result = authorizePopup.ShowDialog(); if (result.HasValue && result.Value) { - var request = (HttpWebRequest)WebRequest.Create(oauth2ResourceUrlBox.Text); - client.AuthorizeRequest(request, authorization); + var requestUri = new UriBuilder(oauth2ResourceUrlBox.Text); + if (oauth2ResourceHttpMethodList.SelectedIndex > 0) { + requestUri.AppendQueryArgument("access_token", authorization.AccessToken); + } + var request = (HttpWebRequest)WebRequest.Create(requestUri.Uri); request.Method = oauth2ResourceHttpMethodList.SelectedIndex < 2 ? "GET" : "POST"; + if (oauth2ResourceHttpMethodList.SelectedIndex == 0) { + client.AuthorizeRequest(request, authorization); + } + using (var resourceResponse = request.GetResponse()) { using (var responseStream = new StreamReader(resourceResponse.GetResponseStream())) { oauth2ResultsBox.Text = responseStream.ReadToEnd(); @@ -225,7 +232,11 @@ } catch (Messaging.ProtocolException ex) { MessageBox.Show(this, ex.Message); } catch (WebException ex) { - MessageBox.Show(this, ex.Message); + string responseText = string.Empty; + using (var responseReader = new StreamReader(ex.Response.GetResponseStream())) { + responseText = responseReader.ReadToEnd(); + } + MessageBox.Show(this, ex.Message + " " + responseText); } } } diff --git a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs index b229bb8..d652051 100644 --- a/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth/Messaging/MessagingUtilities.cs @@ -218,6 +218,22 @@ namespace DotNetOpenAuth.Messaging { } /// <summary> + /// Adds a name-value pair to the end of a given URL + /// as part of the querystring piece. Prefixes a ? or & before + /// first element as necessary. + /// </summary> + /// <param name="builder">The UriBuilder to add arguments to.</param> + /// <param name="name">The name of the parameter to add.</param> + /// <param name="value">The value of the argument.</param> + /// <remarks> + /// If the parameters to add match names of parameters that already are defined + /// in the query string, the existing ones are <i>not</i> replaced. + /// </remarks> + public static void AppendQueryArgument(this UriBuilder builder, string name, string value) { + AppendQueryArgs(builder, new[] { new KeyValuePair<string, string>(name, value) }); + } + + /// <summary> /// Strips any and all URI query parameters that serve as parts of a message. /// </summary> /// <param name="uri">The URI that may contain query parameters to remove.</param> |