ASP.NET OpenID/OAuth Login With ASP.NET 4.5 – Part 4

With ASP.NET 4.5 it is very easy to enable users to login to your site with their accounts from Facebook, Google, LinkedIn, Twitter, Yahoo, and Windows Live. In this 7 part series I’ll show you how for each of the identity providers.

Note: Out-of-the-box this only works with WebForms and MVC4. MVC3 is not supported by default.

Part 4: Logging in with LinkedIn

Like with Facebook as covered in Part 3, you will need to register your application with LinkedIn before users can log in using their LinkedIn account.

  1. Go to
  2. In the menu select Support->API Keys, login when prompted.
  3. Click Add New Application.
  4. Next you need to fill out a form with quite some information in it. Fortunately most is straight forward. The image below shows the Company Info and the Application Info. Most important is the Application Name (in my case Michiel’s Security Demo), the Website URL (in my case, and Live Status. The latter indicating whether this is a development application or a live (production) application.

  5. Next up is contact information, which I’ll skip here, followed by the OAuth User Agreement. This is where you add information on what the user sees when logging in through linked in and where the user should be sent (in your application) when the user logs in (or cancels). In this case I’ll use the root URL of the application, because ASP.NET handles all that for me. Also notice I’ve set the Agreement Language to English.

  6. Agree to the terms of service and click Add Application.
  7. Next you’ll see a screen like the one below. You need the information shown to configure ASP.NET. You can get back to this information later by repeating steps 1 and 2, and then selecting the application you created. You will need the API Key and the Secret Key. The other two are only useful if your application uses the LinkedIn API (not covered here).

  8. Open Visual Studio (if you don’t have already).
  9. Open the project created in Part 1 (or quickly create a project in the same manner).

Now comes the tricky part. For starters, ASP.NET WebForms doesn’t have a neat method AddLinkedIn. There’s a fairly easy way around that using the generic Add method, but you’ll then find out what MVC users have already when they used RegisterLinkInClient: it doesn’t work! After logging in with LinkedIn your application will show one of the following messages:

  • MVC: Login Failure. Unsuccessful login with service.
  • WebForms: External login LinkedIn failed.

The problem is that the internal LinkedInClient class used by both MVC and WebForms isn’t quite correct, as Mr. Roa explains in this blogpost. Now, Mr. Roa’s solution works fine of you’re using ASP.NET MVC, but if you’re using WebForms, you’ll run into a new exception. For some reason verification of the authentication response sent by LinkedIn can’t be processed correctly. I’ve already spent quite some time digging through the underlying mechanics, but so far I haven’t been able to track down the problem. So if you’re using WebForm you’re out of luck. For MVC users just follow the steps Mr. Roa discusses and you’ll be fine.

Leave a Reply

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

71 − 70 =