AuthSession Google Auth in Emulator/Expo Go

Ultimately the newer Auth Session instructions never worked for me. Instead I was able to get expo-google-app-auth working.

What was missing from my previous attempts to use expo-google-app-auth was the creation of iOS and Android specific “Client IDs” in the online google console at https://console.cloud.google.com/apis/credentials.

To get expo-google-app-auth working you must:

  1. Create an “Android proxy” client id and “iOS proxy” client id at https://console.cloud.google.com/apis/credentials with the “package name” as host.exp.exponent.
    Note: the link provided may not take you to the correct page immediately. You may need to first select the appropriate app from the dropdown selector in the top navbar (up to the left)

  2. Copy the “client id” created for use with expo-google-app-auth

  3. Add the “client id” to code as seen in below example

import * as firebase from 'firebase';
import * as GoogleAuth from 'expo-google-app-auth';

const iOSExpoClient = <your iOS expo proxy client id>
const androidExpoClient = <your android expo proxy client id>

const signInWithGoogle = async () => {
  try {
    const result = await GoogleAuth.logInAsync({
      iosClientId: iOSExpoClient,
      androidClientId: androidExpoClient,
      scopes: ['profile', 'email']
    });
    
    if (result.type  === 'success') {
      console.log('success', result)
      // Get credentials
      const credential = firebase.auth.GoogleAuthProvider.credential(data.idToken, data.accessToken);
      // Use credentials to login to firebase
      firebase.auth().signInWithCredential(credential);
    }
  } catch ({ message }) {
    alert('login: Error:' + message);
  }
}

The code should return the credentials you need to firebase.signInWithCredential(). You should be able to now auth with google from any emulated device. Note, you will probably want to handle the “client ids” as an environment variable or key. They are in the code this way just for the sake of the example.