我有一个使用 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/