LinkedIn Login for ASP.NET MVC 5 Application

I am working with an ASP.NET MVC 5 web application. I need to give users a login with their LinkedIn accounts. MVC 5 provides login support using Facebook, Google. But I have no clear idea of ​​how to implement this using LinkedIn.

There is no Katana support for LinkedIn in MVC 5. What will be the approach that should be used to implement this particular behavior in MVC 5? Any suggestions would be appreciated. Thanks.

+8
authentication asp.net-mvc oauth asp.net-mvc-5 linkedin
source share
3 answers

Finally found a way to do this successfully ..! I am duplicating the code used to implement Facebook authentication in Owin / Katana. You can find it here.

The source code of the Katana project

I copied all the files and the folder indicated in the red box in the following figure.

enter image description here

Paste them into my own MVC 5 web application project where I need to implement LinkedIn authentication. Renamed all classes as LinkedIn instead of Facebook.

enter image description here

And then I changed the code to adapt it to LinkedIn.

  • Constant Class Changed DefaultAuthenticationType for LinkedIn instead of Facebook.
  • LinkedInAuthenticationHandler Class

     private const string TokenEndpoint = "https://www.linkedin.com/uas/oauth2/accessToken"; private const string GraphApiEndpoint = "https://api.linkedin.com/v1/people/~"; 

    Modify this code inside the ApplyResponseChallengeAsync method.

     string authorizationEndpoint = "https://www.linkedin.com/uas/oauth2/authorization" + "?response_type=code" + "&client_id=" + Uri.EscapeDataString(Options.AppId) + "&redirect_uri=" + Uri.EscapeDataString(redirectUri) + "&scope=" + Uri.EscapeDataString(scope) + "&state=" + Uri.EscapeDataString(state); 
  • LinkedInAuthenticationOptions Class

     CallbackPath = new PathString("/signin-linkedin"); 

Then go to the Startup.Auth.cs file in the App_Start folder in your project and add this code to it.

  app.UseLinkedInAuthentication( APIKey: "...YourLinkedInAPIKeyHere...", SecretKey: "...YourLinkedInSecretKeyHere..." ); 

Provide information about your application in the LinkedIn API. You can read more about this here.

Using LinkedIn Authentication

It's all. Good luck

0
source share

This does not apply to MVC 5, but there are some links on how to implement LinkedIn oAuth.

Custom oAuth LinkedIn Provider

DotNetOpenAuth for MVC using LinkedIn

Also, I just came across this on SO, LinkedIn Details using DotNetOpenAuth in MVC4

+4
source share

Some time after the OP, the more direct IMHO solution should use the NuGet package for Owin.Security.Providers .

Once the package is added to your solution, using LinkedIn as a provider is very simple, as the author’s blog explains.

And besides being open sourced , the bonus is that you get support for other authentication providers at the same time, such as GitHub, Yahoo or StackExchange: o)

+2
source share

All Articles