diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-05-06 21:09:19 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-05-06 21:09:19 -0700 |
commit | 91f6fca9adfd016f913cab905a986d68117f6caa (patch) | |
tree | 2e2bb8bf4c0819529ca70c8f5fbfccaf5ad88d20 /samples/OAuthConsumer | |
parent | 230e0ee9ad8826e48de7250772eaa895da37afd1 (diff) | |
download | DotNetOpenAuth-91f6fca9adfd016f913cab905a986d68117f6caa.zip DotNetOpenAuth-91f6fca9adfd016f913cab905a986d68117f6caa.tar.gz DotNetOpenAuth-91f6fca9adfd016f913cab905a986d68117f6caa.tar.bz2 |
Working to catch up with latest OAuth 2.0 spec.
Diffstat (limited to 'samples/OAuthConsumer')
-rw-r--r-- | samples/OAuthConsumer/Facebook.aspx | 16 | ||||
-rw-r--r-- | samples/OAuthConsumer/Facebook.aspx.cs | 38 | ||||
-rw-r--r-- | samples/OAuthConsumer/Web.config | 3 |
3 files changed, 57 insertions, 0 deletions
diff --git a/samples/OAuthConsumer/Facebook.aspx b/samples/OAuthConsumer/Facebook.aspx new file mode 100644 index 0000000..536540e --- /dev/null +++ b/samples/OAuthConsumer/Facebook.aspx @@ -0,0 +1,16 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Facebook.aspx.cs" Inherits="Facebook" %> + +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml"> +<head runat="server"> + <title></title> +</head> +<body> + <form id="form1" runat="server"> + <div> + Welcome, + <asp:Label Text="[name]" ID="nameLabel" runat="server" /> + </div> + </form> +</body> +</html> diff --git a/samples/OAuthConsumer/Facebook.aspx.cs b/samples/OAuthConsumer/Facebook.aspx.cs new file mode 100644 index 0000000..ba08920 --- /dev/null +++ b/samples/OAuthConsumer/Facebook.aspx.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using DotNetOpenAuth.ApplicationBlock; +using DotNetOpenAuth.OAuthWrap; +using System.Net; +using System.IO; + +public partial class Facebook : System.Web.UI.Page { + private static readonly FacebookClient client = new FacebookClient { + ClientIdentifier = ConfigurationManager.AppSettings["facebookAppID"], + ClientSecret = ConfigurationManager.AppSettings["facebookAppSecret"], + }; + + protected void Page_Load(object sender, EventArgs e) + { + IAuthorizationState authorization = client.ProcessUserAuthorization(); + if (authorization == null) + { + // Kick off authorization request + client.Channel.Send(client.PrepareRequestUserAuthorization()); + } + else + { + var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken)); + using (var response = request.GetResponse()) { + using (var responseReader = new StreamReader(response.GetResponseStream())) { + string data = responseReader.ReadToEnd(); + } + } + nameLabel.Text = "Success! Access token: " + HttpUtility.HtmlEncode(authorization.AccessToken); + } + } +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/Web.config b/samples/OAuthConsumer/Web.config index 496da95..05eb6a8 100644 --- a/samples/OAuthConsumer/Web.config +++ b/samples/OAuthConsumer/Web.config @@ -50,6 +50,9 @@ <!-- Google sign-up: https://www.google.com/accounts/ManageDomains --> <add key="googleConsumerKey" value=""/> <add key="googleConsumerSecret" value=""/> + <!-- Facebook sign-up: http://developers.facebook.com/setup/ --> + <add key="facebookAppID" value=""/> + <add key="facebookAppSecret" value=""/> </appSettings> <connectionStrings/> |