Tuesday, December 25, 2012

MVC4-Integrating OAuth/OpenID

 MVC 4 has enabled login from facebook and other sites using OAuth and OpenID. MVC 4 uses DotNetOpenAuth library for OAuth and OpenID authentication. In this blog post, we would see how to configure MVC 4 for Facebook Login

1) Create MVC4 application

2) Go to Facebook below URL - https://developers.facebook.com/apps

3) Click on 'Create New App' button

4) Enter your application Name

5) There could be captcha image to validate yourself

6) Fill in the basic information in the next form that is shown. Display Name and Email Address would be prefilled.

7) Click on ‘Website with Facebook login link’ and enter your site URL (like www.example.com).

However if your testing your application on your local machine enter the url like http://localhost:12345 (where 12345 would be your local port number)

8) Click on ‘Save Changes’ button and you would see App ID and App Secret Key

9) Now its time to make changes in application
Open the AuthConfig.cs in App_Start folder. Here you will all the code commented for different clients like Facebook, Twitter,GooglClient etc

                appId: "",
                appSecret: "");

10) Uncomment code lines for Facebook. Add the App ID and App Secret Key.

11) Run the application and click on Log In button. There you would see additional button for Facebook Login

12) Clicking on 'Facebook' button will authenticate user with Facebook credentials.

13) Once you register, you can see that you are authenticates and you can see your name.

Hope this article of mine would give some overview of MVC OAuth.

No comments:

Post a Comment