Facebook Auth0-获取提供程序用户id

Facebook Auth0-获取提供程序用户id,facebook,twitter,auth0,Facebook,Twitter,Auth0,目前,我依靠一个垃圾方法来获取提供者用户id(在社交网站的用户页面URL中使用的字符串/数字),该方法基于从/profile端点分割profile“sub”字段 我看到旧API有一个名为“Identifies”的字段,其中似乎存储了提供者用户id,新API是否有一个等效字段 基本上,它应该返回: facebook:如果未设置昵称,则为用户号码或url昵称mattiamanzati或100011120071734 推特:推特手柄mattiamanzati instagram:instagram句

目前,我依靠一个垃圾方法来获取提供者用户id(在社交网站的用户页面URL中使用的字符串/数字),该方法基于从/profile端点分割profile“sub”字段

我看到旧API有一个名为“Identifies”的字段,其中似乎存储了提供者用户id,新API是否有一个等效字段

基本上,它应该返回:

  • facebook:如果未设置昵称,则为用户号码或url昵称mattiamanzati100011120071734
  • 推特:推特手柄mattiamanzati
  • instagram:instagram句柄CenaCorte
这是我现在使用的代码,您可以看到提供程序和提供程序uid设置有多垃圾

var webAuth = new auth0.WebAuth({
  domain: "himy.eu.auth0.com",
  clientID: "0gz79WpxVxXNH5qeYRXXTxTQiWZZEV9S",
  redirectUri: window.location.href,
  audience: "https://himy.eu.auth0.com/userinfo",
  responseType: "token id_token",
  scope: "openid profile"
});

function handleAuthentication() {
  webAuth.parseHash(function(err, authResult) {
    if (authResult && authResult.accessToken && authResult.idToken) {
      window.location.hash = "";
      webAuth.client.userInfo(authResult.accessToken, function(err, profile) {
        if (profile) {
          if (window.postMessage) {
            if (profile.sub.indexOf("facebook") === 0) {
              profile.provider_uid = profile.sub.split("|")[1];
              profile.provider = "facebook";
            } else if (profile.sub.indexOf("instagram") === 0) {
              profile.provider_uid = profile.nickname;
              profile.provider = "instagram";
            }
            window.postMessage(JSON.stringify(profile));
          }
          console.log(profile);
        }
      });
    } else if (err) {
      console.log(err);
    }
  });
}

window.addEventListener("load", function(e) {
  if (!window.location.hash) {
    webAuth.authorize();
  } else {
    handleAuthentication();
  }
});

您应该只使用从API获得的用户id来标识用户。Facebook不再允许通过API访问用户名字段。我需要它不是为了识别用户,而是在单击用户配置文件时打开用户社交配置文件。然后使用适当的属性。。。对于Facebook,这将是用户对象的
链接
字段。有关于这方面的文档吗?我没有从profile对象中获取它,它需要任何额外的作用域吗?您需要询问Graph API v2.4之后需要的字段,不确定Auth0是否这样做。如果需要更多信息,请查看他们的文档。