Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facebook login still failing #52

Closed
elraider33 opened this issue Apr 14, 2017 · 6 comments
Closed

facebook login still failing #52

elraider33 opened this issue Apr 14, 2017 · 6 comments

Comments

@elraider33
Copy link

I upgraded my project to version 3.1.0 and when I try to login with facebook I get an error. My other authentication(google) works fine

@Tratcher
Copy link
Member

What error? Turn on logging and also capture a network trace.

#38

@YovavGad
Copy link

Make sure all the Microsoft.Owin DLLs were updated to the new version, and check the version of the DLLs in your final bin folder

@elraider33
Copy link
Author

I already review it and this is what i got:
while in the version in the version 3.0.1 the returned values include first name, last name, email and others; in the version 3.1.0 the only returned values are the name and the Id. How can I have the other values?

Regards

@Tratcher
Copy link
Member

See this comment about Fields:
#38 (comment)

@vpekarek
Copy link

Hi, I don't have problem with authentication from Facebook, but I have problem with reading identities, when I am getting back to my pages. I have code like this:

var ctx = Context.GetOwinContext();
var user = ctx != null ? ctx.Authentication.User : new ClaimsPrincipal();
if (user != null && user.Identities.Count() > 0 && user.Identity.IsAuthenticated && string.IsNullOrEmpty(loginProvider))
{
	var claimsPrincipal = new ClaimsPrincipal(user.Identity);
	Thread.CurrentPrincipal = claimsPrincipal;
	var identity = (ClaimsPrincipal)Thread.CurrentPrincipal;

	if (identity.Claims.Count() > 0)
	{
		switch (identity.Claims.First().OriginalIssuer)
		{
			case "Facebook":

				if (!featureExternalLoginFacebook) { break; }

				id = identity.Claims.Where(c => c.Type == "urn:facebook:id").Select(c => c.Value).SingleOrDefault();
				name = identity.Claims.Where(c => c.Type == ClaimTypes.Name).Select(c => c.Value).SingleOrDefault();
				accessToken = identity.Claims.Where(c => c.Type == "FacebookAccessToken").Select(c => c.Value).SingleOrDefault();

				var url = string.Format("https://graph.facebook.com/v2.5/{0}?fields=email,first_name,last_name&access_token={1}", id, accessToken);

				var req = WebRequest.Create(url);
				req.Method = "GET";
				req.ContentType = "application/json";

				using (var res = new StreamReader(req.GetResponse().GetResponseStream()))
				{
					dynamic result = Newtonsoft.Json.JsonConvert.DeserializeObject(res.ReadToEnd());

					if (result.id != null && result.id == id)
					{
						email = result.email != null ? result.email : string.Empty;
						firstName = result.first_name != null ? result.first_name : string.Empty;
						lastName = result.last_name != null ? result.last_name : string.Empty;
					}
				}                            

				break;
		}

		externalApp = identity.Claims.First().OriginalIssuer;

		if (!string.IsNullOrEmpty(id) && !string.IsNullOrEmpty(email))
		{
			return true;
		}
	}
}

This worked good before, but now, user.Identity has only windowsPrincipal. So user is authenticated in FB, but I can't read user e-mail and other info. Any tips?

@elraider33
Copy link
Author

I was able to use the new version . Thanks for the help.

@ghost ghost locked as resolved and limited conversation to collaborators Jan 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants