简体   繁体   English

具有Firebase和Expo的Facebook OAuth

[英]Facebook OAuth with Firebase and Expo

I have a react-native app created with Expo and m Firebase as the backend. 我有一个使用Expo和m Firebase作为后端创建的React-native应用程序。

I have already done the Facebook login which gives me the facebook token 我已经完成了Facebook登录,这给了我Facebook令牌

Now that I have gotten the facebook token, I am trying to integrate my app to use Firebase (so that i have the Firebase userid) which I am encountering difficulties 现在,我已经获得了facebook令牌,我正在尝试集成我的应用程序以使用Firebase(以便我拥有Firebase用户ID),但遇到了困难

I searched online and only found the code for Google Oauth 我在网上搜索,只找到了Google Oauth的代码

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

Anyone can share how they integrate facebook oauth with firebase together with Expo? 任何人都可以分享他们如何将Facebook oauth与firebase以及Expo集成在一起? Thanks 谢谢

Here is code for auth from Facebook and google. 这是来自Facebook和google的身份验证代码。

Facebook Code: 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 Code: 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
                }

And this is simple login code: 这是简单的登录代码:

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

Thanks and let me know if need more!! 谢谢,让我知道是否需要更多!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM