LinkedIn Authentication in ASP.NET MVC

27 Oct

Introduction

Here i will explain about how to implement Linkedin authentication in ASP.NET MVC. In order to use API in our web application, first you need to create an application in  Linkedin Developer Page. The following are the steps to follow to create an application in Linkedin.

Register Application

Register your application in linkedin developers page

Register your application in linkedin developers page

Click on API Keys and then you will see an list of your applications. Now click on Add new Application

Add new application in linkedin

Add new application in linkedin

Next create your application settings

LinkedIn Application Registration

LinkedIn Application Registration

 

Developer Network  Application Details   LinkedIn OAuth Settings

Developer Network Application Details LinkedIn OAuth Settings

Once application is created save the API Key and Secret Key in APP Settings under Web.config file

Developer Network  Application Keys Settings   LinkedIn

We have succesfully created the Linkedin application, now we need to enable the LinkedIn authentication in ASP.NET MVC.

Integrtating LinkedIn Authentication ASP.NET MVC

The following are the steps you need to follow for enabling the LinkedIn authentication in ASP.NET MVC.

By default,  Extrenal authentication in ASP.NET supports only MicrosoftAccount, TwitterAuthentication, FacebookAuthentication, and GoogleAuthentication but we need to use LinkedIn authentication for that we need to install a package from the nuget called Owin.Security.Providers.

Step 1: Execute the following command in the Nuget Package Manager Console(Click on Tools —> Nuget Package Manager —> Package Manager Console)

Install-Package Owin.Security.Providers

Step 2:  In the web.config file add the API Key and Secret Key under app settings

<add key="LinkedInAPIKey" value="759ovbpv5qvg25" />
<add key="LinkedInAPISecret" value="j3Arp8J6y9CPwXhq" />

Step 3: Now go to App_Start/Startup.Auth.cs to enable the Linked Authentication

app.UseLinkedInAuthentication
(
    clientId: ConfigurationManager.AppSettings["LinkedInAPIKey"].ToString(),
    clientSecret: ConfigurationManager.AppSettings["LinkedInAPISecret"].ToString()
);

 Step 4: Everything is configured so now run the web application to test it.

linkedinloginscreen

 

 Now Click on Login

linkedinloginscreen

Now Click on the LinkedIn button to login using LinkedIn API.  The page will be redirected to the LinkedIn Login screen

linkedinloginscreen
Now Click on Allow access button to log into the LinkedIn. After login you will be redirected back to the application

linkedinloginscreen

Click on the Register button to complete the registration process.

 

Leave a Reply

Your email address will not be published. Required fields are marked *