diff options
Diffstat (limited to 'samples/OAuthConsumer')
-rw-r--r-- | samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs | 54 | ||||
-rw-r--r-- | samples/OAuthConsumer/Default.aspx | 1 | ||||
-rw-r--r-- | samples/OAuthConsumer/SampleWcf.aspx.cs | 1 | ||||
-rw-r--r-- | samples/OAuthConsumer/SignInWithTwitter.aspx | 38 | ||||
-rw-r--r-- | samples/OAuthConsumer/SignInWithTwitter.aspx.cs | 37 | ||||
-rw-r--r-- | samples/OAuthConsumer/images/Sign-in-with-Twitter-darker.png | bin | 0 -> 2370 bytes |
6 files changed, 77 insertions, 54 deletions
diff --git a/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs b/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs deleted file mode 100644 index 120f00a..0000000 --- a/samples/OAuthConsumer/App_Code/InMemoryTokenManager.cs +++ /dev/null @@ -1,54 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="InMemoryTokenManager.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using DotNetOpenAuth.OAuth.ChannelElements; -using DotNetOpenAuth.OAuth.Messages; - -public class InMemoryTokenManager : IConsumerTokenManager { - private Dictionary<string, string> tokensAndSecrets = new Dictionary<string, string>(); - - public InMemoryTokenManager(string consumerKey, string consumerSecret) { - if (String.IsNullOrEmpty(consumerKey)) { - throw new ArgumentNullException("consumerKey"); - } - - this.ConsumerKey = consumerKey; - this.ConsumerSecret = consumerSecret; - } - - public string ConsumerKey { get; private set; } - - public string ConsumerSecret { get; private set; } - - #region ITokenManager Members - - public string GetTokenSecret(string token) { - return this.tokensAndSecrets[token]; - } - - public void StoreNewRequestToken(UnauthorizedTokenRequest request, ITokenSecretContainingMessage response) { - this.tokensAndSecrets[response.Token] = response.TokenSecret; - } - - public void ExpireRequestTokenAndStoreNewAccessToken(string consumerKey, string requestToken, string accessToken, string accessTokenSecret) { - this.tokensAndSecrets.Remove(requestToken); - this.tokensAndSecrets[accessToken] = accessTokenSecret; - } - - /// <summary> - /// Classifies a token as a request token or an access token. - /// </summary> - /// <param name="token">The token to classify.</param> - /// <returns>Request or Access token, or invalid if the token is not recognized.</returns> - public TokenType GetTokenType(string token) { - throw new NotImplementedException(); - } - - #endregion -} diff --git a/samples/OAuthConsumer/Default.aspx b/samples/OAuthConsumer/Default.aspx index aa4ef79..c952877 100644 --- a/samples/OAuthConsumer/Default.aspx +++ b/samples/OAuthConsumer/Default.aspx @@ -8,6 +8,7 @@ <ul> <li><a href="GoogleAddressBook.aspx">Download your Gmail address book</a></li> <li><a href="Twitter.aspx">Get your Twitter updates</a></li> + <li><a href="SignInWithTwitter.aspx">Sign In With Twitter</a></li> <li><a href="SampleWcf.aspx">Interop with Service Provider sample using WCF w/ OAuth</a></li> </ul> </asp:Content> diff --git a/samples/OAuthConsumer/SampleWcf.aspx.cs b/samples/OAuthConsumer/SampleWcf.aspx.cs index 7572dd8..d1af6a1 100644 --- a/samples/OAuthConsumer/SampleWcf.aspx.cs +++ b/samples/OAuthConsumer/SampleWcf.aspx.cs @@ -8,6 +8,7 @@ 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; diff --git a/samples/OAuthConsumer/SignInWithTwitter.aspx b/samples/OAuthConsumer/SignInWithTwitter.aspx new file mode 100644 index 0000000..b1dd606 --- /dev/null +++ b/samples/OAuthConsumer/SignInWithTwitter.aspx @@ -0,0 +1,38 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SignInWithTwitter.aspx.cs" + Inherits="SignInWithTwitter" %> + +<!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>Sign-in with Twitter</title> +</head> +<body> + <form id="form1" runat="server"> + <div> + <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0"> + <asp:View ID="View1" runat="server"> + <h2> + Twitter setup</h2> + <p> + A Twitter client app must be endorsed by a Twitter user. + </p> + <ol> + <li><a target="_blank" href="https://twitter.com/oauth_clients">Visit Twitter and create + a client app</a>. </li> + <li>Modify your web.config file to include your consumer key and consumer secret.</li> + </ol> + </asp:View> + <asp:View ID="View2" runat="server"> + <asp:ImageButton ImageUrl="~/images/Sign-in-with-Twitter-darker.png" runat="server" + AlternateText="Sign In With Twitter" ID="signInButton" OnClick="signInButton_Click" /> + <asp:CheckBox Text="force re-login" runat="server" ID="forceLoginCheckbox" /> + <br /> + <asp:Panel runat="server" ID="loggedInPanel" Visible="false"> + Now logged in as + <asp:Label Text="[name]" runat="server" ID="loggedInName" /> + </asp:Panel> + </asp:View> + </asp:MultiView> + </form> +</body> +</html> diff --git a/samples/OAuthConsumer/SignInWithTwitter.aspx.cs b/samples/OAuthConsumer/SignInWithTwitter.aspx.cs new file mode 100644 index 0000000..688471a --- /dev/null +++ b/samples/OAuthConsumer/SignInWithTwitter.aspx.cs @@ -0,0 +1,37 @@ +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; + + 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); + } + } + } + } + + protected void signInButton_Click(object sender, ImageClickEventArgs e) { + TwitterConsumer.StartSignInWithTwitter(forceLoginCheckbox.Checked).Send(); + } +}
\ No newline at end of file diff --git a/samples/OAuthConsumer/images/Sign-in-with-Twitter-darker.png b/samples/OAuthConsumer/images/Sign-in-with-Twitter-darker.png Binary files differnew file mode 100644 index 0000000..746b6b9 --- /dev/null +++ b/samples/OAuthConsumer/images/Sign-in-with-Twitter-darker.png |