Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Microsoft Live Account Authentication on Localhost

I have created a blank, new ASP.NET MVC site.

I have set up an application endpoint at https://account.live.com/developers/ as follows:

API Settings: http://i.imgur.com/bIoV3x9.png API Settings

App Settings and Code-Behind: http://i.imgur.com/P3KFyhV.png App Settings and Code-Behind

I have tried launching my site, connecting to https://localhost:44300/, clicking "Log in", then "Microsoft" and I get a page that says the following:

Microsoft account

We're unable to complete your request

Microsoft account is experiencing technical problems. Please try again later.

But the URL it redirects me to is:

https://login.live.com/err.srf?lc=1033#error=invalid_request&error_description=The%20provided%20value%20for%20the%20input%20parameter%20'redirect_uri'%20is%20not%20valid.%20The%20expected%20value%20is%20'https://login.live.com/oauth20_desktop.srf'%20or%20a%20URL%20which%20matches%20the%20redirect%20URI%20registered%20for%20this%20client%20application

I am to believe that the redirect_uri is not valid. The expected value is some URI to oauth20_desktop.srf. I don't know what in the world is going on/what the problem is. Can anyone shed some light as to what I must do to test Microsoft Account logins to my localhost-running MVC site?

like image 850
Alexandru Avatar asked Jul 31 '14 01:07

Alexandru


1 Answers

Your findings are correct, Microsoft doesn't allow for localhost as redirect_uri and it is explain in the ASP.NET Documentations...

When registering your site with Facebook, you can provide "localhost" for the site domain and "http ://localhost/" for the URL, as shown in the image below. Using localhost works with most providers, but currently does not work with the Microsoft provider. For the Microsoft provider, you must include a valid web site URL.

If you want to get it working you will need to set up an IIS site with custom host headers, this will require you to modify the hosts files in your machine...assuming you are developing on a Windows machine of course

Setting up your environment

  1. Open the IIS Management Console and create a new site
  2. Enter the site name, app pool, physical path and most importantly the host headers....see screenshot below

enter image description here

  1. Click OK, to create the site and then make sure both the site and the app pool are running
  2. Enter the following system path in the "Run command" utility %SystemRoot%\system32\drivers\etc to open the path where the hosts file is located...usually C:\Windows\system32\drivers\etc
  3. Open the hosts file as Administrator and add an entry that matches your set up host headers...

    127.0.0.1 www.testsite.com

  4. Once saved you can open a browser window to test the set up by type in http://www.testsite.com

  5. If it works, then you can use that url for testing purposes with Microsoft OAuth API or any other provider such as Google, Facebook, LinkedIn, etc
like image 116
Leo Avatar answered Oct 21 '22 12:10

Leo