且构网

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

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

更新时间:2023-11-20 11:51:28

如果您是使用 Firebase Auth 的 signInWithPopup/Redirect 登录,您将只能在登录后获得访问令牌.Firebase Auth 不会为您存储它(它也不会存储 Facebook 刷新令牌).您需要将其保存在数据库中,只有指定的用户可以访问它,并且通过 Firebase 函数的 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.