使用Google Plus的Ionic Angular Firebase身份验证不起作用 [英] Ionic Angular Firebase authentication with Google Plus not working
问题描述
我花了很多时间尝试使用Ionic应用程序中的Google帐户在Firebase上对我的用户进行身份验证. 我在Angular上使用Ionic 4.
I've spent a lot of time trying to authenticate my users on Firebase with a Google account in my Ionic app. I'm using Ionic 4 with Angular.
我正在用我所做的研究发布此问题和答案,因为我无法在一处找到我需要的所有东西,因此我不得不进行大量搜索并尝试获得想要的结果.
I'm posting this question and answer with the research I've made because I could not find everything I needed in one place and I had to go through a lot of searches and tries to get the result I wanted.
首先,我尝试使用Firebase软件包进行2种方法,这些方法使我无处可寻:
First of all I've tried 2 ways with the firebase packages that lead me nowhere:
从firebase拥有google提供程序:
Having a google provider from firebase:
import * as firebase from 'firebase';
import { auth } from 'firebase/app';
import { AngularFireAuth } from '@angular/fire/auth';
...
const provider = new auth.GoogleAuthProvider();
第一次尝试是弹出式登录(尽管我不建议这样做):
First try was the popup sign in (although I know that is not the recommended way):
firebase.auth().signInWithPopup(provider).then(function(result) {
但是我立即遇到了Google的障碍,告诉我我正在使用 dissallowed_useragent (由于使用了WebView)...所以这不是一个选择.
But I immediately ran into google's barrier that tell me that I'm using a dissallowed_useragent (because of WebView) ... so this is not an option.
第二个是使用相同提供程序的signInWithRedirect:
Second is signInWithRedirect using the same provider:
firebase.auth().signInWithRedirect(provider).then(function(result) {
然后,将用户重定向到Chrome,然后将登录重定向到localhost/login(他离开应用程序时使用的URL)后,登录即可正常运行. 到此为止,登录尚未完成.
The user is then redirected to Chrome and the login works good BUT after that it gets redirected to localhost/login (the URL that he left the app with). So it ends there and the login is not completed.
我的最后一个选择是Ionic的Google Plus插件:
https://ionicframework.com/docs/native/google-plus
但是下面的代码之后:
My last option was the Google Plus plugin from Ionic:
https://ionicframework.com/docs/native/google-plus
But after the following code:
this.googlePlus.login({
'webClientId': 'webclientid',
'offline': true,
'scopes': 'profile email'
}).then(res => {
...
});
什么也没发生...甚至没有返回任何错误(与try一起使用-catch也是如此).
Nothing happened ... not even an error was returned (used with try - catch as well).
推荐答案
问题是android project.properties一些使用旧版本的库. 解决方案是在platform/android/project.properties中重写它们.
The problem is that the android project.properties some libraries where using old versions. The solution is to rewrite them in platforms/android/project.properties.
我也在使用Ionic Appflow进行构建,因此我必须在config.xml中执行此操作. 所以..我安装了cordova-plugin-platform-replace并在config.xml中添加了以下几行:
I am also using Ionic Appflow to build so I had to do this in config.xml. So .. I installed cordova-plugin-platform-replace and added the following lines in config.xml:
<platform name="android">
<replace-string file="project.properties" find="com.google.android.gms:play-services-auth:11.8.0" replace="com.google.android.gms:play-services-auth:+" />
<replace-string file="project.properties" find="com.google.android.gms:play-services-identity:11.8.0" replace="com.google.android.gms:play-services-identity:+" />
现在,所有内容都像魅力一样.
Now everything works like a charm.
我在这篇文章中找到了答案: https://github.com/EddyVerbruggen/cordova-plugin- googleplus/issues/487#issuecomment-402683868
I found the answer at this post: https://github.com/EddyVerbruggen/cordova-plugin-googleplus/issues/487#issuecomment-402683868
希望这可以帮助其他人节省一些时间.
Hope this helps others save some time.
这篇关于使用Google Plus的Ionic Angular Firebase身份验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!