summaryrefslogtreecommitdiffstats
path: root/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
diff options
context:
space:
mode:
authorAndrew Arnott <andrewarnott@gmail.com>2013-02-26 22:55:18 -0800
committerAndrew Arnott <andrewarnott@gmail.com>2013-02-26 22:55:18 -0800
commit6204dcf07f31b78478bc1ddb55a6ca9027617b67 (patch)
tree2b92fff13f9e253c9504e73b677ec61b352d9f38 /samples/OAuthConsumer/GoogleAddressBook.aspx.cs
parent38a1162c5cbaea035e655dc9accd92f9de5019ed (diff)
downloadDotNetOpenAuth-6204dcf07f31b78478bc1ddb55a6ca9027617b67.zip
DotNetOpenAuth-6204dcf07f31b78478bc1ddb55a6ca9027617b67.tar.gz
DotNetOpenAuth-6204dcf07f31b78478bc1ddb55a6ca9027617b67.tar.bz2
Fixes some OAuth 1 build breaks.
Diffstat (limited to 'samples/OAuthConsumer/GoogleAddressBook.aspx.cs')
-rw-r--r--samples/OAuthConsumer/GoogleAddressBook.aspx.cs36
1 files changed, 10 insertions, 26 deletions
diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
index 8a2a816..4eb4101 100644
--- a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
+++ b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs
@@ -14,50 +14,34 @@
/// A page to demonstrate downloading a Gmail address book using OAuth.
/// </summary>
public partial class GoogleAddressBook : System.Web.UI.Page {
- private string AccessToken {
- get { return (string)Session["GoogleAccessToken"]; }
+ private AccessToken AccessToken {
+ get { return (AccessToken)Session["GoogleAccessToken"]; }
set { Session["GoogleAccessToken"] = value; }
}
- private InMemoryTokenManager TokenManager {
- get {
- var tokenManager = (InMemoryTokenManager)Application["GoogleTokenManager"];
- if (tokenManager == null) {
- string consumerKey = ConfigurationManager.AppSettings["googleConsumerKey"];
- string consumerSecret = ConfigurationManager.AppSettings["googleConsumerSecret"];
- if (!string.IsNullOrEmpty(consumerKey)) {
- tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret);
- Application["GoogleTokenManager"] = tokenManager;
- }
- }
-
- return tokenManager;
- }
- }
-
protected async void Page_Load(object sender, EventArgs e) {
- if (this.TokenManager != null) {
+ var google = new GoogleConsumer();
+ if (google.ConsumerKey != null) {
this.MultiView1.ActiveViewIndex = 1;
if (!IsPostBack) {
- var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager);
-
// Is Google calling back with authorization?
- var accessTokenResponse = await google.ProcessUserAuthorizationAsync(new HttpRequestWrapper(Request), Response.ClientDisconnectedToken);
+ var accessTokenResponse = await google.ProcessUserAuthorizationAsync(this.Request.Url);
if (accessTokenResponse != null) {
this.AccessToken = accessTokenResponse.AccessToken;
- } else if (this.AccessToken == null) {
+ } else if (this.AccessToken.Token == null) {
// If we don't yet have access, immediately request it.
- await GoogleConsumer.RequestAuthorizationAsync(google, GoogleConsumer.Applications.Contacts);
+ Uri redirectUri = await google.RequestUserAuthorizationAsync(GoogleConsumer.Applications.Contacts);
+ this.Response.RedirectLocation = redirectUri.AbsoluteUri;
}
}
}
}
protected async void getAddressBookButton_Click(object sender, EventArgs e) {
- var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager);
+ var google = new GoogleConsumer();
- XDocument contactsDocument = await GoogleConsumer.GetContactsAsync(google, this.AccessToken, 5, 1, Response.ClientDisconnectedToken);
+ XDocument contactsDocument = await google.GetContactsAsync(this.AccessToken, 5, 1, Response.ClientDisconnectedToken);
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 };
StringBuilder tableBuilder = new StringBuilder();