带有 ionic 2 google 身份验证的 Firebase 3
Firebase 3 with ionic 2 google authentication
我是移动应用程序开发和 ionic 2 的新手。我的 google 身份验证对于使用 angularfire2 的 Web 应用程序工作正常,但在移动设备上不起作用(还?)。
我正在使用 ionic 2 版本 2.0.0-beta.35 和 firebase 3.2.1
通过搜索,我了解到目前我需要使用我已经安装的 google+ cordova 插件。
我正在我的 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 未知。我怎样才能让 ts 相信它在那里?
GoogleAuthProvider
对象上没有 credential
。搜索得到这个 link: 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.
之后,我发现installing Cordova InAppBrowser插件彻底解决了我的问题。
我不需要修改我的代码,只需即插即用,就像 David East 在他的 Social login with Ionic blog.
中所说的那样
我是移动应用程序开发和 ionic 2 的新手。我的 google 身份验证对于使用 angularfire2 的 Web 应用程序工作正常,但在移动设备上不起作用(还?)。 我正在使用 ionic 2 版本 2.0.0-beta.35 和 firebase 3.2.1
通过搜索,我了解到目前我需要使用我已经安装的 google+ cordova 插件。
我正在我的 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 未知。我怎样才能让 ts 相信它在那里?
GoogleAuthProvider
对象上没有credential
。搜索得到这个 link: 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.
之后,我发现installing Cordova InAppBrowser插件彻底解决了我的问题。
我不需要修改我的代码,只需即插即用,就像 David East 在他的 Social login with Ionic blog.
中所说的那样