簡體   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