1

I've been scratching my head and googling all night but nothing seems to be working for me. When trying to login to my mvc5 app using Facebook i keep on getting a null reference error in AuthenticationManager.GetExternalLoginInfoAsync(). Logging in using Google works perfectly.

Here's my setup:

  1. Site is running on IIS Express (also tried Local IIS).
  2. Already tried both http and https as some articles are saying fb requires SSL. So i'm sticking with https://localhost:44302/ at the moment (Note: Google works fine either way).

Note: I am using the default setup/templates in mvc5, didn't change anything - except the AppId and AppSecret for fb of course.

Can anyone throw in some solutions pls. Thanks.

dmc
  • 807
  • 2
  • 10
  • 25

1 Answers1

1

Replace var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

by this code:

var result = await AuthenticationManager.AuthenticateAsync(DefaultAuthenticationTypes.ExternalCookie);
if (result == null || result.Identity == null)//here will check if user login done
{
    return RedirectToAction("Login");
}

var idClaim = result.Identity.FindFirst(ClaimTypes.NameIdentifier);
if (idClaim == null)
{
    return RedirectToAction("Login");
}

var login = new UserLoginInfo(idClaim.Issuer, idClaim.Value);//here getting login info
var name = result.Identity.Name == null ? "" : result.Identity.Name.Replace(" ", "");//here getting user name
Yehia Elhawary
  • 578
  • 1
  • 4
  • 20
  • Awesome! Thank you @Yehia , this worked for me. I also replaced that code in ExternalLoginConfirmation. No more errors, definitely logging in now. It's not returning fb username though, but I'm sure i can find something tomorrow. Thanks! – dmc Oct 24 '14 at 15:04
  • urw @DuncanMcIntyre,this link mybe helping you http://stackoverflow.com/questions/17937553/get-extradata-from-mvc5-framework-oauth-owin-identity-provider-with-external-aut – Yehia Elhawary Oct 24 '14 at 15:12