diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-11-02 21:46:06 -0800 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-11-02 21:46:06 -0800 |
commit | 71e99449ee02155f34bb4928313c2200246b8a78 (patch) | |
tree | 8368303d42afe232a460c6cf7afc062d1270fc17 /samples | |
parent | 916966f88a3ed3246374efb625804b11bdda6fa5 (diff) | |
download | DotNetOpenAuth-71e99449ee02155f34bb4928313c2200246b8a78.zip DotNetOpenAuth-71e99449ee02155f34bb4928313c2200246b8a78.tar.gz DotNetOpenAuth-71e99449ee02155f34bb4928313c2200246b8a78.tar.bz2 |
First stab at building specific application Consumer classes for ease of adoption.
Diffstat (limited to 'samples')
-rw-r--r-- | samples/Consumer/App_Code/Constants.cs | 40 | ||||
-rw-r--r-- | samples/Consumer/GoogleAddressBook.aspx.cs | 38 |
2 files changed, 12 insertions, 66 deletions
diff --git a/samples/Consumer/App_Code/Constants.cs b/samples/Consumer/App_Code/Constants.cs deleted file mode 100644 index ba61b43..0000000 --- a/samples/Consumer/App_Code/Constants.cs +++ /dev/null @@ -1,40 +0,0 @@ -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);
- }
-}
diff --git a/samples/Consumer/GoogleAddressBook.aspx.cs b/samples/Consumer/GoogleAddressBook.aspx.cs index 29037d4..9fbcc05 100644 --- a/samples/Consumer/GoogleAddressBook.aspx.cs +++ b/samples/Consumer/GoogleAddressBook.aspx.cs @@ -1,14 +1,11 @@ using System;
-using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
-using DotNetOAuth;
-using DotNetOAuth.ChannelElements;
-using DotNetOAuth.Messaging;
+using DotNetOAuth.CommonConsumers;
/// <summary>
/// A page to demonstrate downloading a Gmail address book using OAuth.
@@ -18,23 +15,20 @@ public partial class GoogleAddressBook : System.Web.UI.Page { if (!IsPostBack) {
if (Session["TokenManager"] != null) {
InMemoryTokenManager tokenManager = (InMemoryTokenManager)Session["TokenManager"];
- WebConsumer google = new WebConsumer(Constants.GoogleDescription, tokenManager) {
- ConsumerKey = tokenManager.ConsumerKey,
- };
+ GoogleConsumer google = new GoogleConsumer(tokenManager, tokenManager.ConsumerKey);
- var accessTokenMessage = google.ProcessUserAuthorization();
- if (accessTokenMessage != null) {
+ var accessToken = google.GetAccessToken();
+ if (accessToken != null) {
// User has approved access
MultiView1.ActiveViewIndex = 1;
- resultsPlaceholder.Controls.Add(new Label { Text = accessTokenMessage.AccessToken });
+ resultsPlaceholder.Controls.Add(new Label { Text = accessToken });
- Response contactsResponse = google.PrepareAuthorizedRequestAndSend(Constants.GoogleScopes.GetContacts, accessTokenMessage.AccessToken);
- XDocument contactsDocument = XDocument.Parse(contactsResponse.Body);
+ XDocument contactsDocument = google.GetContacts(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,
+ };
StringBuilder tableBuilder = new StringBuilder();
tableBuilder.Append("<table><tr><td>Name</td><td>Email</td></tr>");
foreach (var contact in contacts) {
@@ -57,15 +51,7 @@ public partial class GoogleAddressBook : System.Web.UI.Page { InMemoryTokenManager tokenManager = new InMemoryTokenManager(consumerKeyBox.Text, consumerSecretBox.Text);
Session["TokenManager"] = tokenManager;
- WebConsumer google = new WebConsumer(Constants.GoogleDescription, tokenManager);
- google.ConsumerKey = consumerKeyBox.Text;
-
- var extraParameters = new Dictionary<string, string> {
- { "scope", Constants.GoogleScopes.Contacts },
- };
- UriBuilder callback = new UriBuilder(new Uri(Request.Url, Request.RawUrl));
- callback.Query = null;
- var response = google.PrepareRequestUserAuthorization(callback.Uri, extraParameters, null);
- google.Channel.Send(response).Send();
+ var google = new GoogleConsumer(tokenManager, consumerKeyBox.Text);
+ google.RequestAuthorization(GoogleConsumer.Applications.Contacts);
}
}
|