For more about OAuth in the real world, refer to my article in the Free DNC Magazine Issue 4.
Registering with LinkedIn
Before we can start using LinkedIn as an OAuth for us, we have to register an ‘Application’ with Linked in.- Log in to http://developer.linkedin.com/. It requires you have a LinkedIn account and will link the account with your developer account.
- Once you Log in, select API Keys to create an application and get a set of API Keys
- The Application creation page takes a host of information of which phone number is mandatory
- Note we’ve provided Website URL as Localhost loop back address.
- Click on Add Application to create the Application and retrieve the ApiKey and Secret Key.
- You are now all set to build your ASP.NET Web App with LinkedIn Authentication
Configuring you ASP.NET Project
1. Start a new ASP.NET project and Select ASP.NET MVC4 Template Project Type. Use the Internet Template.2. In the web.config add the ApiKey and the Secret Key as two Key/Value pairs in the <appSettings> sections. E.g.
<appSettings>
… (removed for brevity)
<add key="apiKey" value="APIKey FromLinkedInAppRegistration"/>
<add key="apiSecret" value="SecretKey FromLinkedInAppRegistration"/>
</appSettings>
Go to App_Start\AuthConfig.cs and add the following line to setup the LinkedInClient provided by ASP.NET
4. That’s all the configuration that’s required
Logging in Using LinkedIn
1. Run the Application and click on Login. The following screen will come up2. Click on LinkedIn to be redirected to the LinkedIn Login Page
Notice the name you provided for your application has come up - “ASP.NET OAuth Demo”. Login using a valid LinkedIn credential and you will be redirected back to the App
3. SPLAT!!! Application refuses to login!
4. Well fear not, you didn’t do anything wrong. Just that the default LinkedInClient (version before 4.1.4.x) shipped with a bug, which has since been fixed. So go to Nuget Package Management Console and update your DotNetOpenAuth.Core package. As we can see below it’s a big update.
5. After update Repeat from Step 1 and instead of failure on Step 4. You should see the following:
6. Provide a User name and select Register to get Authenticated into the Application.
7. Well, there are no more steps. Here on, if you log off of close browser you can log in LinkedIn Id. You will not be asked to Register if the Linked Id you used already exists in the Database.
This is a very useful tutorial. I have just one Problem:
ReplyDeleteWhen I Start the Project and click on "Register with LinkedIn" I get the following Error:
DotNetOpenAuth.Messaging.ProtocolException is an Exception of type "DotNetOpenAuth.Core.dll"
But I have not seen any information to catch the exception. Maybe you can help me?
Thanks in advance!!!
Hi,
ReplyDeleteThanks so much for sharing this article. Especially, the tip related to resolving the Visual studio template work, well explained keep it up!
Cheers,
Rajesh
I faced a problem when I am going to run my application.I have added all the references and done all these process still when I am running the application it will show my default page not the login page of linked In. please help me
ReplyDelete