Reputation: 16066
I'm trying to get the location (or locality) for the user when using facebook OAuth (I haven't tried with google but it's something that I would like too)
I already have set up my scope in my startup file like this:
app.UseFacebookAuthentication(new FacebookOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ClientId = "",
ClientSecret = "",
Scope = {"email",
"user_friends",
"user_location" }
});
the problem is when I do a
_signInManager.GetExternalLoginInfoAsync()
I'm always getting the same claim types, so I'd like to add the locality or any other claim type available (like username instead email for example).
when I do:
var user = new ApplicationUser
{
ProviderKey = info.ProviderKey,
Email = info.Principal.FindFirstValue(ClaimTypes.Email),
Name = info.Principal.FindFirstValue(ClaimTypes.GivenName),
Surname = info.Principal.FindFirstValue(ClaimTypes.Surname),
AuthenticationType = info.LoginProvider,
NormalizedUserName = info.Principal.FindFirstValue(ClaimTypes.Email),
UserName = info.Principal.FindFirstValue(ClaimTypes.Email),
Location = info.Principal.FindFirstValue(ClaimTypes.Locality), // I'm getting null here
Created = DateTime.UtcNow
};
I think I need to add a configuration for those extra claims I want to collect but I'm not sure where to start, any help will be appreciated.
Upvotes: 0
Views: 78
Reputation: 24133
You need to add location
field:
app.UseFacebookAuthentication(new FacebookOptions
{
AutomaticAuthenticate = true,
AutomaticChallenge = true,
ClientId = "",
ClientSecret = "",
Scope = {"email", "user_friends", "user_location" },
Fields = {"location"}
});
Upvotes: 1