在Firebase中创建用户后获取身份提供商令牌

问题描述 投票:0回答:1

我正在开发一个“登录Google”和“使用Facebook登录”按钮的网络应用程序。用户成功登录Firebase支持的应用后,我希望能够对其Google和Facebook数据进行API调用。示例是从Google相册或Facebook中获取照片。

通常,当您在网络上使用Google Auth API并登录时,这很容易做到,您可以获得可以传递给服务器和服务器的Auth Code,一次性使用访问令牌和刷新令牌的代码并将其存储在服务器端用于任何未来的API调用。以下是此方法教程的链接 - https://developers.google.com/identity/sign-in/web/server-side-flow

Firebase是我的后端,FirebaseUI对我的网络应用程序的用户进行身份验证,如何获取可以传递给Firebase功能的代码,然后可以将其交换为Access Token和Refresh Token,并将其保存到Firestore中以进行进一步的API调用。

javascript firebase firebaseui
1个回答
0
投票

您可以使用来自firebaseUI的signInSuccessWithAuthResult回调:https://github.com/firebase/firebaseui-web#signinsuccesswithauthresultauthresult-redirecturl它将公开userCredential对象。对于像google和facebook这样的OAuth提供商,您可以使用userCredential.credential访问OAuthCredetial。此接口的参考文献如下:https://firebase.google.com/docs/reference/js/firebase.auth.OAuthCredential

© www.soinside.com 2019 - 2024. All rights reserved.