summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-06-07 15:11:10 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-06-07 15:11:10 -0700
commitf0784bf1caaa835162dc1bd920787f092a0d3ef4 (patch)
treec401c66550076702ceccd5df888565bf7a42033f
parent8c2790bc66818c13cc9842a1c6250f3eee5ebca5 (diff)
downloadDotNetOpenAuth-f0784bf1caaa835162dc1bd920787f092a0d3ef4.zip
DotNetOpenAuth-f0784bf1caaa835162dc1bd920787f092a0d3ef4.tar.gz
DotNetOpenAuth-f0784bf1caaa835162dc1bd920787f092a0d3ef4.tar.bz2
OAuthConsumerWpf now works with OAuth 1.0a as well.
-rw-r--r--samples/OAuthConsumerWpf/Authorize.xaml12
-rw-r--r--samples/OAuthConsumerWpf/Authorize.xaml.cs60
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml5
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml.cs53
-rw-r--r--samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj24
5 files changed, 112 insertions, 42 deletions
diff --git a/samples/OAuthConsumerWpf/Authorize.xaml b/samples/OAuthConsumerWpf/Authorize.xaml
new file mode 100644
index 0000000..5aa2349
--- /dev/null
+++ b/samples/OAuthConsumerWpf/Authorize.xaml
@@ -0,0 +1,12 @@
+<Window x:Class="DotNetOpenAuth.Samples.OAuthConsumerWpf.Authorize"
+ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+ Title="Authorize" Width="300" ShowInTaskbar="False">
+ <StackPanel>
+ <TextBlock TextWrapping="Wrap">Complete authorization at your service provider,
+ then enter the verification code below and click Finish:</TextBlock>
+ <TextBox Name="verifierBox"/>
+ <Button Name="finishButton" Click="finishButton_Click">Finish</Button>
+ <Button Name="cancelButton" Click="cancelButton_Click">Cancel</Button>
+ </StackPanel>
+</Window>
diff --git a/samples/OAuthConsumerWpf/Authorize.xaml.cs b/samples/OAuthConsumerWpf/Authorize.xaml.cs
new file mode 100644
index 0000000..26e5abc
--- /dev/null
+++ b/samples/OAuthConsumerWpf/Authorize.xaml.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.Threading;
+using DotNetOpenAuth.OAuth;
+using DotNetOpenAuth.ApplicationBlock;
+using System.Xml.Linq;
+
+namespace DotNetOpenAuth.Samples.OAuthConsumerWpf {
+ /// <summary>
+ /// Interaction logic for Authorize.xaml
+ /// </summary>
+ partial class Authorize : Window {
+ private DesktopConsumer google;
+ private string requestToken;
+
+ internal string AccessToken { get; set; }
+
+ internal Authorize(DesktopConsumer consumer) {
+ InitializeComponent();
+
+ this.google = consumer;
+ Cursor original = this.Cursor;
+ this.Cursor = Cursors.Wait;
+ ThreadPool.QueueUserWorkItem(delegate(object state) {
+ Uri browserAuthorizationLocation = GoogleConsumer.RequestAuthorization(
+ this.google,
+ GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger,
+ out this.requestToken);
+ System.Diagnostics.Process.Start(browserAuthorizationLocation.AbsoluteUri);
+ this.Dispatcher.BeginInvoke(new Action(() => {
+ this.Cursor = original;
+ finishButton.IsEnabled = true;
+ }));
+ });
+
+ }
+
+ private void finishButton_Click(object sender, RoutedEventArgs e) {
+ var grantedAccess = this.google.ProcessUserAuthorization(this.requestToken, verifierBox.Text);
+ this.AccessToken = grantedAccess.AccessToken;
+ DialogResult = true;
+ Close();
+ }
+
+ private void cancelButton_Click(object sender, RoutedEventArgs e) {
+ DialogResult = false;
+ Close();
+ }
+ }
+}
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml b/samples/OAuthConsumerWpf/MainWindow.xaml
index fb036ce..6ada88a 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml
@@ -14,10 +14,7 @@
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
- <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="3">
- <Button Name="beginAuthorizationButton" Click="beginAuthorizationButton_Click">Start authorize</Button>
- <Button Name="completeAuthorizationButton" Margin="5,0,0,0" Click="completeAuthorizationButton_Click" IsEnabled="false">Complete authorization</Button>
- </StackPanel>
+ <Button Grid.Column="1" Grid.Row="3" Name="beginAuthorizationButton" Click="beginAuthorizationButton_Click">Authorize</Button>
<TabControl Grid.ColumnSpan="2" Grid.Row="4" Name="tabControl1" Margin="0,10,0,0">
<TabItem Header="Gmail Contacts" Name="gmailContactsTab">
<Grid Name="contactsGrid">
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml.cs b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
index 6c1c2ba..e408d19 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml.cs
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml.cs
@@ -30,7 +30,6 @@
public partial class MainWindow : Window {
private InMemoryTokenManager tokenManager = new InMemoryTokenManager();
private DesktopConsumer google;
- private string requestToken;
private string accessToken;
public MainWindow() {
@@ -56,40 +55,26 @@
return;
}
- Cursor original = this.Cursor;
- this.Cursor = Cursors.Wait;
- beginAuthorizationButton.IsEnabled = false;
- ThreadPool.QueueUserWorkItem(delegate(object state) {
- Uri browserAuthorizationLocation = GoogleConsumer.RequestAuthorization(
- this.google,
- GoogleConsumer.Applications.Contacts | GoogleConsumer.Applications.Blogger,
- out this.requestToken);
- System.Diagnostics.Process.Start(browserAuthorizationLocation.AbsoluteUri);
- this.Dispatcher.BeginInvoke(new Action(() => {
- this.Cursor = original;
- beginAuthorizationButton.IsEnabled = true;
- completeAuthorizationButton.IsEnabled = true;
- postButton.IsEnabled = true;
- }));
- });
- }
+ Authorize auth = new Authorize(this.google);
+ bool? result = auth.ShowDialog();
+ if (result.HasValue && result.Value) {
+ this.accessToken = auth.AccessToken;
+ postButton.IsEnabled = true;
- private void completeAuthorizationButton_Click(object sender, RoutedEventArgs e) {
- var grantedAccess = this.google.ProcessUserAuthorization(this.requestToken);
- this.accessToken = grantedAccess.AccessToken;
- XDocument contactsDocument = GoogleConsumer.GetContacts(this.google, grantedAccess.AccessToken);
- var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
- select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value };
- contactsGrid.Children.Clear();
- foreach (var contact in contacts) {
- contactsGrid.RowDefinitions.Add(new RowDefinition());
- TextBlock name = new TextBlock { Text = contact.Name };
- TextBlock email = new TextBlock { Text = contact.Email };
- Grid.SetRow(name, contactsGrid.RowDefinitions.Count - 1);
- Grid.SetRow(email, contactsGrid.RowDefinitions.Count - 1);
- Grid.SetColumn(email, 1);
- contactsGrid.Children.Add(name);
- contactsGrid.Children.Add(email);
+ XDocument contactsDocument = GoogleConsumer.GetContacts(this.google, this.accessToken);
+ var contacts = from entry in contactsDocument.Root.Elements(XName.Get("entry", "http://www.w3.org/2005/Atom"))
+ select new { Name = entry.Element(XName.Get("title", "http://www.w3.org/2005/Atom")).Value, Email = entry.Element(XName.Get("email", "http://schemas.google.com/g/2005")).Attribute("address").Value };
+ contactsGrid.Children.Clear();
+ foreach (var contact in contacts) {
+ contactsGrid.RowDefinitions.Add(new RowDefinition());
+ TextBlock name = new TextBlock { Text = contact.Name };
+ TextBlock email = new TextBlock { Text = contact.Email };
+ Grid.SetRow(name, contactsGrid.RowDefinitions.Count - 1);
+ Grid.SetRow(email, contactsGrid.RowDefinitions.Count - 1);
+ Grid.SetColumn(email, 1);
+ contactsGrid.Children.Add(name);
+ contactsGrid.Children.Add(email);
+ }
}
}
diff --git a/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj b/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
index 0617746..6e8e4ea 100644
--- a/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
+++ b/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
@@ -65,15 +65,28 @@
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
- <Reference Include="WindowsBase" />
- <Reference Include="PresentationCore" />
- <Reference Include="PresentationFramework" />
+ <Reference Include="UIAutomationProvider">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="WindowsBase">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationCore">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
+ <Reference Include="PresentationFramework">
+ <RequiredTargetFramework>3.0</RequiredTargetFramework>
+ </Reference>
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
+ <Page Include="Authorize.xaml">
+ <SubType>Designer</SubType>
+ <Generator>MSBuild:Compile</Generator>
+ </Page>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -88,6 +101,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
+ <Compile Include="Authorize.xaml.cs">
+ <DependentUpon>Authorize.xaml</DependentUpon>
+ </Compile>
<Compile Include="InMemoryTokenManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
@@ -131,4 +147,4 @@
<Target Name="AfterBuild">
</Target>
-->
-</Project>
+</Project> \ No newline at end of file