如何在使用Facebook OAuth提供程序时获得位置声明

本文关键字:程序 声明 位置 OAuth Facebook | 更新日期: 2023-09-27 18:09:31

当使用facebook OAuth时,我试图获得用户的位置(或位置)(我没有尝试过谷歌,但这是我想要的东西)

我已经在我的启动文件中设置了我的作用域,像这样:

app.UseFacebookAuthentication(new FacebookOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge = true,
                ClientId = "",
                ClientSecret = "",
                Scope = {"email",
                        "user_friends",
                        "user_location" }
            });

问题是当我执行

_signInManager.GetExternalLoginInfoAsync()

我总是得到相同的索赔类型,所以我想添加位置或任何其他可用的索赔类型(例如,用户名代替电子邮件)。

当我这样做时:

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
 };

我想我需要为那些我想收集的额外索赔添加一个配置,但我不确定从哪里开始,任何帮助都会很感激。

如何在使用Facebook OAuth提供程序时获得位置声明

需要添加location字段:

app.UseFacebookAuthentication(new FacebookOptions
{
      AutomaticAuthenticate = true,
      AutomaticChallenge = true,
      ClientId = "",
      ClientSecret = "",
      Scope = {"email", "user_friends", "user_location" },
      Fields = {"location"}
});