Does anyone know the right set of steps to take to get my login with google button (that works in my web app) to work in an android build? Here’s what I’ve done/worked out:
Starting point
I had inferred from the meteor docs that Google login should “just work” in Android (and in IOS too, for that matter). Indeed the build automatically includes cordova-plugin-googleplus
cordova plugin which further cements this perception. Not only that but when I run the android build on a locally connected android device in debug mode, the build prints out a special warning to say it won’t work in a local environment. Which suggests that it will work when run against a production server. Also, I cannot find any Meteor documentation that directs what steps to take to make it work.
Manifestation
When I click on the Login with Google
button in the Android app, it does in fact popup the Google window asking you to login. That’s fine. It’s just that when the window pops down again I get an “unknown error”. It’s difficult even in the web app to debug/trace errors in the oauth dance that is deep in the Accounts package infrastructure, so I have not, as yet, attempted to identify the error, preferring instead to at least set things up so that I can expect it to work …
Setting up
I am now assuming more steps do need to be taken and I am struggling to find what these are. I have, however, done the following in the google firebase console, but with no success:
- I have a project with Google login enabled and set an entry in my
mobile-config.js
to configure the cordova-plugin-googleplus
plugin with the Web Client Id
as identified in this google sign in provider section that I have enabled
- I have created an Android app whose package name is the same as the id specified in the App.info() properties set in my mobile-config.js
- I have lodged the SHA-1 certificate fingerprint from the certificate with which I signed the android app
I’ve just summarised these actions so that, for anyone in the know, they will understand them and be able to comment on whether they are relevant and/or incomplete.
Is there anyone out there “in the know”?
Many thanks
Does you login method look anything like this?
settings.json
......
"loginStyle": "popup",
"scope": [
"email",
"https://www.googleapis.com/auth/plus.login",
"https://www.googleapis.com/auth/contacts.readonly"
]
Meteor.loginWithGoogle({ requestPermissions: scope, loginStyle, requestOfflineToken: true }, err => {
if (err) {
console.log(err)
if (err !== 'The user canceled the sign-in flow.') {
console.log('Could not sign in', err)
}
.........
Hi,
I am using the Meteor user accounts which means that I have not coded anything like the above explicitly. I’m pretty sure these packages handle all this for me. For example, there’s an old comment inside the file google_sign-in.js
within the google-oath
package that reads:
// After 20 April 2017, Google OAuth login will no longer work from a
// WebView, so Cordova apps must use Google Sign-In instead.
// https://github.com/meteor/meteor/issues/8253
And the code clearly actions accordingly. This is one of the reasons that I’m pretty sure that Meteor accounts sorts it all out for you and I just need to set it up right in the Google developer console…
I think your documentation is from somewhere between Cretaceous and Jurassic ![:slight_smile: :slight_smile:](https://emoji.discourse-cdn.com/twitter/slight_smile.png?v=9)
This is the package: https://github.com/meteor/meteor/blob/46e00a875726dff078c59eaf7fdc7b956cf0a996/packages/accounts-google/google.js
You need to pass options and callback.
This shows you the options you need to pass and how to pass them. https://github.com/meteor/meteor/issues/10609
I confirm that I used this early 2020.
OK, I solved this, so for the record …
If you are using the Meteor user accounts built in then you make no changes to your Meteor code. This is what I suspected. The only thing you have to do is set more things up in Google developer console.
The below is as documented in the cordova google plus plugin, but as it’s not Meteor specific there is a lot of wood around the trees you are looking for, so the below distills the specific thing that I needed to do.
Assuming you had google login working successfully in the web app, then you would have set up a project in Google APIs and created an OAuth 2.0 Client ID for Web application in the Credentials section. There you will have to set up authorised JS origins and redirect URIs.
In order for your google login button to work in an android build, you need to set up another OAuth 2.0 Client ID, this time for Android. Here you don’t specify redirect URIs and the like, but instead you must supply two things in common with your Meteor Android build:
- The Package name that is a reversed domain path that you must also set as your app Id in the
App.info()
details your mobile-config.js
file, as exampled here:
App.info({
id: 'com.<your domain>.<sub domain>'
// etc
});
- The SHA-1 certificate finger print taken from the certificate that you used to sign your APK.
That’s all - easy when you know how!
1 Like