Twitter OAuth With C#/.NET Code


Published on

Published in: Design, Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Twitter OAuth With C#/.NET Code

  1. 1. Twitter OauthAnd .Net Code<br />Mohamed Meligy<br /><br /><br />
  2. 2. Application Registration<br />A Twitter user creates a Twitter Application<br />If the application is web based, it needs to provide a URL. “Localhost” is not accepted as a domain for this URL<br />A Twitter Application gets two pieces of information<br />Consumer Key<br />Consumer Secret<br />A Twitter Application will use these in all coming requests.<br />
  3. 3. Initializing The Process<br />User comes to the application and it decides to authenticate against Twitter<br />Application makes a request using Consumer Key and Secret to obtain “Oauth Request Token”, which consists of two parts<br />Token<br />Token Secret<br />Application makes authentication URL including the “Oauth Request Token” parameter, and optionally a “Call-back URL” (if different than default URL in first step)<br />
  4. 4. User Authentication<br />The user is redirected to Twitter, the URL contains the “Oauth Request” to identify application authentication session<br />Assuming the Twitter User being logged in and authorizes the Application<br />If the application is a desktop application, Twitter gives the a user a number “Verifier” to manually write back to the application<br />If the application is a web application, the user is redirected back to the application call-back URL with a complex “Verifier” parameter in the URL<br />
  5. 5. Obtaining the Access Token<br />The Application makes a request to Twitter including the “Oauth Request Token” and the “Verifier”<br />It obtains an “Access Token”, likewise it consists of two-parts:<br />Token<br />Token Secret<br />The application needs to send the Consumer Key and Secret and Access Token in every future request that needs the Twitter User privileges<br />
  6. 6. Caching Credentials<br />The application needs at least one authorization process as before<br />The Access Token returned can be saved in session/DB/whatever and then re-used later<br />The application can later use the Access Token directly along with the Consumer Key / Secret to communicate with Twitter without going through any of the previous steps<br />
  7. 7. Sample Code<br />TweetSharp v 2.0<br />
  8. 8. Request Token & Redirect<br />
  9. 9. Getting Access Token<br />
  10. 10. Hints for Web Applications<br />The method GetAuthenticationUrl() has an overload that accepts a call-back URL for the user to be redirected to after obtaining verifer<br />The important part in RequestToken is the Token part, not the secret.<br />All parts of AccessToken are important and required<br />When the user is redirected back from Twitter to your application, you get the following QueryString parameters sent to you<br />oauth_token: The Token part of the Request Token<br />oauth_verifier: The verifier required to obtain the Access Token later<br />
  11. 11. Using Cached Access Token<br />
  12. 12. Related Links<br />More Content Like This<br /><br />Twitter Developers Site<br /><br />TweetSharp<br /><br />Questions / Suggestions?<br /><br /><br /><br />