且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Firebase函数中获取提供商访问令牌?

更新时间:2023-11-20 11:34:16

如果您使用Firebase Auth signInWithPopup/Redirect登录,则只有在登录后才能获取访问令牌. Firebase Auth不会为您存储它(也不会存储Facebook刷新令牌).您将需要将其保存在数据库中,只有指定的用户可以访问它,而通过Firebase Functions的Admin SDK可以允许您访问它.如果您认为Firebase Auth应该为提供商管理OAuth令牌,请通过Firebase支持渠道提出请求. 如果这对于您的应用程序功能至关重要,则可以使用Facebook API登录用户并获取Facebook访问令牌,然后使用firebase.auth().signInWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken))登录 Facebook客户端API可以为您管理OAuth令牌.您还可以在需要时使用后端OAuth node.js库通过Firebase函数刷新Facebook令牌.不过,您将需要获取Facebook刷新令牌.

If you are signing in with Firebase Auth signInWithPopup/Redirect, you will only get the access token after sign-in. Firebase Auth does not store it for you (neither does it store the Facebook refresh token). You will need to save it in the Database where only the specified user can access it and the Admin SDK via Firebase Functions can allow you access it. If you think Firebase Auth should manage OAuth tokens for providers, please file a request via Firebase Support channels. If this is essential for your app functionality, you can use the Facebook API to sign in the user and get a Facebook access token and sign in with firebase.auth().signInWithCredential(firebase.auth.FacebookAuthProvider.credential(fbAccessToken)) Facebook client API can manage the OAuth token for you. You can also use a backend OAuth node.js library to refresh Facebook tokens via the Firebase Functions whenever you need one. You would need to get the Facebook refresh token though.