expo: accessToken and idToken are undefined when calling GoogleSignIn.signInAsync()
š Bug Report
When calling the new GoogleSignIn.signInAsync() method, accessToken and idToken are undefined. To test this I created a new android standalone build expo build:android and installed on my device. The sign in is successful but the accessToken and idToken are undefined. I need this to be able to sign into firebase.
I followed these docs: https://docs.expo.io/versions/v33.0.0/sdk/google-sign-in/
Seems to work ok when I was using the old Expo.Google way to sign in: https://docs.expo.io/versions/v33.0.0/sdk/google/
Environment
Expo CLI 2.20.5 environment info: System: OS: Windows 10 Binaries: npm: 6.2.0 - C:\Program Files\nodejs\npm.CMD
Testing this on Android, not iOS.
Steps to Reproduce
I have the following code:
try {
// Docs show that clientID is for IOS only. I'm testing on Android only.
await GoogleSignIn.initAsync();
} catch ({ message }) {
alert('GoogleSignIn.initAsync(): ' + message);
}
try {
await GoogleSignIn.askForPlayServicesAsync();
const { type, user } = await GoogleSignIn.signInAsync();
if (type === 'success') {
// I get a success here but user.idToken is null
// Sign into Firebase with the credential from the Google user.
const credential = firebase.auth.GoogleAuthProvider.credential(user.idToken, user.accessToken);
firebase
.auth()
.signInAndRetrieveDataWithCredential(credential)
.then(function(result) {
alert('Firebase sign in success');
})
.catch(function(error) {
console.error('Error with Firebase sign in ', error.message);
});
}
} catch ({ message }) {
alert('login: Error:' + message);
}
Expected Behavior
accessToken and idToken should be returned.
Actual Behavior
accessToken and idToken are undefined.
Reproducible Demo
Canāt create snack as GoogleSignIn cannot be used with the Expo client, only standalone.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (5 by maintainers)
Yeah thatās what I did (this API canāt be used in the Expo client, so standalone is the only option)
Steps for successful googleSignIn behavior-
expo init newprojectandroid.packagein app.json tocom.example.newprojectandroid.packageexpo.android.googleServicesFileto the relative path of your google-services.json fileexpo build:android, once itās completed runexpo fetch:android:hashesand copy Google Certificate FingerprintI got firebase to work now too. I was stupidly using the stringified version of
user.auth.idTokenanduser.auth.accessToken. Correct code:This is happening to me in the android studio emulator, but it works for ios.
My app.json looks like:
my firebase project setting has the Package name as: com.appname, the google-services.json file is in the correct locationā¦
Not sure where the issue is.
EDIT: I also added the debug SHA-1 certificate displayed when executing this command from the terminal:
keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore