2022
Linkedin Sign In using LinkedinLogin Nuget package in Asp-Net MVC
Install Package from Nuget Package Manager
So, we will be using a nuget package that is used for linkedin login in two easy steps and is quite simple. So first of all you have to install the nuget package that is showed in the image.

You can also install this nuget package using the command in package manager console
Install-Package LinkedinLogin -Version 1.0.0
After you have successfully installed LinkedinLogin pakage . You have to go to the controller and add code on your controller.
Now this method will return you the redirect url which you have to add in your button href on view and on clicking that button it will redirect to linkedin login screen.So we will be storing the information in ViewBag and passing that on the view. So first do this on the controller side on the action which is fired when page is loaded.
public ActionResult Index() { ViewBag.uri = LinkedinLogin.LinkedinPackage.RedirectToLinkedinLoginUrl("ClientId", "redirectUri"); ViewBag.url = LinkedinLogin.LinkedinPackage.RedirectToLinkedinLoginUrl("7710pzauu34u5oni12cxsabc", "http://localhost:8080/Home/RedirectLinkedIN"); return View(); }
Now, we will add another action method which is the redirect method on which we will redirect after you enter linkedin id and password on the linkedin login screen and authentication is successfull. then it will redirect on the method. You have to pass the url of this method in redirect uri as parameter . This must also be added when creating linkedin client id and client secret key.
public ActionResult RedirectLinkedIN(string code) { try { var results = LinkedinLogin.LinkedinPackage.GetLinkedinUserProfile(code, "clientId", "clientSecet", "redirectUri"); var result = LinkedinLogin.LinkedinPackage.GetLinkedinUserProfile(code, "7710pzu5onereeicxs", "xUvKfIranere45Z0KDa50", "http://localhost:8080/Home/RedirectLinkedIN"); } catch (Exception ex) { throw ex; } return View(); }
Now, the url that we set in the viewbag in first step will be used like this on the view . When you will click on this anchor button it will redirect to linkedin Login screen where you will authenticate your user.
@{ ViewBag.Title = "Home Page"; } <a style="margin-top:10px" href="@ViewBag.url" class="btn btn-primary"> Hureee!Login with LinkedIN</a>
Now , run the application and you will see this button. Click on this button
You will see this screen on redirect. You can also face error if Redirect URI in app doesn't match the one passed in code. If everything is fine you will see this screen. Enter the details and click on sign in.
Now, it will redirect to the method which we have passed inside redirect URI.Here you will get Code parameter in request sent by linkedin .This code will be passed in our second method along with client id, client secret and redirect URI. In the result, you can see the linkedin profile returned for the logged in user.
So this is how you can integrate Linkedin Sign In using LinkedinLogin Nuget package in Asp-Net MVC. If you face any issue you can comment on the article.