【问题标题】:How to get location claim when using Facebook OAuth provider使用 Facebook OAuth 提供程序时如何获取位置声明
【发布时间】:2016-09-30 14:06:22
【问题描述】:

我正在尝试在使用 facebook OAuth 时为用户获取位置(或地点)(我没有尝试使用 google,但我也想要它)

我已经在我的启动文件中设置了我的范围,如下所示:

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

我想我需要为我想要收集的那些额外声明添加配置,但我不确定从哪里开始,我们将不胜感激。

【问题讨论】:

    标签: c# oauth asp.net-core


    【解决方案1】:

    需要添加location字段:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-07-28
    • 2022-01-23
    • 2018-03-20
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    • 2014-07-13
    相关资源
    最近更新 更多