AuthSession Google Auth in Emulator/Expo Go

  1. SDK Version: 41
  2. Platforms: Android/iOS

I am attempting to implement Firebase Google authentication and test it on an iOS emulator. My first step is to auth with google and get the token needed to send to firebase. I am stuck on the first step.

After attempting to use expo-google-sign-in and expo-google-app-auth, neither of which got me past a 400 error (because of the redirect bing expo?). I am now attempting to implement AuthSession. I am using the instructions found here with the “firebase” tab selected for the example code.

  • I have the correct client_id’s and have added the appropriate authorized URIs and redirect URIs on the google cloud platform.
  • Test code is as seen in the example from the above linked instructions.
  • I am logged in via expo-login
  • Running iOS emulator

The error I get when attempting to initiate Google.useIdTokenAuthRequest is:
Error: Cannot make a deep link into a standalone app with no custom scheme defined]

How can I setup my code so that I can test the google auth and get back the request response?

Did you find any solution? I am facing the same problem.

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.

@mosleyjr how did you initialize firebase, a bunch of online tutorials told audience to initialize firebase using webclient appId.
But Google OAuth would first authenticated using ios proxy/android proxy clientId, then firebase.auth().SignInWithCredentials would complain about the tokens from not from the web app.
Any advices?

When you see import * as firebase from 'firebase' I am importing “firebase” which has already been initialized elsewhere.

You should follow the instructions here to initialize firebase. I initialize firebase in my “app.js” file

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.