Let’s first establish what the purpose of this code is, in the first place. For this article, the purpose of the code is to Sign in / Login with LinkedIn, in MVC.
Step 1
First, you need to create an empty MVC application.
- On the File menu, click New Project.
- In the New Project dialog box, under Project types, expand Visual C#, and then click Web. In the Name box, type "DemoLinkedINLogin", then click on OK.
- Now, in the dialog box, click on "MVC" under the ASP.NET 4.5.2 Templates. Then, click on "Change Authentication" on the center of the right side. Select "No Authontication".
Step 2
For signing in / logging in with LinkedIn, first of all we need to create an app in our LinkedIn & then, we need client_id and client_secret of that app. So, here we go for creating an app in Google account.
- Log into your LinkedIn account. Use the below link for the same.
Developer LinkedIN Account
- Click on "My Apps" on top menu.

- Now, create an app for login API. Click on "Create Application".

- Fill all the fields for our new application.
Note - Enter your localhost URL in "Website URL". After filling the form, click on "Submit" button.

Now, we need to enter the redirect URL for OAuth 2.0 -- Authorized Redirect URLs:

- Finally, you got your client_id and client_secret. As per your need, select "Default Application Permissions".

Step 3
Now, it's Code Time! Before we start the code, we need to note that LinkedIn Login API relies on OAuth 2.0 protocol for granting access.


atulPosted Mar 14, 2020, 6:56 AM
Hi Ankit,My response is coming blank, I dont know where I am doing wrong IRestResponse response = client.Execute(request); var content = response.Content;
Ankit KanojiaPosted Mar 12, 2020, 2:20 AM
Thank you so much Raja sekhar
Ankit KanojiaPosted Mar 12, 2020, 2:20 AM
Thank you so much Raja sekhar
Ankit KanojiaPosted Mar 12, 2020, 2:20 AM
Thank you so much Ashish Upalekar
Ankit KanojiaPosted Mar 12, 2020, 2:20 AM
Thank you so much vishal joshi for being interactive
Ankit KanojiaPosted Mar 12, 2020, 2:19 AM
Have you tried with your tokens and credentials Vikas Singh? can you elloborate the actual scenerio of issue so that it helps me to resolve issue on same direction.
Ankit KanojiaPosted Mar 12, 2020, 2:18 AM
Thank you so much Vikas Singh, will revert back once i fot the resolution for the issue posted by you. By the way again thanks for being interactive.
Ankit KanojiaPosted Mar 12, 2020, 2:17 AM
Thank you so much Raja sekhar
Ankit KanojiaPosted Mar 12, 2020, 2:17 AM
Thank you so much Dheeraj Pandey
Ankit KanojiaPosted Mar 12, 2020, 2:16 AM
Rajeev Ranjan : There are many choices.. but i choose restsharp.. its light weight and simple that is the reason..
Vikas SinghPosted Mar 12, 2020, 1:12 AM
Here access_token is invalid because api responce is invalid -----------------------------------------------------------------------Var client = new RestClient("https://www.linkedin.com/oauth/v2/accessToken"); var request = new RestRequest(Method.POST); request.AddParameter("grant_type", "authorization_code"); request.AddParameter("code", code); request.AddParameter("redirect_uri", "http://localhost:57633/Home/LinkedINAuth"); request.AddParameter("client_id", "81qwzypoua0y97"); request.AddParameter("client_secret", "gH2exhTg1r6jqK1K"); IRestResponse response = client.Execute(request); var content = response.Content; //Fetch AccessToken JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); LinkedINVM linkedINVM = jsonSerializer.Deserialize<LinkedINVM>(content); //Get Profile Details client = new RestClient("https://api.linkedin.com/v1/people/~?oauth2_access_token=" + linkedINVM.access_token + "&format=json"); request = new RestRequest(Method.GET); response = client.Execute(request); content = response.Content; jsonSerializer = new JavaScriptSerializer(); LinkedINResVM linkedINResVM = jsonSerializer.Deserialize<LinkedINResVM>(content); return View(linkedINResVM);
Raja sekharPosted May 24, 2018, 6:17 AM
Hi Suchit How can i retrieve Email Address??
siva cPosted Mar 15, 2018, 2:22 AM
Hi Suchit, I tried to get the access token by this Local IIS url like request.AddParameter("redirect_uri", "http://our system ipaddress/virdirname/Home/LinkedINAuth"); but, after login i am getting the object null reference error. Could you please help on this?
Ashish UpalekarPosted Jul 21, 2017, 9:56 AM
Hi Suchit, Code is working fine for r_basic profile but when I replace it with r_fullprofile its not working. Getting null response. I have one app where I configured r_fullprofile permission. I understand that I need to expand LinkedInVM class to hold additional info. But atleast I should have got response. Do you have any code for r_fullprofile ?
Dheeraj PandeyPosted Mar 24, 2017, 8:12 AM
In above example "linkedINVM.access_token " is not define any where and thats why i am not able to gate profile detail. so please help me to get user profile detail.
Rajeev RanjanPosted Nov 30, 2016, 11:23 PM
Super article sir, but why Restsharp?there is already linkedin dll for same task