A recent project at work lead me to develop a lightweight C# Oauth Consumer class to call an OAuth API from a Microsoft Office addin.
Oauth is “an open protocol to allow secure API authorization in a simple and standard method from desktop and web applications”. A lot of documentation, and the specification, about the OAuth protocol can be found on oauth.net.
I personally read
- Twitter’s introduction to Oauth
- Lorna Jane Mitchell’s introduction on ThinkVitamin
- and glimpsed at the specification on oauth.net a few times
The first thing I did was to look for an existing class on aouth.net but everything seemed to be an overkill for my project so, using the Zend::OAuth package as a guideline for my architecture, I set out to develop my own. A fellow developer also gave me some sample code he used on his own project which included a modified version of Tim Pinkawa‘s OAuthBase.cs class. My thanks to them for their help with this library.
In order to make sharpOauth a valuable library to share with other developers, I wanted to add code samples illustrating its usage. I wrote two
- sample1_twitterClient is a code sample for a desktop or mobile application which will use the pincode system to validate the authorization process. I also added in this sample, an example of use of the unique access token provided by twitter when one creates an application to bypass the authorization process.
- sample2_twitterWeb is a asp .net web application sample which will prompt twitter, upon valid authorization, to redirect to the callback Url defined in the settings.
I hope the code and samples are documented enough to where anyone can download the library and start using it in his/her own OAuth projects. The library can be found on my GitHub page in the sharpOauth repository. Code away and don’t hesitate to comment or submit improvements to the code.