Posts Tagged Linkedin
LinkedIn OAuth using Hammock in C# & ASP.NET
Posted by suddenelfilio in .net, Web & Design, Web Services on 24/08/2010
UPDATE: Hammock moved to github https://github.com/danielcrenna/hammock
Codeplex.com description of Hammock:
Hammock is a REST library for .NET that greatly simplifies consuming and wrapping RESTful services.

I’m currently working on a little web project that needed integration with LinkedIn.com. The LinkedIn API allows for OAuth authorization and authentication. They describe the process of getting a request token, authorizing it by the user and then getting an access token. Standard OAuth you might say. So I needed a way to do this in C# and found the Hammock library. Although Hammock does not only do OAuth I used it for that purpose only at the moment.
Below is the code I wrote to get a request token and send the user to the authorization page at Linkedin:
public void RequestAndAuthorize()
{
var credentials = new OAuthCredentials
{
CallbackUrl = "http://127.0.0.1/oauth/callback/",
ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"],
Verifier = "123456",
Type = OAuthType.RequestToken
};
var client = new RestClient { Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials };
var request = new RestRequest { Path = "requestToken" };
RestResponse response = client.Request(request);
string token = response.Content.Split('&').Where(s => s.StartsWith("oauth_token=")).Single().Split('=')[1];
string token_secret = response.Content.Split('&').Where(s => s.StartsWith("oauth_token_secret=")).Single().Split('=')[1];
Response.Redirect("https://api.linkedin.com/uas/oauth?oauth_token=" + token);
}
Once the user has authorized your request token the LinkedIn server will redirect the user back to the callback url in this case this is http://127.0.0.1/oauth/callback. Using the returned oauth_token and oauth_token_secret (you got this one while requesting a request token) you can now get an access token so you can start making authenticated API calls from you application on behalf of the user.
This is the code that is used when the callback url is called:
public void Callback()
{
var credentials = new OAuthCredentials
{
ConsumerKey = ConfigurationManager.AppSettings["ConsumerKey"],
ConsumerSecret = ConfigurationManager.AppSettings["ConsumerSecret"],
Token = token,
TokenSecret = token_secret,
Verifier = verifier,
Type = OAuthType.AccessToken,
ParameterHandling = OAuthParameterHandling.HttpAuthorizationHeader,
SignatureMethod = OAuthSignatureMethod.HmacSha1,
Version = "1.0"
};
var client = new RestClient { Authority = "https://api.linkedin.com/uas/oauth", Credentials = credentials, Method = WebMethod.Post };
var request = new RestRequest { Path = "accessToken" };
RestResponse response = client.Request(request);
string content = response.Content;
}
As you can see Hammock is really nice and allows for easy OAuth authentication/authorization to be used.
Outlook Social Connector for LinkedIn
Posted by suddenelfilio in .net, Windows on 25/02/2010
The social networking site LinkedIn released their Outlook Social Connector for Microsoft Outlook. Something that was new to me is that OSC is not an office 2010 feature anymore because it is possible to download osc for outlook 2007 and 2003 so you can use the osc connecters in the ‘older’ versions of ms outlook as well. Very nice move I think.
To download the LinkedIn outlook social connector go to: http://www.linkedin.com/outlook

