1

I'm having some problems with out of the box Microsoft Authentication with a plain MVC 5 site.

I have set up my hosts file to route 127.0.0.1 to www.mysite.com.

I have configured the redirect url for the App on windows live to goto www.mysite.com/signin-microsoft

In Visual Studio 2015 I've set the properties for the website to use Local IIS and www.mysite.com

When I try to authenticate through Microsoft, it shows the Live login screen, when I enter my details it redirects back to the account controller endpoint ExternalLoginCallback(string returnUrl) but - returnUrl is null and the next line where it tries to get loginInfo always returns null.

Auth is set up in Startup.Auth as

var options = new MicrosoftAccountAuthenticationOptions
            {
                ClientId = "<redacted>",
                ClientSecret = "<redacted>",
                CallbackPath = new PathString("/signin-microsoft")

        };
options.Scope.Add(scope);

        app.UseMicrosoftAccountAuthentication(options);

I hit this url in fiddler - "Account/ExternalLoginCallback?error=access_denied"

I've followed the answer in this post - ASP.NET MVC Microsoft Live Account Authentication on Localhost

I can't work out what I'm missing.

Any help would be greatly appreciated.

Thanks

Community
  • 1
  • 1
Dave
  • 2,552
  • 5
  • 25
  • 30
  • What is "Microsoft Authentication"? Doesn't the callback site need to be publicly accessible for third-party authentication to work? – CodeCaster Oct 28 '15 at 11:40
  • OAuth using Microsoft as a provider. Basically using the "UseMicrosoftAccountAuthentication" section in Startup.Auth.cs. From what I've read you can spoof it in dev using the hosts file... – Dave Oct 28 '15 at 11:41
  • Did you check if your callback address is configured in your Microsoft application? – Douglas Gandini Oct 28 '15 at 11:49
  • Yep - redirectUrl is set to be www.mysite.com/signin-microsoft – Dave Oct 28 '15 at 11:51
  • Try to disable the option Restrict JWT Issuing. – Douglas Gandini Oct 28 '15 at 12:10
  • Disabling Restrict JWT Issuing gives the same issue. AuthenticationManager.GetExternalLoginInfoAsync() always returns null - I don't see the Live login screen. – Dave Oct 28 '15 at 12:54

1 Answers1

1

You may get a clue of what is wrong by turning on the tracing for your OWIN middleware in the web.config of your project:

<configuration>
  <system.diagnostics>
    <switches>
      <add name="Microsoft.Owin" value="Verbose" />
    </switches>
  </system.diagnostics>
</configuration>

The output will by default appear in your debug console window, but you can change this by adding trace listeners. For more information about OWIN logging see this article.

MvdD
  • 22,082
  • 8
  • 65
  • 93