diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-02 22:51:25 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-02 22:51:25 -0800 |
commit | fe66a05013df51312dec9074eed7915ba3b2da8a (patch) | |
tree | f2188cf7f97147f0f92fd306078404325f218b76 /samples | |
parent | 8969dfec9e4e4ecc45f909137dc3a23d7af0bee8 (diff) | |
download | DotNetOpenAuth-fe66a05013df51312dec9074eed7915ba3b2da8a.zip DotNetOpenAuth-fe66a05013df51312dec9074eed7915ba3b2da8a.tar.gz DotNetOpenAuth-fe66a05013df51312dec9074eed7915ba3b2da8a.tar.bz2 |
Applied the Google common consumer class to the WPF sample.
Diffstat (limited to 'samples')
-rw-r--r-- | samples/ConsumerWpf/Constants.cs | 48 | ||||
-rw-r--r-- | samples/ConsumerWpf/ConsumerWpf.csproj | 1 | ||||
-rw-r--r-- | samples/ConsumerWpf/MainWindow.xaml.cs | 19 |
3 files changed, 8 insertions, 60 deletions
diff --git a/samples/ConsumerWpf/Constants.cs b/samples/ConsumerWpf/Constants.cs deleted file mode 100644 index cc21908..0000000 --- a/samples/ConsumerWpf/Constants.cs +++ /dev/null @@ -1,48 +0,0 @@ -//-----------------------------------------------------------------------
-// <copyright file="Constants.cs" company="Andrew Arnott">
-// Copyright (c) Andrew Arnott. All rights reserved.
-// </copyright>
-//-----------------------------------------------------------------------
-
-namespace DotNetOAuth.Samples.ConsumerWpf {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using DotNetOAuth;
- using DotNetOAuth.ChannelElements;
- using DotNetOAuth.Messaging;
-
- /// <summary>
- /// Service Provider definitions.
- /// </summary>
- public static class Constants {
- /// <summary>
- /// The Consumer to use for accessing Google data APIs.
- /// </summary>
- public static readonly ServiceProviderDescription GoogleDescription = new ServiceProviderDescription {
- RequestTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetRequestToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
- UserAuthorizationEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthAuthorizeToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
- AccessTokenEndpoint = new MessageReceivingEndpoint("https://www.google.com/accounts/OAuthGetAccessToken", HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.GetRequest),
- TamperProtectionElements = new ITamperProtectionChannelBindingElement[] {
- new HmacSha1SigningBindingElement(),
- },
- };
-
- /// <summary>
- /// Values of the "scope" parameter that indicates what data streams the Consumer
- /// wants access to.
- /// </summary>
- public static class GoogleScopes {
- /// <summary>
- /// Access to the Gmail address book.
- /// </summary>
- public const string Contacts = "http://www.google.com/m8/feeds/";
-
- /// <summary>
- /// The URI to get contacts once authorization is granted.
- /// </summary>
- public static readonly MessageReceivingEndpoint GetContacts = new MessageReceivingEndpoint("http://www.google.com/m8/feeds/contacts/default/full/", HttpDeliveryMethods.GetRequest);
- }
- }
-}
\ No newline at end of file diff --git a/samples/ConsumerWpf/ConsumerWpf.csproj b/samples/ConsumerWpf/ConsumerWpf.csproj index 389894f..4632889 100644 --- a/samples/ConsumerWpf/ConsumerWpf.csproj +++ b/samples/ConsumerWpf/ConsumerWpf.csproj @@ -69,7 +69,6 @@ </Compile>
</ItemGroup>
<ItemGroup>
- <Compile Include="Constants.cs" />
<Compile Include="InMemoryTokenManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType>
diff --git a/samples/ConsumerWpf/MainWindow.xaml.cs b/samples/ConsumerWpf/MainWindow.xaml.cs index e1a4b6b..37dc288 100644 --- a/samples/ConsumerWpf/MainWindow.xaml.cs +++ b/samples/ConsumerWpf/MainWindow.xaml.cs @@ -15,6 +15,7 @@ using System.Xml.Linq;
using DotNetOAuth;
using DotNetOAuth.ChannelElements;
+ using DotNetOAuth.CommonConsumers;
using DotNetOAuth.Messaging;
/// <summary>
@@ -28,7 +29,7 @@ public MainWindow() {
InitializeComponent();
- this.google = new DesktopConsumer(Constants.GoogleDescription, this.tokenManager);
+ this.google = GoogleConsumer.CreateDesktopConsumer(this.tokenManager, string.Empty);
}
private void beginAuthorizationButton_Click(object sender, RoutedEventArgs e) {
@@ -36,22 +37,18 @@ this.tokenManager.ConsumerSecret = consumerSecretBox.Text;
this.google.ConsumerKey = consumerKeyBox.Text;
- var extraParameters = new Dictionary<string, string> {
- { "scope", Constants.GoogleScopes.Contacts },
- };
- Uri browserAuthorizationLocation = this.google.RequestUserAuthorization(extraParameters, null, out this.requestToken);
+ Uri browserAuthorizationLocation = GoogleConsumer.RequestAuthorization(this.google, GoogleConsumer.Applications.Contacts, out this.requestToken);
System.Diagnostics.Process.Start(browserAuthorizationLocation.AbsoluteUri);
}
private void completeAuthorizationButton_Click(object sender, RoutedEventArgs e) {
var grantedAccess = this.google.ProcessUserAuthorization(this.requestToken);
- Response contactsResponse = this.google.PrepareAuthorizedRequestAndSend(Constants.GoogleScopes.GetContacts, grantedAccess.AccessToken);
- XDocument contactsDocument = XDocument.Parse(contactsResponse.Body);
+ 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());
|