I have a flutter mobile application for both ios/android. I decided to add social login using google for both android and ios, using the google_sign_in package.
I have created two client ids, on google console for android and ios respectively.
In flutter I am trying to get the idtoken usign the following code:
GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
String? googleToken = googleAuth.idToken;
For ios everything works fine and I am able to get the idtoken and send it to my backend server. For android however, i am able to see the popup with sign in with google, select the google account, and then i get the idtoken as null.
The oauth2 client id is set up as an android application and the sha-1 certificate is correctly registred as per my release signing key.
An important mention will be that i am not using and i don’t want to use firebase for this. I want to retrieve the idtoken which I am sending to my backend for validation, and generate a jwt for my app which i return back to the flutter to be used for further calls.
Any ideas why this idtoken is coming null for android and it works for ios?
Thanks!
3
Answers
For anyone struggling with the same issue, the only solution that worked is described in this comment: Solution
If you are getting a null ID token on Android when using Google Sign-In, one common issue is that the OAuth 2.0 client ID in your Google Developer Console is not configured correctly for your Android app.
Make sure you have correctly associated the SHA-1 certificate fingerprint of your Android app’s signing key with the OAuth 2.0 client ID in the Google Developer Console.
Verify that you have specified the correct package name for your Android app in the OAuth 2.0 client ID configuration.
Ensure that your Android app has the necessary permissions, including INTERNET and ACCESS_NETWORK_STATE, in the AndroidManifest.xml file.
Double-check your code implementation for Google Sign-In in your Flutter app to retrieve the ID token from the GoogleSignInAccount object.