diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2010-04-19 07:09:32 -0400 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2010-04-19 07:09:32 -0400 |
commit | 668c50fd19dc633bd367ac8ace37df8b5f9a5881 (patch) | |
tree | 8ab71b553fa22e12aae6817b3c6fab93acdd31df /samples/OAuthConsumer | |
parent | fef932af78eac2b775452c4a851e84a813027548 (diff) | |
download | DotNetOpenAuth-668c50fd19dc633bd367ac8ace37df8b5f9a5881.zip DotNetOpenAuth-668c50fd19dc633bd367ac8ace37df8b5f9a5881.tar.gz DotNetOpenAuth-668c50fd19dc633bd367ac8ace37df8b5f9a5881.tar.bz2 |
Updated OAuth C and SP samples to use standard WAP namespaces.
Diffstat (limited to 'samples/OAuthConsumer')
21 files changed, 643 insertions, 610 deletions
diff --git a/samples/OAuthConsumer/Code/Logging.cs b/samples/OAuthConsumer/Code/Logging.cs index 185c9a9..510ea85 100644 --- a/samples/OAuthConsumer/Code/Logging.cs +++ b/samples/OAuthConsumer/Code/Logging.cs @@ -1,20 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Web; +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using System.Web; -/// <summary> -/// Logging tools for this sample. -/// </summary> -public static class Logging { /// <summary> - /// An application memory cache of recent log messages. + /// Logging tools for this sample. /// </summary> - public static StringBuilder LogMessages = new StringBuilder(); + public static class Logging { + /// <summary> + /// An application memory cache of recent log messages. + /// </summary> + public static StringBuilder LogMessages = new StringBuilder(); - /// <summary> - /// The logger for this sample to use. - /// </summary> - public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.ConsumerSample"); + /// <summary> + /// The logger for this sample to use. + /// </summary> + public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOpenAuth.OAuthConsumer"); + } }
\ No newline at end of file diff --git a/samples/OAuthConsumer/Code/TracePageAppender.cs b/samples/OAuthConsumer/Code/TracePageAppender.cs index 93ec9e3..5d3ba36 100644 --- a/samples/OAuthConsumer/Code/TracePageAppender.cs +++ b/samples/OAuthConsumer/Code/TracePageAppender.cs @@ -1,11 +1,13 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Web; +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.IO; + using System.Web; -public class TracePageAppender : log4net.Appender.AppenderSkeleton { - protected override void Append(log4net.Core.LoggingEvent loggingEvent) { - StringWriter sw = new StringWriter(Logging.LogMessages); - Layout.Format(sw, loggingEvent); + public class TracePageAppender : log4net.Appender.AppenderSkeleton { + protected override void Append(log4net.Core.LoggingEvent loggingEvent) { + StringWriter sw = new StringWriter(Logging.LogMessages); + Layout.Format(sw, loggingEvent); + } } -} +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/Global.asax b/samples/OAuthConsumer/Global.asax index fa4ca9b..06ffcd8 100644 --- a/samples/OAuthConsumer/Global.asax +++ b/samples/OAuthConsumer/Global.asax @@ -1,31 +1 @@ -<%@ Application Language="C#" %> - -<script RunAt="server"> - void Application_Start(object sender, EventArgs e) { - log4net.Config.XmlConfigurator.Configure(); - Logging.Logger.Info("Sample starting..."); - } - - void Application_End(object sender, EventArgs e) { - Logging.Logger.Info("Sample shutting down..."); - // this would be automatic, but in partial trust scenarios it is not. - log4net.LogManager.Shutdown(); - } - - void Application_Error(object sender, EventArgs e) { - Logging.Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError()); - } - - void Session_Start(object sender, EventArgs e) { - // Code that runs when a new session is started - - } - - void Session_End(object sender, EventArgs e) { - // Code that runs when a session ends. - // Note: The Session_End event is raised only when the sessionstate mode - // is set to InProc in the Web.config file. If session mode is set to StateServer - // or SQLServer, the event is not raised. - - } -</script> +<%@ Application Language="C#" Inherits="OAuthConsumer.Global" CodeBehind="Global.asax.cs" %> diff --git a/samples/OAuthConsumer/Global.asax.cs b/samples/OAuthConsumer/Global.asax.cs new file mode 100644 index 0000000..b2f5b5a --- /dev/null +++ b/samples/OAuthConsumer/Global.asax.cs @@ -0,0 +1,36 @@ +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Web; + + public partial class Global : HttpApplication { + protected void Application_Start(object sender, EventArgs e) { + log4net.Config.XmlConfigurator.Configure(); + Logging.Logger.Info("Sample starting..."); + } + + protected void Application_End(object sender, EventArgs e) { + Logging.Logger.Info("Sample shutting down..."); + // this would be automatic, but in partial trust scenarios it is not. + log4net.LogManager.Shutdown(); + } + + protected void Application_Error(object sender, EventArgs e) { + Logging.Logger.ErrorFormat("An unhandled exception was raised. Details follow: {0}", HttpContext.Current.Server.GetLastError()); + } + + protected void Session_Start(object sender, EventArgs e) { + // Code that runs when a new session is started + + } + + protected void Session_End(object sender, EventArgs e) { + // Code that runs when a session ends. + // Note: The Session_End event is raised only when the sessionstate mode + // is set to InProc in the Web.config file. If session mode is set to StateServer + // or SQLServer, the event is not raised. + + } + } +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx b/samples/OAuthConsumer/GoogleAddressBook.aspx index bd4bd81..1be21aa 100644 --- a/samples/OAuthConsumer/GoogleAddressBook.aspx +++ b/samples/OAuthConsumer/GoogleAddressBook.aspx @@ -1,5 +1,5 @@ <%@ Page Title="Gmail address book demo" Language="C#" MasterPageFile="~/MasterPage.master" - AutoEventWireup="true" Inherits="GoogleAddressBook" Codebehind="GoogleAddressBook.aspx.cs" %> + AutoEventWireup="true" Inherits="OAuthConsumer.GoogleAddressBook" Codebehind="GoogleAddressBook.aspx.cs" %> <asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server"> <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs index 463d7e3..825dd1a 100644 --- a/samples/OAuthConsumer/GoogleAddressBook.aspx.cs +++ b/samples/OAuthConsumer/GoogleAddressBook.aspx.cs @@ -1,73 +1,75 @@ -using System; -using System.Configuration; -using System.Linq; -using System.Text; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Xml.Linq; -using DotNetOpenAuth.ApplicationBlock; -using DotNetOpenAuth.OAuth; +namespace OAuthConsumer { + using System; + using System.Configuration; + using System.Linq; + using System.Text; + using System.Web; + using System.Web.UI; + using System.Web.UI.WebControls; + using System.Xml.Linq; + using DotNetOpenAuth.ApplicationBlock; + using DotNetOpenAuth.OAuth; -/// <summary> -/// 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"]; } - set { Session["GoogleAccessToken"] = value; } - } + /// <summary> + /// 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"]; } + 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; + 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; + return tokenManager; + } } - } - protected void Page_Load(object sender, EventArgs e) { - if (this.TokenManager != null) { - MultiView1.ActiveViewIndex = 1; + protected void Page_Load(object sender, EventArgs e) { + if (this.TokenManager != null) { + MultiView1.ActiveViewIndex = 1; - if (!IsPostBack) { - var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager); + if (!IsPostBack) { + var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager); - // Is Google calling back with authorization? - var accessTokenResponse = google.ProcessUserAuthorization(); - if (accessTokenResponse != null) { - this.AccessToken = accessTokenResponse.AccessToken; - } else if (this.AccessToken == null) { - // If we don't yet have access, immediately request it. - GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Contacts); + // Is Google calling back with authorization? + var accessTokenResponse = google.ProcessUserAuthorization(); + if (accessTokenResponse != null) { + this.AccessToken = accessTokenResponse.AccessToken; + } else if (this.AccessToken == null) { + // If we don't yet have access, immediately request it. + GoogleConsumer.RequestAuthorization(google, GoogleConsumer.Applications.Contacts); + } } } } - } - protected void getAddressBookButton_Click(object sender, EventArgs e) { - var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager); + protected void getAddressBookButton_Click(object sender, EventArgs e) { + var google = new WebConsumer(GoogleConsumer.ServiceDescription, this.TokenManager); - XDocument contactsDocument = GoogleConsumer.GetContacts(google, this.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 }; - StringBuilder tableBuilder = new StringBuilder(); - tableBuilder.Append("<table><tr><td>Name</td><td>Email</td></tr>"); - foreach (var contact in contacts) { - tableBuilder.AppendFormat( - "<tr><td>{0}</td><td>{1}</td></tr>", - HttpUtility.HtmlEncode(contact.Name), - HttpUtility.HtmlEncode(contact.Email)); + XDocument contactsDocument = GoogleConsumer.GetContacts(google, this.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 }; + StringBuilder tableBuilder = new StringBuilder(); + tableBuilder.Append("<table><tr><td>Name</td><td>Email</td></tr>"); + foreach (var contact in contacts) { + tableBuilder.AppendFormat( + "<tr><td>{0}</td><td>{1}</td></tr>", + HttpUtility.HtmlEncode(contact.Name), + HttpUtility.HtmlEncode(contact.Email)); + } + tableBuilder.Append("</table>"); + resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); } - tableBuilder.Append("</table>"); - resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); } -} +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/GoogleAddressBook.aspx.designer.cs b/samples/OAuthConsumer/GoogleAddressBook.aspx.designer.cs index 053bf3a..64558d5 100644 --- a/samples/OAuthConsumer/GoogleAddressBook.aspx.designer.cs +++ b/samples/OAuthConsumer/GoogleAddressBook.aspx.designer.cs @@ -7,34 +7,36 @@ // </auto-generated> //------------------------------------------------------------------------------ - - -public partial class GoogleAddressBook { - - /// <summary> - /// MultiView1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.MultiView MultiView1; +namespace OAuthConsumer { - /// <summary> - /// getAddressBookButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button getAddressBookButton; - /// <summary> - /// resultsPlaceholder control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.PlaceHolder resultsPlaceholder; + public partial class GoogleAddressBook { + + /// <summary> + /// MultiView1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.MultiView MultiView1; + + /// <summary> + /// getAddressBookButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button getAddressBookButton; + + /// <summary> + /// resultsPlaceholder control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.PlaceHolder resultsPlaceholder; + } } diff --git a/samples/OAuthConsumer/OAuthConsumer.csproj b/samples/OAuthConsumer/OAuthConsumer.csproj index 8063e15..f725ba7 100644 --- a/samples/OAuthConsumer/OAuthConsumer.csproj +++ b/samples/OAuthConsumer/OAuthConsumer.csproj @@ -78,6 +78,9 @@ </None> </ItemGroup> <ItemGroup> + <Compile Include="Global.asax.cs"> + <DependentUpon>Global.asax</DependentUpon> + </Compile> <Compile Include="GoogleAddressBook.aspx.designer.cs"> <DependentUpon>GoogleAddressBook.aspx</DependentUpon> </Compile> diff --git a/samples/OAuthConsumer/SampleWcf.aspx b/samples/OAuthConsumer/SampleWcf.aspx index 84df01b..fb318ce 100644 --- a/samples/OAuthConsumer/SampleWcf.aspx +++ b/samples/OAuthConsumer/SampleWcf.aspx @@ -1,4 +1,4 @@ -<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="SampleWcf" Codebehind="SampleWcf.aspx.cs" %> +<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="OAuthConsumer.SampleWcf" Codebehind="SampleWcf.aspx.cs" %> <asp:Content ID="Content2" ContentPlaceHolderID="Body" runat="Server"> <fieldset title="Authorization"> diff --git a/samples/OAuthConsumer/SampleWcf.aspx.cs b/samples/OAuthConsumer/SampleWcf.aspx.cs index 25e8f55..4055c6c 100644 --- a/samples/OAuthConsumer/SampleWcf.aspx.cs +++ b/samples/OAuthConsumer/SampleWcf.aspx.cs @@ -1,117 +1,119 @@ -using System; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Net; -using System.ServiceModel; -using System.ServiceModel.Channels; -using System.ServiceModel.Security; -using System.Web.UI.WebControls; -using DotNetOpenAuth; -using DotNetOpenAuth.ApplicationBlock; -using DotNetOpenAuth.Messaging; -using DotNetOpenAuth.OAuth; -using DotNetOpenAuth.OAuth.ChannelElements; -using OAuthConsumer.SampleServiceProvider; +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Linq; + using System.Net; + using System.ServiceModel; + using System.ServiceModel.Channels; + using System.ServiceModel.Security; + using System.Web.UI.WebControls; + using DotNetOpenAuth; + using DotNetOpenAuth.ApplicationBlock; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuth; + using DotNetOpenAuth.OAuth.ChannelElements; + using OAuthConsumer.SampleServiceProvider; -/// <summary> -/// Sample consumer of our Service Provider sample's WCF service. -/// </summary> -public partial class SampleWcf : System.Web.UI.Page { - protected void Page_Load(object sender, EventArgs e) { - if (!IsPostBack) { - if (Session["WcfTokenManager"] != null) { - WebConsumer consumer = this.CreateConsumer(); - var accessTokenMessage = consumer.ProcessUserAuthorization(); - if (accessTokenMessage != null) { - Session["WcfAccessToken"] = accessTokenMessage.AccessToken; - authorizationLabel.Text = "Authorized! Access token: " + accessTokenMessage.AccessToken; + /// <summary> + /// Sample consumer of our Service Provider sample's WCF service. + /// </summary> + public partial class SampleWcf : System.Web.UI.Page { + protected void Page_Load(object sender, EventArgs e) { + if (!IsPostBack) { + if (Session["WcfTokenManager"] != null) { + WebConsumer consumer = this.CreateConsumer(); + var accessTokenMessage = consumer.ProcessUserAuthorization(); + if (accessTokenMessage != null) { + Session["WcfAccessToken"] = accessTokenMessage.AccessToken; + authorizationLabel.Text = "Authorized! Access token: " + accessTokenMessage.AccessToken; + } } } } - } - protected void getAuthorizationButton_Click(object sender, EventArgs e) { - WebConsumer consumer = this.CreateConsumer(); - UriBuilder callback = new UriBuilder(Request.Url); - callback.Query = null; - string[] scopes = (from item in scopeList.Items.OfType<ListItem>() - where item.Selected - select item.Value).ToArray(); - string scope = string.Join("|", scopes); - var requestParams = new Dictionary<string, string> { + protected void getAuthorizationButton_Click(object sender, EventArgs e) { + WebConsumer consumer = this.CreateConsumer(); + UriBuilder callback = new UriBuilder(Request.Url); + callback.Query = null; + string[] scopes = (from item in scopeList.Items.OfType<ListItem>() + where item.Selected + select item.Value).ToArray(); + string scope = string.Join("|", scopes); + var requestParams = new Dictionary<string, string> { { "scope", scope }, }; - var response = consumer.PrepareRequestUserAuthorization(callback.Uri, requestParams, null); - consumer.Channel.Send(response); - } - - protected void getNameButton_Click(object sender, EventArgs e) { - try { - nameLabel.Text = CallService(client => client.GetName()); - } catch (SecurityAccessDeniedException) { - nameLabel.Text = "Access denied!"; + var response = consumer.PrepareRequestUserAuthorization(callback.Uri, requestParams, null); + consumer.Channel.Send(response); } - } - protected void getAgeButton_Click(object sender, EventArgs e) { - try { - int? age = CallService(client => client.GetAge()); - ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available"; - } catch (SecurityAccessDeniedException) { - ageLabel.Text = "Access denied!"; + protected void getNameButton_Click(object sender, EventArgs e) { + try { + nameLabel.Text = CallService(client => client.GetName()); + } catch (SecurityAccessDeniedException) { + nameLabel.Text = "Access denied!"; + } } - } - protected void getFavoriteSites_Click(object sender, EventArgs e) { - try { - string[] favoriteSites = CallService(client => client.GetFavoriteSites()); - favoriteSitesLabel.Text = string.Join(", ", favoriteSites); - } catch (SecurityAccessDeniedException) { - favoriteSitesLabel.Text = "Access denied!"; + protected void getAgeButton_Click(object sender, EventArgs e) { + try { + int? age = CallService(client => client.GetAge()); + ageLabel.Text = age.HasValue ? age.Value.ToString(CultureInfo.CurrentCulture) : "not available"; + } catch (SecurityAccessDeniedException) { + ageLabel.Text = "Access denied!"; + } } - } - private T CallService<T>(Func<DataApiClient, T> predicate) { - DataApiClient client = new DataApiClient(); - var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest); - var accessToken = Session["WcfAccessToken"] as string; - if (accessToken == null) { - throw new InvalidOperationException("No access token!"); + protected void getFavoriteSites_Click(object sender, EventArgs e) { + try { + string[] favoriteSites = CallService(client => client.GetFavoriteSites()); + favoriteSitesLabel.Text = string.Join(", ", favoriteSites); + } catch (SecurityAccessDeniedException) { + favoriteSitesLabel.Text = "Access denied!"; + } } - WebConsumer consumer = this.CreateConsumer(); - WebRequest httpRequest = consumer.PrepareAuthorizedRequest(serviceEndpoint, accessToken); - HttpRequestMessageProperty httpDetails = new HttpRequestMessageProperty(); - httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization]; - using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { - OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails; - return predicate(client); - } - } + private T CallService<T>(Func<DataApiClient, T> predicate) { + DataApiClient client = new DataApiClient(); + var serviceEndpoint = new MessageReceivingEndpoint(client.Endpoint.Address.Uri, HttpDeliveryMethods.AuthorizationHeaderRequest | HttpDeliveryMethods.PostRequest); + var accessToken = Session["WcfAccessToken"] as string; + if (accessToken == null) { + throw new InvalidOperationException("No access token!"); + } + WebConsumer consumer = this.CreateConsumer(); + WebRequest httpRequest = consumer.PrepareAuthorizedRequest(serviceEndpoint, accessToken); - private WebConsumer CreateConsumer() { - string consumerKey = "sampleconsumer"; - string consumerSecret = "samplesecret"; - var tokenManager = Session["WcfTokenManager"] as InMemoryTokenManager; - if (tokenManager == null) { - tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); - Session["WcfTokenManager"] = tokenManager; + HttpRequestMessageProperty httpDetails = new HttpRequestMessageProperty(); + httpDetails.Headers[HttpRequestHeader.Authorization] = httpRequest.Headers[HttpRequestHeader.Authorization]; + using (OperationContextScope scope = new OperationContextScope(client.InnerChannel)) { + OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = httpDetails; + return predicate(client); + } } - MessageReceivingEndpoint oauthEndpoint = new MessageReceivingEndpoint( - new Uri("http://localhost:65169/OAuth.ashx"), - HttpDeliveryMethods.PostRequest); - WebConsumer consumer = new WebConsumer( - new ServiceProviderDescription { - RequestTokenEndpoint = oauthEndpoint, - UserAuthorizationEndpoint = oauthEndpoint, - AccessTokenEndpoint = oauthEndpoint, - TamperProtectionElements = new DotNetOpenAuth.Messaging.ITamperProtectionChannelBindingElement[] { + + private WebConsumer CreateConsumer() { + string consumerKey = "sampleconsumer"; + string consumerSecret = "samplesecret"; + var tokenManager = Session["WcfTokenManager"] as InMemoryTokenManager; + if (tokenManager == null) { + tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); + Session["WcfTokenManager"] = tokenManager; + } + MessageReceivingEndpoint oauthEndpoint = new MessageReceivingEndpoint( + new Uri("http://localhost:65169/OAuth.ashx"), + HttpDeliveryMethods.PostRequest); + WebConsumer consumer = new WebConsumer( + new ServiceProviderDescription { + RequestTokenEndpoint = oauthEndpoint, + UserAuthorizationEndpoint = oauthEndpoint, + AccessTokenEndpoint = oauthEndpoint, + TamperProtectionElements = new DotNetOpenAuth.Messaging.ITamperProtectionChannelBindingElement[] { new HmacSha1SigningBindingElement(), }, - }, - tokenManager); + }, + tokenManager); - return consumer; + return consumer; + } } -} +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/SampleWcf.aspx.designer.cs b/samples/OAuthConsumer/SampleWcf.aspx.designer.cs index 79cdbfe..c041338 100644 --- a/samples/OAuthConsumer/SampleWcf.aspx.designer.cs +++ b/samples/OAuthConsumer/SampleWcf.aspx.designer.cs @@ -7,88 +7,90 @@ // </auto-generated> //------------------------------------------------------------------------------ - - -public partial class SampleWcf { - - /// <summary> - /// scopeList control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.CheckBoxList scopeList; - - /// <summary> - /// getAuthorizationButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button getAuthorizationButton; - - /// <summary> - /// authorizationLabel control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Label authorizationLabel; - - /// <summary> - /// getNameButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button getNameButton; - - /// <summary> - /// nameLabel control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Label nameLabel; - - /// <summary> - /// getAgeButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button getAgeButton; - - /// <summary> - /// ageLabel control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Label ageLabel; +namespace OAuthConsumer { - /// <summary> - /// getFavoriteSites control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button getFavoriteSites; - /// <summary> - /// favoriteSitesLabel control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Label favoriteSitesLabel; + public partial class SampleWcf { + + /// <summary> + /// scopeList control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.CheckBoxList scopeList; + + /// <summary> + /// getAuthorizationButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button getAuthorizationButton; + + /// <summary> + /// authorizationLabel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label authorizationLabel; + + /// <summary> + /// getNameButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button getNameButton; + + /// <summary> + /// nameLabel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label nameLabel; + + /// <summary> + /// getAgeButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button getAgeButton; + + /// <summary> + /// ageLabel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label ageLabel; + + /// <summary> + /// getFavoriteSites control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button getFavoriteSites; + + /// <summary> + /// favoriteSitesLabel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label favoriteSitesLabel; + } } diff --git a/samples/OAuthConsumer/SignInWithTwitter.aspx b/samples/OAuthConsumer/SignInWithTwitter.aspx index 5b1624d..86d29a4 100644 --- a/samples/OAuthConsumer/SignInWithTwitter.aspx +++ b/samples/OAuthConsumer/SignInWithTwitter.aspx @@ -1,5 +1,5 @@ <%@ Page Language="C#" AutoEventWireup="true" - Inherits="SignInWithTwitter" Codebehind="SignInWithTwitter.aspx.cs" %> + Inherits="OAuthConsumer.SignInWithTwitter" Codebehind="SignInWithTwitter.aspx.cs" %> <!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"> diff --git a/samples/OAuthConsumer/SignInWithTwitter.aspx.cs b/samples/OAuthConsumer/SignInWithTwitter.aspx.cs index 688471a..9cea1f5 100644 --- a/samples/OAuthConsumer/SignInWithTwitter.aspx.cs +++ b/samples/OAuthConsumer/SignInWithTwitter.aspx.cs @@ -1,37 +1,39 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Web; -using System.Web.Security; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Xml.Linq; -using System.Xml.XPath; -using DotNetOpenAuth.ApplicationBlock; -using DotNetOpenAuth.OAuth; +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Configuration; + using System.Linq; + using System.Web; + using System.Web.Security; + using System.Web.UI; + using System.Web.UI.WebControls; + using System.Xml.Linq; + using System.Xml.XPath; + using DotNetOpenAuth.ApplicationBlock; + using DotNetOpenAuth.OAuth; -public partial class SignInWithTwitter : System.Web.UI.Page { - protected void Page_Load(object sender, EventArgs e) { - if (TwitterConsumer.IsTwitterConsumerConfigured) { - MultiView1.ActiveViewIndex = 1; + public partial class SignInWithTwitter : System.Web.UI.Page { + protected void Page_Load(object sender, EventArgs e) { + if (TwitterConsumer.IsTwitterConsumerConfigured) { + MultiView1.ActiveViewIndex = 1; - if (!IsPostBack) { - string screenName; - int userId; - if (TwitterConsumer.TryFinishSignInWithTwitter(out screenName, out userId)) { - loggedInPanel.Visible = true; - loggedInName.Text = screenName; + if (!IsPostBack) { + string screenName; + int userId; + if (TwitterConsumer.TryFinishSignInWithTwitter(out screenName, out userId)) { + loggedInPanel.Visible = true; + loggedInName.Text = screenName; - // In a real app, the Twitter username would likely be used - // to log the user into the application. - ////FormsAuthentication.RedirectFromLoginPage(screenName, false); + // In a real app, the Twitter username would likely be used + // to log the user into the application. + ////FormsAuthentication.RedirectFromLoginPage(screenName, false); + } } } } - } - protected void signInButton_Click(object sender, ImageClickEventArgs e) { - TwitterConsumer.StartSignInWithTwitter(forceLoginCheckbox.Checked).Send(); + protected void signInButton_Click(object sender, ImageClickEventArgs e) { + TwitterConsumer.StartSignInWithTwitter(forceLoginCheckbox.Checked).Send(); + } } }
\ No newline at end of file diff --git a/samples/OAuthConsumer/SignInWithTwitter.aspx.designer.cs b/samples/OAuthConsumer/SignInWithTwitter.aspx.designer.cs index d515c2a..962a1af 100644 --- a/samples/OAuthConsumer/SignInWithTwitter.aspx.designer.cs +++ b/samples/OAuthConsumer/SignInWithTwitter.aspx.designer.cs @@ -7,79 +7,81 @@ // </auto-generated> //------------------------------------------------------------------------------ - - -public partial class SignInWithTwitter { - - /// <summary> - /// form1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.HtmlControls.HtmlForm form1; - - /// <summary> - /// MultiView1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.MultiView MultiView1; - - /// <summary> - /// View1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.View View1; - - /// <summary> - /// View2 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.View View2; - - /// <summary> - /// signInButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.ImageButton signInButton; - - /// <summary> - /// forceLoginCheckbox control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.CheckBox forceLoginCheckbox; +namespace OAuthConsumer { - /// <summary> - /// loggedInPanel control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Panel loggedInPanel; - /// <summary> - /// loggedInName control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Label loggedInName; + public partial class SignInWithTwitter { + + /// <summary> + /// form1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// <summary> + /// MultiView1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.MultiView MultiView1; + + /// <summary> + /// View1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.View View1; + + /// <summary> + /// View2 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.View View2; + + /// <summary> + /// signInButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.ImageButton signInButton; + + /// <summary> + /// forceLoginCheckbox control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.CheckBox forceLoginCheckbox; + + /// <summary> + /// loggedInPanel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Panel loggedInPanel; + + /// <summary> + /// loggedInName control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label loggedInName; + } } diff --git a/samples/OAuthConsumer/TracePage.aspx b/samples/OAuthConsumer/TracePage.aspx index 1b686db..d3539fb 100644 --- a/samples/OAuthConsumer/TracePage.aspx +++ b/samples/OAuthConsumer/TracePage.aspx @@ -1,4 +1,4 @@ -<%@ Page Language="C#" AutoEventWireup="true" Inherits="TracePage" Codebehind="TracePage.aspx.cs" %> +<%@ Page Language="C#" AutoEventWireup="true" Inherits="OAuthConsumer.TracePage" Codebehind="TracePage.aspx.cs" %> <!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"> diff --git a/samples/OAuthConsumer/TracePage.aspx.cs b/samples/OAuthConsumer/TracePage.aspx.cs index 7075ce3..b9ca260 100644 --- a/samples/OAuthConsumer/TracePage.aspx.cs +++ b/samples/OAuthConsumer/TracePage.aspx.cs @@ -1,21 +1,23 @@ -using System; -using System.Collections.Generic; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Web; + using System.Web.UI; + using System.Web.UI.WebControls; -/// <summary> -/// A page to display recent log messages. -/// </summary> -public partial class TracePage : System.Web.UI.Page { - protected void Page_Load(object sender, EventArgs e) { - this.placeHolder1.Controls.Add(new Label { Text = HttpUtility.HtmlEncode(Logging.LogMessages.ToString()) }); - } + /// <summary> + /// A page to display recent log messages. + /// </summary> + public partial class TracePage : System.Web.UI.Page { + protected void Page_Load(object sender, EventArgs e) { + this.placeHolder1.Controls.Add(new Label { Text = HttpUtility.HtmlEncode(Logging.LogMessages.ToString()) }); + } - protected void clearLogButton_Click(object sender, EventArgs e) { - Logging.LogMessages.Length = 0; + protected void clearLogButton_Click(object sender, EventArgs e) { + Logging.LogMessages.Length = 0; - // clear the page immediately, and allow for F5 without a Postback warning. - Response.Redirect(Request.Url.AbsoluteUri); + // clear the page immediately, and allow for F5 without a Postback warning. + Response.Redirect(Request.Url.AbsoluteUri); + } } -} +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/TracePage.aspx.designer.cs b/samples/OAuthConsumer/TracePage.aspx.designer.cs index 6a0028b..73184b5 100644 --- a/samples/OAuthConsumer/TracePage.aspx.designer.cs +++ b/samples/OAuthConsumer/TracePage.aspx.designer.cs @@ -7,34 +7,36 @@ // </auto-generated> //------------------------------------------------------------------------------ - - -public partial class TracePage { - - /// <summary> - /// form1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.HtmlControls.HtmlForm form1; +namespace OAuthConsumer { - /// <summary> - /// clearLogButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button clearLogButton; - /// <summary> - /// placeHolder1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.PlaceHolder placeHolder1; + public partial class TracePage { + + /// <summary> + /// form1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.HtmlControls.HtmlForm form1; + + /// <summary> + /// clearLogButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button clearLogButton; + + /// <summary> + /// placeHolder1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.PlaceHolder placeHolder1; + } } diff --git a/samples/OAuthConsumer/Twitter.aspx b/samples/OAuthConsumer/Twitter.aspx index f52f624..a24c7bd 100644 --- a/samples/OAuthConsumer/Twitter.aspx +++ b/samples/OAuthConsumer/Twitter.aspx @@ -1,4 +1,4 @@ -<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="Twitter" Codebehind="Twitter.aspx.cs" %> +<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" Inherits="OAuthConsumer.Twitter" Codebehind="Twitter.aspx.cs" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server"> </asp:Content> diff --git a/samples/OAuthConsumer/Twitter.aspx.cs b/samples/OAuthConsumer/Twitter.aspx.cs index f309396..44350ca 100644 --- a/samples/OAuthConsumer/Twitter.aspx.cs +++ b/samples/OAuthConsumer/Twitter.aspx.cs @@ -1,94 +1,96 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Text; -using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; -using System.Xml.Linq; -using System.Xml.XPath; -using DotNetOpenAuth.ApplicationBlock; -using DotNetOpenAuth.OAuth; +namespace OAuthConsumer { + using System; + using System.Collections.Generic; + using System.Configuration; + using System.Linq; + using System.Text; + using System.Web; + using System.Web.UI; + using System.Web.UI.WebControls; + using System.Xml.Linq; + using System.Xml.XPath; + using DotNetOpenAuth.ApplicationBlock; + using DotNetOpenAuth.OAuth; -public partial class Twitter : System.Web.UI.Page { - private string AccessToken { - get { return (string)Session["TwitterAccessToken"]; } - set { Session["TwitterAccessToken"] = value; } - } + public partial class Twitter : System.Web.UI.Page { + private string AccessToken { + get { return (string)Session["TwitterAccessToken"]; } + set { Session["TwitterAccessToken"] = value; } + } - private InMemoryTokenManager TokenManager { - get { - var tokenManager = (InMemoryTokenManager)Application["TwitterTokenManager"]; - if (tokenManager == null) { - string consumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; - string consumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; - if (!string.IsNullOrEmpty(consumerKey)) { - tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); - Application["TwitterTokenManager"] = tokenManager; + private InMemoryTokenManager TokenManager { + get { + var tokenManager = (InMemoryTokenManager)Application["TwitterTokenManager"]; + if (tokenManager == null) { + string consumerKey = ConfigurationManager.AppSettings["twitterConsumerKey"]; + string consumerSecret = ConfigurationManager.AppSettings["twitterConsumerSecret"]; + if (!string.IsNullOrEmpty(consumerKey)) { + tokenManager = new InMemoryTokenManager(consumerKey, consumerSecret); + Application["TwitterTokenManager"] = tokenManager; + } } - } - return tokenManager; + return tokenManager; + } } - } - protected void Page_Load(object sender, EventArgs e) { - if (this.TokenManager != null) { - MultiView1.ActiveViewIndex = 1; + protected void Page_Load(object sender, EventArgs e) { + if (this.TokenManager != null) { + MultiView1.ActiveViewIndex = 1; - if (!IsPostBack) { - var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager); + if (!IsPostBack) { + var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager); - // Is Twitter calling back with authorization? - var accessTokenResponse = twitter.ProcessUserAuthorization(); - if (accessTokenResponse != null) { - this.AccessToken = accessTokenResponse.AccessToken; - } else if (this.AccessToken == null) { - // If we don't yet have access, immediately request it. - twitter.Channel.Send(twitter.PrepareRequestUserAuthorization()); + // Is Twitter calling back with authorization? + var accessTokenResponse = twitter.ProcessUserAuthorization(); + if (accessTokenResponse != null) { + this.AccessToken = accessTokenResponse.AccessToken; + } else if (this.AccessToken == null) { + // If we don't yet have access, immediately request it. + twitter.Channel.Send(twitter.PrepareRequestUserAuthorization()); + } } } } - } - protected void downloadUpdates_Click(object sender, EventArgs e) { - var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager); - XPathDocument updates = new XPathDocument(TwitterConsumer.GetUpdates(twitter, this.AccessToken).CreateReader()); - XPathNavigator nav = updates.CreateNavigator(); - var parsedUpdates = from status in nav.Select("/statuses/status").OfType<XPathNavigator>() - where !status.SelectSingleNode("user/protected").ValueAsBoolean - select new { - User = status.SelectSingleNode("user/name").InnerXml, - Status = status.SelectSingleNode("text").InnerXml, - }; + protected void downloadUpdates_Click(object sender, EventArgs e) { + var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager); + XPathDocument updates = new XPathDocument(TwitterConsumer.GetUpdates(twitter, this.AccessToken).CreateReader()); + XPathNavigator nav = updates.CreateNavigator(); + var parsedUpdates = from status in nav.Select("/statuses/status").OfType<XPathNavigator>() + where !status.SelectSingleNode("user/protected").ValueAsBoolean + select new { + User = status.SelectSingleNode("user/name").InnerXml, + Status = status.SelectSingleNode("text").InnerXml, + }; - StringBuilder tableBuilder = new StringBuilder(); - tableBuilder.Append("<table><tr><td>Name</td><td>Update</td></tr>"); + StringBuilder tableBuilder = new StringBuilder(); + tableBuilder.Append("<table><tr><td>Name</td><td>Update</td></tr>"); - foreach (var update in parsedUpdates) { - tableBuilder.AppendFormat( - "<tr><td>{0}</td><td>{1}</td></tr>", - HttpUtility.HtmlEncode(update.User), - HttpUtility.HtmlEncode(update.Status)); + foreach (var update in parsedUpdates) { + tableBuilder.AppendFormat( + "<tr><td>{0}</td><td>{1}</td></tr>", + HttpUtility.HtmlEncode(update.User), + HttpUtility.HtmlEncode(update.Status)); + } + tableBuilder.Append("</table>"); + resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); } - tableBuilder.Append("</table>"); - resultsPlaceholder.Controls.Add(new Literal { Text = tableBuilder.ToString() }); - } - protected void uploadProfilePhotoButton_Click(object sender, EventArgs e) { - if (profilePhoto.PostedFile.ContentType == null) { + protected void uploadProfilePhotoButton_Click(object sender, EventArgs e) { + if (profilePhoto.PostedFile.ContentType == null) { + photoUploadedLabel.Visible = true; + photoUploadedLabel.Text = "Select a file first."; + return; + } + + var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager); + XDocument imageResult = TwitterConsumer.UpdateProfileImage( + twitter, + this.AccessToken, + profilePhoto.PostedFile.InputStream, + profilePhoto.PostedFile.ContentType); photoUploadedLabel.Visible = true; - photoUploadedLabel.Text = "Select a file first."; - return; } - - var twitter = new WebConsumer(TwitterConsumer.ServiceDescription, this.TokenManager); - XDocument imageResult = TwitterConsumer.UpdateProfileImage( - twitter, - this.AccessToken, - profilePhoto.PostedFile.InputStream, - profilePhoto.PostedFile.ContentType); - photoUploadedLabel.Visible = true; } -} +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/Twitter.aspx.designer.cs b/samples/OAuthConsumer/Twitter.aspx.designer.cs index 10938cd..7c37271 100644 --- a/samples/OAuthConsumer/Twitter.aspx.designer.cs +++ b/samples/OAuthConsumer/Twitter.aspx.designer.cs @@ -7,70 +7,72 @@ // </auto-generated> //------------------------------------------------------------------------------ - - -public partial class Twitter { - - /// <summary> - /// MultiView1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.MultiView MultiView1; - - /// <summary> - /// View1 control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.View View1; - - /// <summary> - /// profilePhoto control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.FileUpload profilePhoto; - - /// <summary> - /// uploadProfilePhotoButton control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button uploadProfilePhotoButton; - - /// <summary> - /// photoUploadedLabel control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Label photoUploadedLabel; +namespace OAuthConsumer { - /// <summary> - /// downloadUpdates control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.Button downloadUpdates; - /// <summary> - /// resultsPlaceholder control. - /// </summary> - /// <remarks> - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// </remarks> - protected global::System.Web.UI.WebControls.PlaceHolder resultsPlaceholder; + public partial class Twitter { + + /// <summary> + /// MultiView1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.MultiView MultiView1; + + /// <summary> + /// View1 control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.View View1; + + /// <summary> + /// profilePhoto control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.FileUpload profilePhoto; + + /// <summary> + /// uploadProfilePhotoButton control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button uploadProfilePhotoButton; + + /// <summary> + /// photoUploadedLabel control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Label photoUploadedLabel; + + /// <summary> + /// downloadUpdates control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.Button downloadUpdates; + + /// <summary> + /// resultsPlaceholder control. + /// </summary> + /// <remarks> + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// </remarks> + protected global::System.Web.UI.WebControls.PlaceHolder resultsPlaceholder; + } } diff --git a/samples/OAuthConsumer/Web.config b/samples/OAuthConsumer/Web.config index cad6ef2..5e96705 100644 --- a/samples/OAuthConsumer/Web.config +++ b/samples/OAuthConsumer/Web.config @@ -149,7 +149,7 @@ </assemblyBinding> </runtime> <log4net> - <appender name="TracePageAppender" type="TracePageAppender, OAuthConsumer"> + <appender name="TracePageAppender" type="OAuthConsumer.TracePageAppender, OAuthConsumer"> <layout type="log4net.Layout.PatternLayout"> <conversionPattern value="%date (GMT%date{%z}) [%thread] %-5level %logger - %message%newline" /> </layout> |