diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-10 21:19:09 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2009-04-10 21:19:09 -0700 |
commit | 5cb3aa5dda4d090400e6561c6ec64999ed5fca4c (patch) | |
tree | 0cf5633163de5d2f4e61c4e4a1c1d3783f234e5f /samples/OAuthConsumerWpf/MainWindow.xaml.cs | |
parent | 8254a5ca1ced42181eb33e1282cfab5e429b0243 (diff) | |
parent | 3588b38fff5216468485d75642f91d283208c5c8 (diff) | |
download | DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.zip DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.tar.gz DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.tar.bz2 |
Merge commit 'v3.0'
Diffstat (limited to 'samples/OAuthConsumerWpf/MainWindow.xaml.cs')
-rw-r--r-- | samples/OAuthConsumerWpf/MainWindow.xaml.cs | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml.cs b/samples/OAuthConsumerWpf/MainWindow.xaml.cs index b57589a..6c1c2ba 100644 --- a/samples/OAuthConsumerWpf/MainWindow.xaml.cs +++ b/samples/OAuthConsumerWpf/MainWindow.xaml.cs @@ -1,7 +1,9 @@ namespace DotNetOpenAuth.Samples.OAuthConsumerWpf { using System; using System.Collections.Generic; + using System.Configuration; using System.Linq; + using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading; using System.Windows; @@ -34,13 +36,25 @@ public MainWindow() { InitializeComponent(); - this.google = GoogleConsumer.CreateDesktopConsumer(this.tokenManager, string.Empty); + this.tokenManager.ConsumerKey = ConfigurationManager.AppSettings["googleConsumerKey"]; + this.tokenManager.ConsumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"]; + + string pfxFile = ConfigurationManager.AppSettings["googleConsumerCertificateFile"]; + if (string.IsNullOrEmpty(pfxFile)) { + this.google = new DesktopConsumer(GoogleConsumer.ServiceDescription, this.tokenManager); + } else { + string pfxPassword = ConfigurationManager.AppSettings["googleConsumerCertificatePassword"]; + var signingCertificate = new X509Certificate2(pfxFile, pfxPassword); + var service = GoogleConsumer.CreateRsaSha1ServiceDescription(signingCertificate); + this.google = new DesktopConsumer(service, this.tokenManager); + } } private void beginAuthorizationButton_Click(object sender, RoutedEventArgs e) { - this.tokenManager.ConsumerKey = consumerKeyBox.Text; - this.tokenManager.ConsumerSecret = consumerSecretBox.Text; - this.google.ConsumerKey = consumerKeyBox.Text; + if (string.IsNullOrEmpty(this.tokenManager.ConsumerKey)) { + MessageBox.Show(this, "You must modify the App.config or OAuthConsumerWpf.exe.config file for this application to include your Google OAuth consumer key first.", "Configuration required", MessageBoxButton.OK, MessageBoxImage.Stop); + return; + } Cursor original = this.Cursor; this.Cursor = Cursors.Wait; @@ -65,10 +79,7 @@ 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, - }; + 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()); |