summaryrefslogtreecommitdiffstats
path: root/samples/OAuthConsumerWpf
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2009-04-10 21:19:09 -0700
committerAndrew Arnott <andrewarnott@gmail.com>2009-04-10 21:19:09 -0700
commit5cb3aa5dda4d090400e6561c6ec64999ed5fca4c (patch)
tree0cf5633163de5d2f4e61c4e4a1c1d3783f234e5f /samples/OAuthConsumerWpf
parent8254a5ca1ced42181eb33e1282cfab5e429b0243 (diff)
parent3588b38fff5216468485d75642f91d283208c5c8 (diff)
downloadDotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.zip
DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.tar.gz
DotNetOpenAuth-5cb3aa5dda4d090400e6561c6ec64999ed5fca4c.tar.bz2
Merge commit 'v3.0'
Diffstat (limited to 'samples/OAuthConsumerWpf')
-rw-r--r--samples/OAuthConsumerWpf/App.config17
-rw-r--r--samples/OAuthConsumerWpf/InMemoryTokenManager.cs6
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml12
-rw-r--r--samples/OAuthConsumerWpf/MainWindow.xaml.cs27
-rw-r--r--samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj5
-rw-r--r--samples/OAuthConsumerWpf/Properties/AssemblyInfo.cs2
6 files changed, 46 insertions, 23 deletions
diff --git a/samples/OAuthConsumerWpf/App.config b/samples/OAuthConsumerWpf/App.config
index 9780370..2f849e4 100644
--- a/samples/OAuthConsumerWpf/App.config
+++ b/samples/OAuthConsumerWpf/App.config
@@ -3,6 +3,23 @@
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler" requirePermission="false" />
</configSections>
+
+ <appSettings>
+ <!-- Fill in your various consumer keys and secrets here to make the sample work. -->
+ <!-- You must get these values by signing up with each individual service provider. -->
+ <!-- Google sign-up: https://www.google.com/accounts/ManageDomains -->
+ <add key="googleConsumerKey" value=""/>
+ <!-- Google requires either a secret or an X.509 certificate. This sample will use
+ the certificate if it is specified, otherwise it will use the shared secret. -->
+ <add key="googleConsumerSecret" value=""/>
+ <add key="googleConsumerCertificateFile" value=""/>
+ <add key="googleConsumerCertificatePassword" value=""/>
+ </appSettings>
+
+ <system.net>
+ <defaultProxy enabled="true" />
+ </system.net>
+
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Testing.log" />
diff --git a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
index b4692f1..faa485f 100644
--- a/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
+++ b/samples/OAuthConsumerWpf/InMemoryTokenManager.cs
@@ -11,15 +11,15 @@ namespace DotNetOpenAuth.Samples.OAuthConsumerWpf {
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
- internal class InMemoryTokenManager : ITokenManager {
+ internal class InMemoryTokenManager : IConsumerTokenManager {
private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>();
internal InMemoryTokenManager() {
}
- internal string ConsumerKey { get; set; }
+ public string ConsumerKey { get; internal set; }
- internal string ConsumerSecret { get; set; }
+ public string ConsumerSecret { get; internal set; }
#region ITokenManager Members
diff --git a/samples/OAuthConsumerWpf/MainWindow.xaml b/samples/OAuthConsumerWpf/MainWindow.xaml
index f422353..fb036ce 100644
--- a/samples/OAuthConsumerWpf/MainWindow.xaml
+++ b/samples/OAuthConsumerWpf/MainWindow.xaml
@@ -18,18 +18,6 @@
<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>
- <Label>Consumer Key</Label>
- <TextBox Grid.Column="1" Name="consumerKeyBox"/>
- <Label Grid.Row="1">Consumer Secret</Label>
- <TextBox Grid.Row="1" Grid.Column="1" Name="consumerSecretBox"/>
- <Label Grid.Row="2" Grid.Column="1">
- <TextBlock>
- Don't have a Google Consumer Key?
- <Hyperlink NavigateUri="https://www.google.com/accounts/ManageDomains">
- <TextBlock>Get one!</TextBlock>
- </Hyperlink>
- </TextBlock>
- </Label>
<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 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());
diff --git a/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj b/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
index e1181ae..0617746 100644
--- a/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
+++ b/samples/OAuthConsumerWpf/OAuthConsumerWpf.csproj
@@ -43,11 +43,16 @@
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\log4net.dll</HintPath>
+ </Reference>
<Reference Include="Microsoft.Contracts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=736440c9b414ea16, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\Microsoft.Contracts.dll</HintPath>
</Reference>
<Reference Include="System" />
+ <Reference Include="System.configuration" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
diff --git a/samples/OAuthConsumerWpf/Properties/AssemblyInfo.cs b/samples/OAuthConsumerWpf/Properties/AssemblyInfo.cs
index 029ad14..8d23055 100644
--- a/samples/OAuthConsumerWpf/Properties/AssemblyInfo.cs
+++ b/samples/OAuthConsumerWpf/Properties/AssemblyInfo.cs
@@ -16,6 +16,8 @@ using System.Windows;
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
+[assembly: log4net.Config.XmlConfigurator(Watch = true)]
+
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.