Code2night
  • Home
  • Blogs
  • Tutorial
  • Post Blog
  • Tools
    • Json Beautifier
    • Html Beautifier
  • Members
    • Register
    • Login
  1. Home
  2. Blogpost
14 May
2022

How to Integrate Linkedin Login in Asp.net MVC

by Shubham Batra

65

Download Attachments

Social Login

So, now a days it is really important while developing applications that user's don't have to waste a lot of time trying to register or go inside your web application. So , keeping in mind the need of today's world we have few Social Login's available that are getting used mostly. These include Google Login,Linkedin and Microsoft. So, if you want to implement Google Login than please refer to this article Google Authentication in Asp.net MVC , that explains all steps for Google Login.

LinkedIN Login


So, for linkedin login we will have to follow these steps, first of all we will need to get our Client Id and Client Secret like all social Login's. So we will see how to get client id and client secret in LinkedIn.

Register New LinkedIN App

So we have to register a new linkedin app first, so just go to developer login of linkedin and login using one linkedin account , like showed in the image.

So , here we have to enter LinkedIN account username and password and click on Sign In.

Now, we will see this screen where you have to click on Create App

Now , we have to add the app name that will be showed when user will be asked for permission while using LinkedIN Login on your webapp. 

After entering the name , you will need one company page.  You can click on Create a company profile  ,  if you don't have a company page already.

On this screen you have to click on Company because we want to create one company page.

Fill all the details here , that is required and should be valid. For this step , your linkedin account must be old one. As it will not save for new accounts.

After filling your details, you have to click on Create page .  This will create your company page and we can go back to the process of creating app in step 3.

Now, you can select your created company page in the Linked Page selection search box. Select your company page and then enter privacy page url, which can be any url.

Now, add your logo and check the checkbox and click on create app.

Now, at this step, you have to click on this edit icon and you will see one link button there

This, must be the URL from your application where you will redirect when user will authorize the LinkedIn Login. You can change this url as per your need.

Now, click on the products tab.

Now, this is one of the most important step, as you have to select the features that you want to use, so click on select on the last two options. This will open a popup where you will have to check the checkbox and then the add button.

After adding both the service, they will appear like this, now your app is set up for getting used.You can go to Auth and check your Client Id and client Secret. 

Note, down your client id and client secret key from here. Now, we will go to our application and write the code for LinkedIN Authentication. 

