Twitter OAuth library for .net apps,
To Install:
Install-Package TwitterOAuth
Add following configuration to appSettings below web.config file
<add key="Tw-ApiKey" value="your consumer key here"/>
<add key="Tw-AppSecret" value="your consumer secret here"/>
<add key="Tw-RedirectUri" value="your redirected uri here"/>
- Setup Authentication Link (Button)
Markup
<a href='http://twitter.com/oauth/authorize?<%=GetUrlParamters()%>'>Login with Twitter</a>
Code Behind
protected string GetUrlParamters()
{
ITwitterOAuthManager oAuthManager = new TwitterOAuthManager();
return oAuthManager.GetUrlParameters();
}
- After Twitter redirected to referrer url, Redirected page code behind
protected void Page_Load(object sender, EventArgs e)
{
ITwitterOAuthManager oAuthManager = new TwitterOAuthManager();
if (oAuthManager.CheckTwitterOAuthRequest(Request.QueryString))
{
TwitterBasicProfile result = oAuthManager.Authenticate(Request.QueryString);
txtHtmlArea.InnerHtml = Server.HtmlEncode(result.ScreenName);
}
}
Redirected page markup
<div id="txtHtmlArea" runat="server"></div>