javascript - Facebook OAuth 与 Firebase 和 Expo

标签 javascript react-native firebase-authentication expo

我有一个使用 Expo 和 m Firebase 作为后端创建的 react native 应用程序。

我已经完成 Facebook 登录,这给了我 facebook token

现在我已经获得了 facebook token ,我正在尝试集成我的应用程序以使用 Firebase(以便我拥有 Firebase 用户 ID),但我遇到了困难

网上搜了一下,只找到了Google Oauth的代码

googleAuthenticate = (idToken, accessToken) => {
      const credential = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);
      return firebase.auth().signInWithCredential(credential);
};

任何人都可以分享他们如何将 facebook oauth 与 firebase 与 Expo 结合在一起吗?谢谢

最佳答案

这是来自 Facebook 和 google 的身份验证代码。

Facebook 代码:

LoginManager
        .logInWithReadPermissions(['public_profile', 'email'])
        .then((result) => {
            if (!result.isCancelled) {
                console.log(`Login success with permissions: ${result.grantedPermissions.toString()}`)
                // get the access token
                return AccessToken.getCurrentAccessToken()
            }
        })
        .then(data => {
            if (data) {
                // create a new firebase credential with the token
                const credential = firebase.auth.FacebookAuthProvider.credential(data.accessToken)
                // login with credential
                return firebase.auth().signInWithCredential(credential)
            }
        })
        .then((currentUser) => {
            if (currentUser) {
                //Here is user profile 
            }
        }

Google 代码:

 GoogleSignin.configure()
        .then(() => {
            GoogleSignin.signIn()
                .then((data) => {
                    // create a new firebase credential with the token
                    const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken)

                    // login with credential
                    return firebase.auth().signInWithCredential(credential)

                })
                .then((currentUser) => {
                   //Here is user profile
                }

这是简单的登录代码:

firebase.auth().signInWithEmailAndPassword(this.state.username, this.state.password)
                            .then((user) => {
                               //Here is user profile after login
                            }

谢谢,如果需要更多,请告诉我!!

关于javascript - Facebook OAuth 与 Firebase 和 Expo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48780386/

相关文章:

javascript - AngularJS ng-repeat 的性能问题

javascript - 上传成功但没有上传文件?

javascript - Meteor 登录 - 注销 ~ 钩子(Hook)/回调

ios - CocoaPods 找不到 pod 的兼容版本 "boost-for-react-native"

Firebase 以其他用户身份登录

javascript - 如何将 Node 模块导入我的 backbone.js 应用程序?

javascript - Uncaught Error : Invariant Violation: Element type is invalid: expected a string

xcode - 使用静态框架,如 Realm,通过 Cocoapods 安装 React-Native

android - Firebase UI - 身份验证 - 使用自己的布局

android - java.lang.NoSuchMethodError : No virtual method setTokenProvider 错误