【发布时间】:2019-11-20 23:19:17
【问题描述】:
我花了很多时间尝试在我的 Ionic 应用中使用 Google 帐户在 Firebase 上对我的用户进行身份验证。 我正在使用 Ionic 4 和 Angular。
我将这个问题和答案与我所做的研究一起发布,因为我无法在一个地方找到我需要的所有东西,我不得不进行大量搜索并尝试获得我想要的结果。
首先,我尝试了 2 种使用 firebase 软件包的方法,但这些方法让我无处可去:
拥有来自 firebase 的 google 提供商:
import * as firebase from 'firebase';
import { auth } from 'firebase/app';
import { AngularFireAuth } from '@angular/fire/auth';
...
const provider = new auth.GoogleAuthProvider();
第一次尝试是弹出式登录(虽然我知道这不是推荐的方式):
firebase.auth().signInWithPopup(provider).then(function(result) {
但我立即遇到了谷歌的障碍,告诉我我正在使用 dissallowed_useragent(因为 WebView)......所以这不是一个选项。
其次是使用同一个提供者的signInWithRedirect:
firebase.auth().signInWithRedirect(provider).then(function(result) {
然后用户被重定向到 Chrome 并且登录工作良好但之后它被重定向到 localhost/login(他离开应用程序的 URL)。 至此结束,登录未完成。
我的最后一个选择是 Ionic 的 Google Plus 插件:
https://ionicframework.com/docs/native/google-plus
但是在下面的代码之后:
this.googlePlus.login({
'webClientId': 'webclientid',
'offline': true,
'scopes': 'profile email'
}).then(res => {
...
});
什么都没有发生...甚至没有返回错误(也与 try - catch 一起使用)。
【问题讨论】:
-
你是否在 firebase 控制台中启用了 gmail
-
当然,忘了说了……这个是先启用的。
-
你有没有得到 eny 错误代码,例如 ->10
-
当我尝试使用 Google Plus 登录时,我没有收到任何错误。该功能默默地失败了。
标签: javascript angular firebase ionic-framework firebase-authentication