Search code examples
asp.netowinasp.net-identity

ASP.NET MVC 5 (VS2013 final): Facebook login with OWIN fails (loginInfo is null)


I installed the VS2013 final bits that were released yesterday, and I'm trying to get an example working where I enable an external Facebook login. My first question:

In this controller code (which I did not touch and left as is from the sample template):

    //
    // GET: /Account/ExternalLoginCallback
    [AllowAnonymous]
    public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
    {
        var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
        if (loginInfo == null)
        {
            return RedirectToAction("Login");
        }

I set a breakpoint on the line await AuthenticationManager.GetExternalLoginInfoAsync(). The code returns (after I do my Facebook login), and "loginInfo" is null. In the UI, the login page continues to be displayed, with no change. How can I debug this? I was trying to find the code inside of GetExternalLoginInfoAsync() but according to this thread:

Where is Microsoft.AspNet.Identity.Owin.AuthenticationManager in Asp.Net Identity RTM version?

AuthenticationManager is now gone. (This does not seem to be the case per above.)

My second question: Is anyone else able to get the sample working with Facebook login with no changes to the ASP.NET MVC5 sample code (other than uncommenting app.UseFacebookAuthentication and filling in your FB app details)? (You'll have to configure an alias host with Facebook, such as "localtest.me" and configure it with IIS express.)

Thanks for any help...

-Ben


Solution

  • Ok, this was silly of me. First off, I started debugging using Fiddler, and saw that Facebook was sending back this:

    WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "The request is invalid because the app secret is the same as the client token"

    This message was inaccurate, but searching for it, I found another thread where a user specified that resetting the app secret solved the problem. (I hadn't used this app in a long time so that may have been related.) So I took those steps, but still saw the problem. But the message in Fiddler changed:

    WWW-Authenticate: OAuth "Facebook Platform" "invalid_request" "The request is invalid because the app is configured as a desktop app"

    Indeed, the app was misconfigured in Facebook. I set it to be a web app, and it works perfectly now! Hopefully this can help others, as this was not clear until firing up Fiddler.