首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ionic的Google-Plus和Firebase身份验证插件一起使用时不起作用

Ionic的Google-Plus和Firebase身份验证插件一起使用时不起作用
EN

Stack Overflow用户
提问于 2019-05-24 00:47:34
回答 2查看 449关注 0票数 0

Ionic的google-plus和firebase身份验证插件在一起使用时无法正常工作。

我正在尝试使用google-plus和Ionic的firebase身份验证插件一起对用户进行firebase身份验证。google+插件是独立工作的,我得到了idToken和accessToken。当我添加firebase身份验证插件并运行构建时,什么也没有发生。google-plus插件没有响应,也没有错误。

下面是离子信息...

ionic (Ionic CLI):4.1.0 (/home/chandra/.npm-global/lib/node_modules/ionic)离子框架: ionic-angular 3.9.5 @ Ionic /应用程序脚本: 3.2.2

cordova (Cordova CLI):9.0.0 ( Cordova -lib@9.0.1) Cordova平台: android 7.1.1 cordova插件:cordova-plugin-ionic keyboard 2.1.3,cordova-plugin-ionic webview 4.0.1,(以及8个其他插件)

Android SDK工具: 26.1.1 NodeJS : v8.10.0 (/usr/bin/node) npm : 6.4.0操作系统: Linux 4.15

下面是单击"Login with Google“按钮时调用的函数。

代码语言:javascript
复制
googlePlusLogin() {
  console.log("Trying to do Gooogle sign-in ....");
  this.gplus.login({ webClientId:  "xxx.apps.googleusercontent.com" })
  .then(res => {
    console.log("Google response: ", res);
    signinCallback(res);
  })
  .catch(err => console.error(err));

  let me = this;
  function signinCallback(authResult) {
    let res = me.firebaseAuth.signInWithGoogle(
      authResult.idToken,
      authResult.accessToken
    );
    console.log("Firebase Auth Result: ", res);
  }
}

我打算将google-plus插件提供的idToken和accessToken传递给firebase身份验证插件,这样firebase就可以进行身份验证了。

EN

回答 2

Stack Overflow用户

发布于 2019-05-24 17:39:19

为什么你要为Google Plus使用一个单独的插件(这只是一个Google登录)?我使用的是Firebase插件,Google身份验证就是通过下面这段代码来处理的

代码语言:javascript
复制
import * as firebase from 'firebase';

...

googleLogin()
{
    const provider = new firebase.auth.GoogleAuthProvider();
    return this.afAuth.auth.signInWithPopup(provider).then((result) => {
        var uid = result.user.uid
        var name = result.user.displayName
        var email = result.user.email
        var photoURL = result.user.photoURL
        this.linkUser(uid, email, name, photoURL)
    })
}
票数 0
EN

Stack Overflow用户

发布于 2019-08-07 12:03:44

我也在使用做同样的事情,这是对我有效的:

代码语言:javascript
复制
async googleSignin(){
  try{
    const gpRes = await this.googlePlus.login({})  
      //webClientId is only required when we need the offline support, but for starting this is okay.
    const credential = this.afAuth.auth.signInWithCredential(auth.GoogleAuthProvider.credential(null, gpRes.accessToken));
      //Here also within Credential() first parameter is idToken and then accessToken, both are optional and I pass only the accessToken which is enough

      //TODO: Get the signed in user data from credential.user and update UI or change the route
  } catch (error){
     //TODO: Handle error here
  }
}

我希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56279748

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档