public ActionResult RedirectLinkedIN(string code, string state)
        {
            try
            {
                var client = new RestClient("https://www.linkedin.com/oauth/v2/accessToken");
                var request = new RestRequest(Method.POST);
                ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
                request.AddParameter("grant_type", "authorization_code");
                request.AddParameter("code", Request.QueryString["code"].ToString());
                request.AddParameter("redirect_uri", "http://localhost:8080/Home/RedirectLinkedIN");
                request.AddParameter("client_id", "Enter Your ClientId");
                request.AddParameter("client_secret", "Enter Your Client Secret");/*These are to be added in the view also on the button*/
                IRestResponse response = client.Execute(request);
                var content = response.Content;
                var res = (JObject)JsonConvert.DeserializeObject(content);
                var client2 = new RestClient("https://api.linkedin.com/v2/emailAddress?q=members&projection=(elements*(handle~))&oauth2_access_token=" + res["access_token"]);
                client = new RestClient("https://api.linkedin.com/v2/me?projection=(id,firstName,lastName,profilePicture(displayImage~:playableStreams))&oauth2_access_token=" + res["access_token"]);
               
                request = new RestRequest(Method.GET);
                var request2 = new RestRequest(Method.GET);
                response = client.Execute(request);
                var response2 = client2.Execute(request);
                content = response.Content;
                var content2 = response2.Content;
                var user = (JObject)JsonConvert.DeserializeObject(content);
                var useremail = (JObject)JsonConvert.DeserializeObject(content2);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return View();
        }

So , on the controller we will add one action where the user will redirect after successful login, this action and url must match the name which was given while creating the app.You have to install RestSharp 104 version for this.


<a style="margin-top:10px" href="https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=77bc666rocp9sm&redirect_uri=http://localhost:8080/Home/RedirectLinkedIN&state=987654321&scope=r_liteprofile,r_emailaddress"
   class="btn btn-primary"> Hureee!Login with LinkedIN</a>

Here, on the view we will add one button  , which will be used for LinkedIN Authentication. Remember, you have to replace the url and client id in the href. Now run your application.


After, clicking on allow it will go on your Redirect URL which you have provided while creating app. You will get your Login information there.Like showed in the image.


So, this is how to Integrate Linkedin Login in Asp.net MVC.  If you get any error regarding Redirect Url, then please double check the url in the code and the app and also that you are using your client id and client secret.

  • |
  • LinkedIn Authentication , Login using LinkedIN , Social Login in AspNet , LinkedIn Authentication in AspNet MVC , LinkedIn Login in aspnet MVC

Comments

Tags

How to set Date and time format in IIS Manager
IIS Manager
IIS
Internet Information Services (IIS) Manager
Internet Information Services (IIS)
Internet Information Services
Error Handling In AspNet Core
Exception Handling Asp Net Core
Exception Handling
Exception Handling Asp Net
Aspnet
Creating Log Files in MVC
Error Handling in MVC
Exception Handling in AspNet
Handling Exceptions and Creating Error Logs in Asp net Mvc using base controller
net
Code2Tonight
Stopping Browser Reload On Save
Repository Pattern with ADONet in MVC
Repository Pattern With ASPNET MVC And AdoNet
MVC Crud Operation
Jquery Full Calender Integrated With ASPNET
Full Calendar
Jquery Calendar
Slick Slider
Slick Slider Example
responsive carousels
Entity Framework
MVC
Intergrate SummerNote Text Editor into AspNet MVC
Web Config
Auto Redirection
Redirection from Http to https
AspNet
Url Rewriting
Postgre
PgAdmin4
PostgreSql
A Non Fatal Error Occured During Cluster Initialisation In Postgre SQL
Microsoft Outlook
Outlook Appointments
Microsoft Exchange Service
Send Email With HTML Template And PDF Using ASPNet C#
Send Email
Email with html template
email with pdf attachment
email with html and pdf
Microsoft Outlook Contacts
Outlook
Microsoft Exhchange Service
JSON
Convert string with dot notation to JSON
HTTP Error 5025 ANCM Out Of Process Startup Failure
Internet Information Service
Net core
Payumoney Integration With AspNet MVC
Prism js
Highlighting Syntax
Syntax Highlighting
code stylings
c#
Jquery AJax
Ajax
Jquery
Implement Stripe Payment Gateway In ASPNET
Using Checkout in an ASPNET Web Forms application
Stripe Payment
Stripe Payment Integration
Stripe Integeration
How to upload Image file using AJAX andjQuery
upload Image file using AJAX and jquery
Ajax call
file upload using ajax
file uploading using ajax and jquery
ConfigurationBuilder does not contain a definition for SetBasePath
Reading app json file in dot net core
Appsetting jso
Dot Net Core
Globalization and localization in ASPNET Core
Asp Net Core with Resource file resx
How to get the resx file strings in asp net core
Culture in Net core
Localisation in AspNet Core
Url Encryption in AspNet MVC
Url Encryption in C#
Url Encryption
Custom Helpers
Slick Slider with single slide
Slick
Vue js
Child Components
How to reload vue js child components
Net Core
Visual Studio
C#
Net core 31
Razor
Zoom sdk
Zoom c# wrapper Inegration
zoom Integration in c#
Zoom Integration
Zoom window sdk
vue js toggle button
vue js
toggle buttons
vuejs
vue js toggle switch
SignalR
VueJs
SignalR in Net Core
Chat App in Vue js
Chat App using SignalR
AspNet Chat app
JPlayer
Html5 Audio Video Player
Music Player
QR Code Generator
QR Code
Jquery QR Code
AspNet MVC
Google Maps
Google map api
Places API
Google map Places API in AspNet
Jquery Autocomplete
Autocomplete
Jquery UI Autocomplete
ExcelDataReader
Import data from excel in AspNet
Card Number Formatting
Amex Card Format
Card Format
FCM
Cloud Messaging
Android Notifications
FCM Notifications for IOS
IOS Notifications
Angular js
apply css on child components in Angular js
Angular Mentions
Google Sign In
Google Login
Google Oauth Api
Social Login
Aspnet Mvc
Google + Api
Create and publish a package using Visual Studio (NET Framework
Windows)
Create and publish a nuget package
create your own nuget package
Image compress
Image optimization
compress Image
optimize Image
WebForm
AspNet Web Pages
Batch Script
Database backup
Powershell
ASpNet
Sql Server Backup
LinkedIn Authentication
Login using LinkedIN
Social Login in AspNet
LinkedIn Authentication in AspNet MVC
LinkedIn Login in aspnet MVC
Shuffle List in c#
C#Net
Google Login in AspNet MVC
GoogleAuthentication Nuget package
Password Encryption
RFC Encryption
Encryption and Decryption
Encryption in AspNet
Base 64 Encryption
Base 64 Decryption

Welcome To Code2night, A common place for sharing your programming knowledge,Blogs and Videos

  • Kurukshetra
  • [email protected]

Links

  • Home
  • Blogs
  • Tutorial
  • Post Blog

Popular Tags

Copyright © 2022 by Code2night. All Rights Reserved

  • Home
  • Blog
  • Login
  • SignUp
  • Contact
  • Json Beautifier