Introduction
Here, I will explain how to implement Linkedin authentication in ASP.NET MVC. In order to use API in our web application, first we 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
Click on API Keys and then you will see a list of your applications. Now click on Add new Application.
Add new application in linkedin
Next create your application settings.
LinkedIn Application Registration
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.
We have successfully 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, external 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.
Now Click on Login
Now click on the LinkedIn button to login using LinkedIn API.
The page will be redirected to the LinkedIn Login screen.
Now click on Allow access button to log into the LinkedIn. After login, you will be redirected back to the application.
Click on the Register button to complete the registration process.
The post LinkedIn Authentication in ASP.NET MVC appeared first on Venkat Baggu Blog.