{"id":2404,"date":"2012-08-15T10:03:00","date_gmt":"2012-08-15T10:03:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2012\/08\/15\/oauthopenid-support-for-webforms-mvc-and-webpages\/"},"modified":"2012-08-15T10:03:00","modified_gmt":"2012-08-15T10:03:00","slug":"oauthopenid-support-for-webforms-mvc-and-webpages","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/oauthopenid-support-for-webforms-mvc-and-webpages\/","title":{"rendered":"OAuth\/OpenID Support for WebForms, MVC and WebPages"},"content":{"rendered":"<p><span style=\"background-color: #00ff00\"><strong>[Update]<\/strong><\/span><\/p>\n<p><span style=\"background-color: #00ff00\">Adding relevant links at the bottom of the post<\/span><\/p>\n<p>One of the coolest features in Visual Studio 2012 is the ability to login using your Microsoft, Facebook, Twitter or Google account. The project templates showcase a social way of logging in along with the usual way of logging in by creating a local account<\/p>\n<p>This post highlights how you can turn on support for logging through these services in the project&nbsp; templates. Head over the following video to get a quick glance on this feature&nbsp;<a href=\"http:\/\/www.asp.net\/vnext\/overview\/videos\/oauth-in-the-default-aspnet-45-templates\">http:\/\/www.asp.net\/vnext\/overview\/videos\/oauth-in-the-default-aspnet-45-templates<\/a><\/p>\n<h2>Enable OAuth login using Facebook, Twitter<\/h2>\n<p><strong>Steps to get keys for Facebook<\/strong><\/p>\n<ul>\n<li>Go to the <a href=\"https:\/\/developers.facebook.com\/apps\">Facebook developers site<\/a> (log in if you&#8217;re not already logged in).<\/li>\n<li>Choose the Create New App button, and then follow the prompts to name and create the new application.<\/li>\n<li>In the section Select how your app will integrate with Facebook, choose the Website section.<\/li>\n<li>Fill in the Site URL field with the URL of your site (for example, <a href=\"http:\/\/www.example.com\/\">http:\/\/www.example.com<\/a>). The Domain field is optional; you can use this to provide authentication for an entire domain (such as example.com). <br \/>Note&nbsp;&nbsp; If you are running a site on your local computer with a URL like <a href=\"http:\/\/localhost:12345\/\">http:\/\/localhost:12345<\/a> (where the number is a local port number), you can add this value to the Site URL field for testing your site. However, any time the port number of your local site changes, you will need to update the Site URL field of your application.<\/li>\n<li>Choose the Save Changes button.<\/li>\n<li>Choose the Apps tab again, and then view the start page for your application.<\/li>\n<li>Copy the App ID and App Secret values for your application and paste them into a temporary text file. You will pass these values to the Facebook provider in your website code.<\/li>\n<li>Exit the Facebook developer site.<\/li>\n<\/ul>\n<p><strong>Steps to get keys for Twitter<\/strong><\/p>\n<ul>\n<li>Browse to the <a href=\"https:\/\/dev.twitter.com\/\">Twitter developers site<\/a>.<\/li>\n<li>Choose the Create an App link and then log into the site.<\/li>\n<li>On the Create an Application form, fill in the Name and Description fields.<\/li>\n<li>In the WebSite field, enter the URL of your site (for example, <a href=\"http:\/\/www.example.com\/\">http:\/\/www.example.com<\/a>). <br \/>Note&nbsp;&nbsp; If you&#8217;re testing your site locally (using a URL like <a href=\"http:\/\/localhost:12345\/\">http:\/\/localhost:12345<\/a>), Twitter might not accept the URL. However, you might be able to use the local loopback IP address (for example <a href=\"http:\/\/127.0.0.1:12345\/\">http:\/\/127.0.0.1:12345<\/a>). This simplifies the process of testing your application locally. However, every time the port number of your local site changes, you&#8217;ll need to update the WebSite field of your application.<\/li>\n<li>In the Callback URL field, enter a URL for the page in your website that you want users to return to after logging into Twitter. For example, to send users to the home page of the Starter Site (which will recognize their logged-in status), enter the same URL that you entered in the WebSite field.<\/li>\n<li>Accept the terms and choose the Create your Twitter application button.<\/li>\n<li>On the My Applications landing page, choose the application you created.<\/li>\n<li>On the Details tab, scroll to the bottom and choose the Create My Access Token button.<\/li>\n<li>On the Details tab, copy the Consumer Key and Consumer Secret values for your application and paste them into a temporary text file. You&#8217;ll pass these values to the Twitter provider in your website code.<\/li>\n<li>Exit the Twitter site.<\/li>\n<\/ul>\n<h4>Steps to enable OAuth support in WebForms<\/h4>\n<ul>\n<ul>\n<li>Create a new ASP.NET WebForms Application<\/li>\n<li>Goto App_Start\\AuthConfig.cs and uncomment the following lines of code<\/li>\n<\/ul>\n<\/ul>\n<div class=\"csharpcode\">\n<pre class=\"alt\">OpenAuth.AuthenticationClients.AddTwitter(<\/pre>\n<\/div>\n<div class=\"csharpcode\">\n<pre>                 consumerKey: <span class=\"str\">\"your Twitter consumer key\"<\/span>,<\/pre>\n<\/div>\n<div class=\"csharpcode\">\n<pre class=\"alt\">                 consumerSecret: <span class=\"str\">\"your Twitter consumer secret\"<\/span>);<\/pre>\n<\/div>\n<div class=\"csharpcode\">\n<pre>&nbsp;<\/pre>\n<\/div>\n<div class=\"csharpcode\">\n<pre class=\"alt\">            OpenAuth.AuthenticationClients.AddFacebook(<\/pre>\n<\/div>\n<div class=\"csharpcode\">\n<pre>                 appId: <span class=\"str\">\"your Facebook app id\"<\/span>,<\/pre>\n<\/div>\n<div class=\"csharpcode\">\n<pre class=\"alt\">                 appSecret: <span class=\"str\">\"your Facebook app secret\"<\/span>);<\/pre>\n<\/div>\n<h4>Steps to enable OAuth support in MVC<\/h4>\n<ul>\n<ul><!--StartFragment--><\/p>\n<li>Create a new ASP.NET MVC Internet Application<\/li>\n<li>Goto App_Start\\AuthConfig.cs and uncomment the following lines of code<\/li>\n<\/ul>\n<\/ul>\n<div class=\"csharpcode\">\n<pre class=\"alt\"><span class=\"rem\">\/\/OAuthWebSecurity.RegisterTwitterClient(<\/span><\/pre>\n<pre>            <span class=\"rem\">\/\/ consumerKey: \"\",<\/span><\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/ consumerSecret: \"\");<\/span><\/pre>\n<pre>&nbsp;<\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/OAuthWebSecurity.RegisterFacebookClient(<\/span><\/pre>\n<pre>            <span class=\"rem\">\/\/ appId: \"\",<\/span><\/pre>\n<pre class=\"alt\">            \/\/    appSecret: <span class=\"str\">\"\"<\/span>);<\/pre>\n<\/div>\n<h4>Steps to enable OAuth support in WebPages<\/h4>\n<ul>\n<ul><!--StartFragment--><\/p>\n<li>Create a new ASP.NET WebSite(Razor2)<\/li>\n<li>Goto _AppStart.cshtml and uncomment the following lines of code<\/li>\n<\/ul>\n<\/ul>\n<div class=\"csharpcode\">\n<pre class=\"alt\"><span class=\"rem\">\/\/OAuthWebSecurity.RegisterTwitterClient(<\/span><\/pre>\n<pre>            <span class=\"rem\">\/\/ consumerKey: \"\",<\/span><\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/ consumerSecret: \"\");<\/span><\/pre>\n<pre>&nbsp;<\/pre>\n<pre class=\"alt\">            <span class=\"rem\">\/\/OAuthWebSecurity.RegisterFacebookClient(<\/span><\/pre>\n<pre>            <span class=\"rem\">\/\/ appId: \"\",<\/span><\/pre>\n<pre class=\"alt\">            \/\/    appSecret: <span class=\"str\">\"\"<\/span>);<\/pre>\n<\/div>\n<h2>OpenID services such as Google<\/h2>\n<h4>Steps to enable OpenID support in WebForms<\/h4>\n<ul><!--StartFragment--><\/p>\n<li>Create a new ASP.NET WebForms Application<\/li>\n<li>Goto App_Start\\AuthConfig.cs and uncomment the following lines of code<\/li>\n<p><!--EndFragment--><\/ul>\n<pre class=\"csharpcode\">OpenAuth.AuthenticationClients.AddGoogle();<\/pre>\n<p>&nbsp;<\/p>\n<h4>Steps to enable OpenID support in MVC<\/h4>\n<ul>\n<li>Create a new ASP.NET MVC Internet Application<\/li>\n<li>Goto App_Start\\AuthConfig.cs and uncomment the following lines of code<\/li>\n<\/ul>\n<p>OAuthWebSecurity.RegisterGoogleClient();<\/p>\n<h4>Steps to enable OpenID support in WebPages<\/h4>\n<ul><!--StartFragment--><\/p>\n<li>Create a new ASP.NET WebSite(Razor2)<\/li>\n<li>Goto _AppStart.cshtml and uncomment the following lines of code<\/li>\n<\/ul>\n<p>OAuthWebSecurity.RegisterGoogleClient();<\/p>\n<h4><span style=\"background-color: #00ff00\"><strong>Links to relevant posts<\/strong><\/span><\/h4>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/08\/22\/extra-information-from-oauth-openid-provider.aspx\">http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/08\/22\/extra-information-from-oauth-openid-provider.aspx<\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/08\/23\/plugging-custom-oauth-openid-providers.aspx\">http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/08\/23\/plugging-custom-oauth-openid-providers.aspx<\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/08\/24\/customizing-the-login-ui-when-using-oauth-openid.aspx\">http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/08\/24\/customizing-the-login-ui-when-using-oauth-openid.aspx<\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/09\/12\/integrate-openauth-openid-with-your-existing-asp-net-application-using-universal-providers.aspx\">http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/09\/12\/integrate-openauth-openid-with-your-existing-asp-net-application-using-universal-providers.aspx<\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/09\/19\/configuring-your-asp-net-application-for-microsoft-oauth-account.aspx\">http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/09\/19\/configuring-your-asp-net-application-for-microsoft-oauth-account.aspx<\/a><\/p>\n<p><a href=\"http:\/\/www.asp.net\/mvc\/overview\/getting-started\/using-oauth-providers-with-mvc\">http:\/\/www.asp.net\/mvc\/overview\/getting-started\/using-oauth-providers-with-mvc<\/a>&nbsp;<\/p>\n<p>Happy Logging in a social way!!!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Update] Adding relevant links at the bottom of the post One of the coolest features in Visual Studio 2012 is the ability to login using your Microsoft, Facebook, Twitter or Google account. The project templates showcase a social way of logging in along with the usual way of logging in by creating a local account [&hellip;]<\/p>\n","protected":false},"author":408,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[],"class_list":["post-2404","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet"],"acf":[],"blog_post_summary":"<p>[Update] Adding relevant links at the bottom of the post One of the coolest features in Visual Studio 2012 is the ability to login using your Microsoft, Facebook, Twitter or Google account. The project templates showcase a social way of logging in along with the usual way of logging in by creating a local account [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/408"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=2404"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2404\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=2404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=2404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=2404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}