diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-21 14:10:41 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-03-21 14:10:41 -0700 |
commit | ec8e3b27155297b790cadcfdebbe24fa2cbfa639 (patch) | |
tree | bd710d4964741fddad097b66e7b5e0b6eeca8b1b /samples/ConsumerWpf | |
parent | 4197cf4144223397b3c1aa03eb136b34820c3684 (diff) | |
download | DotNetOpenAuth-ec8e3b27155297b790cadcfdebbe24fa2cbfa639.zip DotNetOpenAuth-ec8e3b27155297b790cadcfdebbe24fa2cbfa639.tar.gz DotNetOpenAuth-ec8e3b27155297b790cadcfdebbe24fa2cbfa639.tar.bz2 |
Added Blogger posting OAuth sample.
Diffstat (limited to 'samples/ConsumerWpf')
-rw-r--r-- | samples/ConsumerWpf/MainWindow.xaml | 41 | ||||
-rw-r--r-- | samples/ConsumerWpf/MainWindow.xaml.cs | 15 |
2 files changed, 47 insertions, 9 deletions
diff --git a/samples/ConsumerWpf/MainWindow.xaml b/samples/ConsumerWpf/MainWindow.xaml index 4fdf4e6..a3794c8 100644 --- a/samples/ConsumerWpf/MainWindow.xaml +++ b/samples/ConsumerWpf/MainWindow.xaml @@ -1,8 +1,8 @@ <Window x:Class="DotNetOpenAuth.Samples.ConsumerWpf.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - Title="DotNetOpenAuth Consumer (sample)" Height="248" Width="429"> - <Grid> + Title="DotNetOpenAuth Consumer (sample)" Height="400" Width="442"> + <Grid Margin="5"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition /> @@ -30,11 +30,36 @@ </Hyperlink> </TextBlock> </Label> - <Grid Grid.ColumnSpan="2" Grid.Row="4" Name="contactsGrid"> - <Grid.ColumnDefinitions> - <ColumnDefinition Width="Auto" /> - <ColumnDefinition Width="Auto" /> - </Grid.ColumnDefinitions> - </Grid> + <TabControl Grid.ColumnSpan="2" Grid.Row="4" Name="tabControl1" Margin="0,10,0,0"> + <TabItem Header="Gmail Contacts" Name="gmailContactsTab"> + <Grid Name="contactsGrid"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="Auto" /> + </Grid.ColumnDefinitions> + </Grid> + </TabItem> + <TabItem Header="Blogger" Name="bloggerTab"> + <Grid> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="Auto" /> + <ColumnDefinition Width="*" /> + </Grid.ColumnDefinitions> + <Grid.RowDefinitions> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + <RowDefinition Height="Auto" /> + </Grid.RowDefinitions> + <Label>Blog URL</Label> + <TextBox Grid.Column="1" x:Name="blogUrlBox"/> + <Label Grid.Row="1">Title</Label> + <TextBox Grid.Row="1" Grid.Column="1" x:Name="postTitleBox">OAuth Rocks!</TextBox> + <Label Grid.Row="2">Body</Label> + <TextBox Grid.Row="2" Grid.Column="1" x:Name="postBodyBox" AcceptsReturn="True" AcceptsTab="True" AutoWordSelection="True" TextWrapping="WrapWithOverflow"><p xmlns="http://www.w3.org/1999/xhtml">Oauth is cool</p></TextBox> + <Button x:Name="postButton" Grid.Row="3" Grid.Column="1" Click="postButton_Click" IsEnabled="False">Post</Button> + </Grid> + </TabItem> + </TabControl> </Grid> </Window> diff --git a/samples/ConsumerWpf/MainWindow.xaml.cs b/samples/ConsumerWpf/MainWindow.xaml.cs index bcaae6f..ea3ea39 100644 --- a/samples/ConsumerWpf/MainWindow.xaml.cs +++ b/samples/ConsumerWpf/MainWindow.xaml.cs @@ -13,7 +13,9 @@ using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; + using System.Xml; using System.Xml.Linq; + using System.Xml.XPath; using DotNetOpenAuth; using DotNetOpenAuth.ApplicationBlock; using DotNetOpenAuth.Messaging; @@ -27,6 +29,7 @@ private InMemoryTokenManager tokenManager = new InMemoryTokenManager(); private DesktopConsumer google; private string requestToken; + private string accessToken; public MainWindow() { InitializeComponent(); @@ -43,18 +46,23 @@ this.Cursor = Cursors.Wait; beginAuthorizationButton.IsEnabled = false; ThreadPool.QueueUserWorkItem(delegate(object state) { - Uri browserAuthorizationLocation = GoogleConsumer.RequestAuthorization(this.google, GoogleConsumer.Applications.Contacts, out this.requestToken); + 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; })); }); } 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 { @@ -73,5 +81,10 @@ contactsGrid.Children.Add(email); } } + + private void postButton_Click(object sender, RoutedEventArgs e) { + XElement postBodyXml = XElement.Parse(postBodyBox.Text); + GoogleConsumer.PostBlogEntry(this.google, this.accessToken, blogUrlBox.Text, postTitleBox.Text, postBodyXml); + } } } |