summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml13
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml.cs22
2 files changed, 12 insertions, 23 deletions
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml b/samples/OAuthConsumerWpf/MainWindow.xaml
index 71f3810..979bc7e 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml
@@ -103,9 +103,9 @@
<TextBox Grid.Row="3" Grid.Column="1" x:Name="resourceUrlBox" />
<ComboBox Grid.Row="3" Grid.Column="2" x:Name="resourceHttpMethodList" SelectedIndex="0">
<ComboBox.Items>
- <ComboBoxItem>GET w/ header</ComboBoxItem>
- <ComboBoxItem>GET w/ querystring</ComboBoxItem>
- <ComboBoxItem>POST</ComboBoxItem>
+ <ComboBoxItem>GET w/ header</ComboBoxItem>
+ <ComboBoxItem>GET w/ querystring</ComboBoxItem>
+ <ComboBoxItem>POST</ComboBoxItem>
</ComboBox.Items>
</ComboBox>
<Label Grid.Row="4">Consumer key</Label>
@@ -159,10 +159,9 @@
<TextBox Grid.Row="3" Grid.Column="1" x:Name="oauth2ResourceUrlBox" Text="http://localhost:23603/api/values" TabIndex="208" />
<ComboBox Grid.Row="3" Grid.Column="2" x:Name="oauth2ResourceHttpMethodList" SelectedIndex="0" TabIndex="209">
<ComboBox.Items>
- <ComboBoxItem>GET w/ header</ComboBoxItem>
- <ComboBoxItem>GET w/ querystring</ComboBoxItem>
- <ComboBoxItem>POST</ComboBoxItem>
- </ComboBox.Items>
+ <ComboBoxItem>GET</ComboBoxItem>
+ <ComboBoxItem>POST</ComboBoxItem>
+ </ComboBox.Items>
</ComboBox>
<Label Grid.Row="4" TabIndex="210">Client Identifier</Label>
<TextBox Grid.Row="4" Grid.Column="1" x:Name="oauth2ClientIdentifierBox" Grid.ColumnSpan="2" Text="a" TabIndex="211" />
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml.cs b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
index efe7673..d58df8c 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml.cs
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
@@ -179,24 +179,14 @@
authorizePopup.ClientAuthorizationView.RequestImplicitGrant = flowBox.SelectedIndex == 1;
bool? result = authorizePopup.ShowDialog();
if (result.HasValue && result.Value) {
- var requestUri = new UriBuilder(this.oauth2ResourceUrlBox.Text);
- if (this.oauth2ResourceHttpMethodList.SelectedIndex > 0) {
- requestUri.AppendQueryArgument("access_token", authorizePopup.Authorization.AccessToken);
- }
-
- var request = (HttpWebRequest)WebRequest.Create(requestUri.Uri);
- request.Method = this.oauth2ResourceHttpMethodList.SelectedIndex < 2 ? "GET" : "POST";
- if (this.oauth2ResourceHttpMethodList.SelectedIndex == 0) {
- await client.AuthorizeRequestAsync(request, authorizePopup.Authorization, CancellationToken.None);
- }
-
- using (var resourceResponse = request.GetResponse()) {
- using (var responseStream = new StreamReader(resourceResponse.GetResponseStream())) {
- this.oauth2ResultsBox.Text = responseStream.ReadToEnd();
+ var request = new HttpRequestMessage(
+ new HttpMethod(((ComboBoxItem)this.oauth2ResourceHttpMethodList.SelectedValue).Content.ToString()),
+ this.oauth2ResourceUrlBox.Text);
+ using (var httpClient = new HttpClient(client.CreateAuthorizingHandler(authorizePopup.Authorization))) {
+ using (var resourceResponse = await httpClient.SendAsync(request)) {
+ this.oauth2ResultsBox.Text = await resourceResponse.Content.ReadAsStringAsync();
}
}
- } else {
- return;
}
} catch (Messaging.ProtocolException ex) {
MessageBox.Show(this, ex.Message);