{"id":2174,"date":"2012-09-19T10:34:49","date_gmt":"2012-09-19T10:34:49","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2012\/09\/19\/configuring-your-asp-net-application-for-microsoft-oauth-account\/"},"modified":"2012-09-19T10:34:49","modified_gmt":"2012-09-19T10:34:49","slug":"configuring-your-asp-net-application-for-microsoft-oauth-account","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/configuring-your-asp-net-application-for-microsoft-oauth-account\/","title":{"rendered":"Configuring your ASP.NET application for Microsoft OAuth account"},"content":{"rendered":"<p><font size=\"3\">This post is a part of the <a href=\"http:\/\/blogs.msdn.com\/b\/webdev\/archive\/2012\/08\/15\/oauth-openid-support-for-webforms-mvc-and-webpages.aspx\" target=\"_blank\" rel=\"noopener\">series<\/a> about how to enable and use OpenID\/OAuth support that was added to the ASP.NET templates in Visual Studio 2012. In this post I am going to detail the instructions on configuring your application to use Microsoft account for authentication. I am going to be focusing on configuring the application for a development environment(using VS &amp; IISExpress)<\/font><\/p>\n<ul>\n<li><strong><font size=\"3\"> Create a new ASP.NET MVC\/WebForms or WebPages application <\/font><\/strong>&#160;<\/li>\n<ul>\n<li><font size=\"3\">Build and run the website.<\/font><\/li>\n<\/ul>\n<\/ul>\n<p>&#160;<\/p>\n<ul>\n<li><font size=\"3\"><strong>Use a test domain<\/strong><\/font><\/li>\n<ul>\n<li><font size=\"3\">You need to use a domain other than localhost since Microsoft account cannot redirect back to localhost<\/font><\/li>\n<li><font size=\"3\">Some folks have graciously reserved <\/font><a href=\"http:\/\/readme.localtest.me\/\"><font size=\"3\">localtest.me<\/font><\/a><font size=\"3\"> for local testing of domains so you do not have to mess with hosts files. Follow the link for more information<\/font><\/li>\n<li><font size=\"3\">You can use Foo.localtest.me as a test domain. (Make sure Foo is unique. I would recommend prefixing it with something unique such as Foo&lt;MyName&gt;.localtest.me ). For the purpose of this article we will use Foo.localtest.me<\/font><\/li>\n<li><font size=\"3\">Ping Foo.localtest.me should be reverted back to local machine<\/font><\/li>\n<\/ul>\n<\/ul>\n<p><strong><font size=\"3\"><\/font><\/strong><\/p>\n<ul>\n<li><strong><font size=\"3\">Edit firewall rules for port 80 to receive external requests.<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">Follow the guidelines as mentioned (These work for windows8 as well)<\/font><a href=\"http:\/\/maximumpcguides.com\/windows-7\/open-a-port-in-windows-7s-firewall\/\"><font size=\"3\">http:\/\/maximumpcguides.com\/windows-7\/open-a-port-in-windows-7s-firewall\/<\/font><\/a><\/li>\n<\/ul>\n<\/ul>\n<p><strong><font size=\"3\"><\/font><\/strong><\/p>\n<ul>\n<li><strong><font size=\"3\">Configuring the Microsoft live portal<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">Open link <\/font><a href=\"https:\/\/manage.dev.live.com\/AddApplication.aspx\"><font size=\"3\">https:\/\/manage.dev.live.com\/AddApplication.aspx<\/font><\/a><font size=\"3\">. Login using live credentials <\/font><\/li>\n<p>     <font size=\"3\"><\/font>      <\/p>\n<li><font size=\"3\">Enter Application name and click on I accept (Read the terms of use and privacy if it concerns you !)<\/font><\/li>\n<p>     <font size=\"3\"><\/font>      <\/p>\n<li><font size=\"3\">In the Live Connect Developer Center where the APP was created in step 7, click on Application Settings page link -&gt; API settings<\/font><\/li>\n<p>     <font size=\"3\"><\/font>      <\/p>\n<li><font size=\"3\">In the redirectDomain enter the above created domain name. Eg: <\/font><a href=\"http:\/\/Foo.localtest.me\"><font size=\"3\">http:\/\/Foo.localtest.me<\/font><\/a><\/li>\n<p>     <font size=\"3\"><\/font>      <\/p>\n<li><font size=\"3\">Hit Save and the changes should be saved<!--EndFragment--><\/font><\/li>\n<\/ul>\n<\/ul>\n<p><strong><font size=\"3\"><\/font><\/strong><\/p>\n<ul>\n<li><strong><font size=\"3\">Configuring the keys in your application<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">For MVC\/WebForms applications<\/font><\/li>\n<ul>\n<li><font size=\"3\">Edit&#160; the AuthConfig file in the App_Start folder and uncomment the code for the Microsoft OAuth provider. Copy the client ID and client secret in the AuthConfig file in the uncommented section of Microsoft login<\/font><\/li>\n<\/ul>\n<p> <!--StartFragment--><font size=\"3\"><\/font>      <\/p>\n<li><font size=\"3\">For WebPages applications<\/font><\/li>\n<p>     <font size=\"3\"><\/font>      <\/p>\n<ul><font size=\"3\"><\/font>        <\/p>\n<li><font size=\"3\">Edit&#160; the&#160; _AppStart.cshtml file and uncomment the code for the Microsoft OAuth provider. Copy the client ID and client secret to this file in the uncommented section of Microsoft login<\/font><\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<p>&#160;<\/p>\n<ul>\n<li><strong><font size=\"3\">Map the test domain to your application<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">Now we need to add mapping for the domain name to be redirected to our application created in step 1<\/font><\/li>\n<li><strong><font size=\"3\">For IIS Express<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">Open applicationHost.config in %Documents%\\IISExpress\\config <\/font><\/li>\n<li><font size=\"3\">Locate the binding for the web application in the file. It will be defined in the &lt;site&gt; tag. For example<\/font><\/li>\n<ul>\n<div id=\"codeSnippetWrapper\">\n<div id=\"codeSnippet\">\n<pre>&lt;site name=<span>&quot;WebApplication5&quot;<\/span> id=<span>&quot;6&quot;<\/span>&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;application path=<span>&quot;\/&quot;<\/span> applicationPool=<span>&quot;Clr4IntegratedAppPool&quot;<\/span>&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;virtualDirectory path=<span>&quot;\/&quot;<\/span> physicalPath=<span>&quot;pathtoapplication\\WebApplication5&quot;<\/span> \/&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;\/application&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;bindings&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;binding protocol=<span>&quot;http&quot;<\/span> bindingInformation=<span>&quot;*:46178:localhost&quot;<\/span> \/&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;\/bindings&gt;<\/pre>\n<p><!--CRLF--><\/p>\n<pre>&lt;\/site&gt;<\/pre>\n<p><!--CRLF--><\/div>\n<\/p><\/div>\n<\/ul>\n<li><font size=\"3\">Add a new binding for port 80 and the domain name to this web application under the &lt;bindings&gt;<\/font><\/li>\n<p>      <font size=\"3\"><\/font><\/p>\n<li><font size=\"3\">&lt;binding protocol=&quot;http&quot; bindingInformation=&quot;*:80:Foo.localtest.me &quot; \/&gt;<\/font><\/li>\n<p>      <font size=\"3\"><\/font><\/p>\n<li><font size=\"3\">Restart IIS Express and relaunch the website. Test the above setting made by opening in the browser Foo.localtest.me. It should open the web application created.<\/font><\/li>\n<\/ul>\n<li><strong><font size=\"3\">IIS (7.0) upwards<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">Host you application in IIS<\/font><\/li>\n<li><font size=\"3\">Open up IIS Manager locate your web application under the Sites list and select &quot;Bindings&quot; from the action menu on the right. Add a binding for your chosen hostname (e.g. Foo.localtest.me ).<\/font><\/li>\n<\/ul>\n<\/ul>\n<\/ul>\n<ul>\n<li><strong><font size=\"3\">Run the site to see it in action<\/font><\/strong><\/li>\n<ul>\n<li><font size=\"3\">Make sure you are running VS as an admin for this to work<\/font><\/li>\n<li><font size=\"3\">Now launch the application either hosted in IIS Express or IIS<\/font><\/li>\n<li><font size=\"3\">Browse to the test domain Foo.localtest.me<\/font><\/li>\n<li><font size=\"3\">Navigate to Login page and login using Microsoft Live credentials. Login should be successful<\/font><\/li>\n<\/ul>\n<\/ul>\n<p><font size=\"3\">Hope you have fun while integrating Microsoft Account into your applications<\/font><\/p>\n<p><font size=\"3\">Cross posted to <a title=\"http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/09\/19\/configuring-your-asp-net-application-for-microsoft-oauth-account.aspx\" href=\"http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/09\/19\/configuring-your-asp-net-application-for-microsoft-oauth-account.aspx\">http:\/\/blogs.msdn.com\/b\/pranav_rastogi\/archive\/2012\/09\/19\/configuring-your-asp-net-application-for-microsoft-oauth-account.aspx<\/a><\/font><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is a part of the series about how to enable and use OpenID\/OAuth support that was added to the ASP.NET templates in Visual Studio 2012. In this post I am going to detail the instructions on configuring your application to use Microsoft account for authentication. I am going to be focusing on configuring [&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":[31,7406],"class_list":["post-2174","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-asp-net","tag-oauth"],"acf":[],"blog_post_summary":"<p>This post is a part of the series about how to enable and use OpenID\/OAuth support that was added to the ASP.NET templates in Visual Studio 2012. In this post I am going to detail the instructions on configuring your application to use Microsoft account for authentication. I am going to be focusing on configuring [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2174","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=2174"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/2174\/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=2174"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=2174"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=2174"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}