如何从Firebase Admin获取Facebook ID? [英] How to get Facebook ID from Firebase Admin?

查看:57
本文介绍了如何从Firebase Admin获取Facebook ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Admin在我的NodeJs应用程序中登录.客户端将通过发送一个idToken(从Firebase获取)登录,然后NodeJs服务器将使用admin.auth().verifyIdToken(idToken)获取用户.

I'm using Firebase Admin for login in my NodeJs app. Client will login by sending an idToken (which is get from Firebase), and then NodeJs server will get the user by using admin.auth().verifyIdToken(idToken).

结果将如下所示:

{ iss: 'https://securetoken.google.com/myapp-5cde1',
  name: 'Manh Hung',
  picture: 'https://graph.facebook.com/185960225411xxx/picture',
  aud: 'xxxxxx-5cde1',
  auth_time: 1526626xxx,
  user_id: 'uCxxxxxxxxxxxxxxxQR4d2',
  sub: 'uCwNoxxxxxxxxxxxxxxuQR4d2',
  iat: 15266xxx1,
  exp: 15266xxx91,
  firebase:
   { identities: { 'facebook.com': [Array] },
     sign_in_provider: 'facebook.com' },
  uid: 'uCxxxxxxxxxxxxxxxQR4d2' 
}

是的,我通过"sign_in_provider:'facebook.com'"通过Facebook获得了用户的注册方法.但是我不知道如何获取用户的Facebook ID. 有人可以给我建议吗?非常感谢!

Yes, I got the user's registration method is by Facebook via "sign_in_provider: 'facebook.com'". But I don't know how to get user's Facebook ID. Can someone give me an advice? So many thanks!

推荐答案

该特定信息在ID令牌中不可用.您将需要使用Firebase Admin SDK查找用户并检查providerData:

That specific information will not be available in the ID token. You will need to use the Firebase Admin SDK to lookup the user and inspect the providerData:

admin.auth().getUser(uid)
  .then(function(userRecord) {
    // Assuming the first provider linked is facebook.
    // The facebook ID can be obtained as follows.
    console.log(userRecord.providerData[0].uid);
  })
  .catch(function(error) {
    console.log("Error fetching user data:", error);
  });

这篇关于如何从Firebase Admin获取Facebook ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