This is a mirror of official site: http://jasper-net.blogspot.com/

Twitter OAuth authentication using .Net

| Wednesday, August 31, 2011
dev-bird.gif

Introduction

In this article I want to demonstrate how to implement OAuth authentication in .Net. I've previously written about my dislike of third party SDKs for social media integration and how we should leverage technology based solutions instead. One of the sticking points in doing this tends to be that implementing OAuth based authentication is relatively difficult compared with actually making the requests themselves. There is documentation available, but there seems to be a lack of .NET example code to go with it.

In keeping with my thoughts in previous articles I would recommend using open source OAuth based libraries to solve this problem, and again avoid resorting to third party Twitter/Facebook implementations which more strongly couple code to specific APIs. This keeps the solution more reusable and builds on specific technologies to better future proof your application.

I've also previously shown how client-side plugins can be used in combination with server-side code to speed development in this area. However sometimes authentication does need to be implemented purely on the server-side.

So how difficult is this?

It turns out implementing OAuth on the server-side in .Net isn't too difficult, the battle is getting the encoding and authentication signature right. With so few examples it can be a little daunting, so here's an example written in pure .NET using the official Twitter OAuth documentation and a bit of trial and error.


Background

The following example shows how to authenticate against the Twitter APIs using a registered Twitter application. Any interaction with the APIs when authenticated in this manner will behave as if coming from the Twitter account under which the application has been registered. It's therefore useful for sending out status updates or sending out notifications from a specific account.

Usually OAuth requires redirecting the user to a login screen to obtain an oAuth token which requires a bit more work. However when authenticating via a Twitter application this step is skipped as your application already has an oAuth token provided (access token). Whether you are using the application oAuth token or a user oAuth token, the following code can be used to authenticate against the twitter APIs.


The Code

The first step is to visit the Twitter developer section and register a new application. On completion you will be provided with a set of public/private keys which you will need the replace in the example below in order to run. The values I have used directly correspond with the documented example here. Make sure you replace them with your own.

var oauth_token           = "819797-Jxq8aYUDRmykzVKrgoLhXSq67TEa5ruc4GJC2rWimw";
var oauth_token_secret    = "J6zix3FfA9LofH0awS24M3HcBYXO5nI1iYe8EfBA";
var oauth_consumer_key    = "GDdmIQH6jhtmLUypg82g";
var oauth_consumer_secret = "MCD8BKwGdgPHvAuvgvz4EQpqDAtx89grbuNMRd7Eh98";


Read more: Codeproject
QR: TwitterOAuth.aspx

Posted via email from Jasper-net

17 comments:

Anonymous said...

I will immediately grab your rss feed as I can not to find your email
subscription link or newsletter service. Do you've any? Kindly allow me know so that I could subscribe. Thanks.

Also visit my web-site :: Natural Cleanse Review

Anonymous said...

Some bodies have a high burn rate of calories, which prevents them
from accumulating fat. Humans, naturally, do not like
bitter flavors or foods. The reason is that too often people consume too much protein at one time and most of it goes to waste.


Here is my page :: Order Power Pump XL

Anonymous said...

Thank you for the good writeup. It in fact was a amusement account it.

Look advanced to far added agreeable from you!
By the way, how can we communicate?

Here is my weblog; 365 day loan

Anonymous said...

I like what you guys are up too. This sort of
clever work and coverage! Keep up the very good works guys I've added you guys to my own blogroll.

Visit my blog :: Xength X1 Male Enhancement

Anonymous said...

Thanks for finally writing about > "Twitter OAuth authentication using .Net" < Loved it!

Take a look at my site ... garcinia cambogia where to
but

Anonymous said...

Hey there this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with HTML.
I'm starting a blog soon but have no coding experience so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

My homepage - Ultra Celeb Diet Review

Anonymous said...

This is very fascinating, You're a very skilled blogger. I've joined your feed and
look forward to looking for more of your great post.

Additionally, I've shared your web site in my social networks

Look at my site ... Cambogia Trim Diet

Anonymous said...

I enjoy, cause I found exactly what I was having a look for.
You have ended my four day long hunt! God Bless you man.
Have a great day. Bye

Here is my homepage - Saffron X Diet

Anonymous said...

Thanks for another excellent article. Where else may anybody get that kind of info
in such an ideal way of writing? I have a presentation
next week, and I am at the search for such info.

Feel free to visit my site Acai Ultra Lean Diet - -

Anonymous said...

Hey! This post could not be written any better! Reading through
this post reminds me of my old room mate! He always kept chatting about this.
I will forward this article to him. Pretty sure he will
have a good read. Thanks for sharing!

pure Garcinia Cambogia ()

Anonymous said...

What's Going down i'm new to this, I stumbled upon this I've found It positively helpful and it has aided me out loads. I'm hoping to
give a contribution & help other users like its
aided me. Good job.

Look into my blog Lift and glow pro review

Anonymous said...

My spouse and I stumbled over here coming from a different web address and thought I
might as well check things out. I like what I see so now i'm following you. Look forward to going over your web page again.

my weblog Weight lose

Anonymous said...

Please let me know if you're looking for a article author for your weblog. You have some really great articles and I believe I would be a good asset. If you ever want to take some of the load off, I'd love to write some
articles for your blog in exchange for a link back to mine.
Please shoot me an email if interested. Thanks!


Enduros Male Enhancement Free Trial

Anonymous said...

Hi, I do believe your website might be having
browser compatibility problems. When I look at your website in Safari,
it looks fine however, if opening in IE, it's got some overlapping
issues. I merely wanted to give you a quick heads up!
Other than that, great website!

Have a look at my web page: CSR Racing Cheats

Anonymous said...

Hi, i believe that i noticed you visited my site so i came to go back the choose?.I
am attempting to to find issues to enhance my web site!I guess its ok to make use of a few of your concepts!!


Also visit my page; http://cambogiahca.com/

Anonymous said...

Hey There. I found your blog using msn. This is an extremely well written article.
I'll be suyre to bookmark it and come back
to read more of your useful information. Thanks for the post.
I'll certainly return.

my blog :: Quality Flooring Atlanta

Anonymous said...

This piece of writing is genuinely a good one it assists new internet people,
who are wishing for blogging.

Here is my web site - voyage au costa rica blogspot