繁体   English   中英

具有Ionic 2 Google身份验证的Firebase 3

[英]Firebase 3 with ionic 2 google authentication

我是移动应用程序开发和ionic 2的新手。使用angularfire2,我可以使Google身份验证在Web应用程序上正常运行,但是在移动设备上不起作用(还可以吗?)。 我正在使用ionic 2版本2.0.0-beta.35和firebase 3.2.1

搜索使我了解到,暂时需要使用已安装的cordova的google +插件。

我正在我的ts代码中尝试此方法:

loginWithGooglePlugin()
{
    return Observable.create(observer =>
    {
        // note for iOS the googleplus plugin requires ENABLE_BITCODE to be turned off in the Xcode
        window.plugins.googleplus.login(
            {
                'scopes': 'profile email', // optional, space-separated list of scopes, If not included or empty, defaults to `profile` and `email`.
                'webClientId': '_google_client_app_id_.apps.googleusercontent.com',
                'offline': true, // optional, but requires the webClientId - if set to true the plugin will also return a serverAuthCode, which can be used to grant offline access to a non-Google server
            },
            function (authData)
            {
                console.log('got google auth data:', JSON.stringify(authData, null, 2));
                let provider = firebase.auth.GoogleAuthProvider.credential(authData.idToken, authData.accessToken);
                firebase.auth().signInWithCredential(provider).then((success) =>
                {
                    console.log('success!', JSON.stringify(success, null, 2));
                    observer.next(success);
                }, (error) =>
                {
                    console.log('error', JSON.stringify(error, null, 2))
                });
            },
            function (msg)
            {
                this.error = msg;
            }
        );
    });
}

但是编译器一直抱怨两件事:1. window.plugins未知。 我如何才能说服它在那里?

  1. GoogleAuthProvider对象上没有credential 搜索产生了以下链接: firebase docs ,其中说有方法getCredential ,该方法也无法识别。

我的typings似乎很好。 GoogleAuthProvider本身被识别。

我怎样才能解决这个问题?

实际上,这是打字稿定义中的错误。 Firebase团队已收到通知,正在修复。 同时,使用以下解决方法:

(<any> firebase.auth.GoogleAuthProvider).credential 

在我的Ionic2 RC1 + Firebase3.5 + AngularFire2.beta5项目中,我遇到了同样的问题... Google Auth with Popup在浏览器中起作用,但在我的Android .APK中却不起作用

首先,我将192.168.1.172添加到我的Firebase控制台授权域列表中,并将<allow-navigation href="http://192.168.1.172:8100"/>到我的config.xml中

之后,我发现安装Cordova InAppBrowser插件可以彻底解决我的问题。

就像David East在Ionic博客的社交登录中所说的那样,我不需要修改代码,只需即插即用。

暂无
暂无

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

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