Wednesday, November 28, 2012

LinkedIn REST URL (Step 2 - Obtain Authorization)

Hello again,

I wrote about how to obtain a request token for LinkedIn yesterday.
For those of you who would like to read it can view it at http://dailyprogrammingtalk.blogspot.com/2012/11/linkedin-rest-url-step-1-obtain-request.html

That was just step 1 of OAuth authentication.
Step 2 is simpler. After making a POST request to obtain a request token, we will receive a response similar to below:
oauth_token=abcd&oauth_token_secret=abc123&oauth_callback_confirmed=true&xoauth_request_auth_url=https%3A%2F%2Fapi.linkedin.com%2Fuas%2Foauth%2Fauthorize&oauth_expires_in=599

Parse the querystring:
string token = Regex.Match(token, @"oauth_token=([^&]+)").Groups[1].Value,
string tokenSecret = Regex.Match(token, @"oauth_token_secret=([^&]+)").Groups[1].Value


After getting the token and token secret, append the request token in the querystring and redirect users to:
https://api.linkedin.com/uas/oauth/authenticate?oauth_token=abcd

At this point, users will choose to allow us to access their LinkedIn info or not. If yes, users will be redirected to our callback url (this callback url was set up when we obtained our consumer key on developer.linkedin.com) similar to below:

http://localhost:12345/linkedincallback.aspx?oauth_token=abcd&oauth_verifier=94262

On the callback page, parse and store the values for oauth_token, oauth_verifier, and oauth_token_secret because we need those for step 3 of OAuth authentication.

Let's move on to Step 3: http://dailyprogrammingtalk.blogspot.com/2012/12/linkedin-rest-url-step-3-obtain-access.html

No comments:

Post a Comment