I wrote OAuth for this manager because the existing options were too complex.
OAuth with validation in .NET
The class focuses on OAuth and works specifically with Twitter. This is not a class that provides a ton of methods for the entire surface of the Twitter web API. This is just OAuth. If you want to update the status on Twitter, this class does not provide the "UpdateStatus" method. I decided that application developers just needed to build the HTTP message that they want to send. In other words, an HTTP message is an API. But OAuth stuff can get a little complicated, so it deserves an API, which is an OAuth class.
Here's an example code for requesting a “request token”:
var oauth = new OAuth.Manager(); oauth["consumer_key"] = MY_APP_SPECIFIC_CONSUMER_KEY; oauth["consumer_secret"] = MY_APP_SPECIFIC_CONSUMER_SECRET; oauth.AcquireRequestToken(SERVICE_SPECIFIC_REQUEST_TOKEN_URL, "POST");
THIS . On Twitter, the request url for tokens related to services is " https://api.twitter.com/oauth/request_token ".
Once you receive the request token, you will choose a web browser user interface in which the user will explicitly give you approval for your application to access Twitter. You need to do this once, the first time you launch the application. Do this in the built-in WebBrowser control with the following code:
var url = SERVICE_SPECIFIC_AUTHORIZE_URL_STUB + oauth["token"]; webBrowser1.Url = new Uri(url);
For Twitter, the URL for this is: https://api.twitter.com/oauth/authorize?oauth_token= "with the addition of oauth_token.
Take the pin from the web browser user interface using some screenshots of the HTML screen. Then request the "access token":
oauth.AcquireAccessToken(URL_ACCESS_TOKEN, "POST", pin);
For Twitter, this URL is " https://api.twitter.com/oauth/access_token ".
You do not need to explicitly handle the access token; the OAuthManager class keeps it in a state for you. But tokens and a secret are available in oauth["token"] and oauth["token_secret"] if you want to write them to persistent storage. To make requests with this access token, generate the authz header as follows:
var authzHeader = oauth.GenerateAuthzHeader(url, "POST");
... where url is the endpoint of the resource. To update the status of a user on Twitter, it will be " http://api.twitter.com/1/statuses/update.xml?status=Hello ".
Then set the resulting string to the HTTP header named Authorization and send the HTTP request to the URL.
In subsequent runs, when you already have an access token and a secret, you can create an OAuth.Manager instance as follows:
var oauth = new OAuth.Manager(); oauth["consumer_key"] = MY_APP_SPECIFIC_CONSUMER_KEY; oauth["consumer_secret"] = MY_APP_SPECIFIC_CONSUMER_SECRET; oauth["token"] = your_stored_access_token; oauth["token_secret"] = your_stored_access_secret;
Then just generate the authz header and execute your queries as described above.
Download DLL
Browse Documentation