5

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: https://i.stack.imgur.com/kOWns.png API Settings

App Settings and Code-Behind: https://i.stack.imgur.com/9kcjS.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?

Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • 1
    "matches the redirect URI registered for this client application" is the answer. Your setting show some ".com" return url while you likely pass some sort of http://localhost... one. Check out my answer in http://stackoverflow.com/questions/4532721/facebook-development-in-localhost to dealing with it. – Alexei Levenkov Jul 31 '14 at 01:20
  • @AlexeiLevenkov Can it ever work on IIS Express? I have tried changing my hosts file to point to 127.0.0.1 mydomain.com where mydomain is the domain in the picture (blanked out) but this didn't work. Does it only work on IIS? – Alexandru Jul 31 '14 at 01:34
  • 1
    You need Fiddler workaround - hosts file does not work with Dev server/IIS express which are only expecting localhost in default config. – Alexei Levenkov Jul 31 '14 at 02:12

1 Answers1

8

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
Leo
  • 14,625
  • 2
  • 37
  • 55
  • Can it ever work on IIS Express? I have tried changing my hosts file to point to 127.0.0.1 mydomain.com where mydomain is the domain in the picture (blanked out) but this didn't work. Does it only work on IIS? – Alexandru Jul 31 '14 at 01:34
  • 2
    @Alexandru setting hosts file entries alone is not enough. You need to add custom host headers to your site matching the entries specified in the hosts file. I don't know if you can achieve this with IIS Express, coz I never use it...I always set up a dev environment as close as possible to the live environment. So, use IIS 7/7.5, set up a site and add the host headers, it should work – Leo Jul 31 '14 at 02:04
  • @Alexandru I just noticed you accepted the answer as I was adding more details...I'll leave it there just in case you get any doubts and/or for future references – Leo Jul 31 '14 at 02:36