2
votes

I am trying to use the Firestore HTTP REST APIs from React Native.

I am only using HTTP (no SDK).

After the user has logged in with Google Signin (react-native-google-signin), I have an idToken and accessToken.

I want to be able to convert one of these into a Firebase idToken that can be used in the 'Authorization': 'Bearer ${firebaseIdToken}' HTTP header using only the Firebase REST HTTP APIs

https://firebase.google.com/docs/reference/rest/auth/#section-verify-custom-token

  • Input "token"="A Firebase Auth custom token".
    • Neither idToken or accessToken from the Google Signin work here.
    • Do I need to send the Google idToken to the server to convert it to a Firebase Auth idToken?

Before I was using these SDK calls for auth:

const cred = firebase.auth.GoogleAuthProvider.credential(idToken, accessToken);
await firebase.auth().signInAndRetrieveDataWithCredential(cred)
const firebaseIdToken = await firebase.auth().currentUser.getIdToken();
const headers = { 
    'Authorization': `Bearer ${firebaseIdToken}`
}

Related links

https://github.com/react-native-community/react-native-google-signin https://firebase.google.com/docs/auth/admin/create-custom-tokens

1

1 Answers

3
votes

You can use the REST API to exchange an OAuth credential for a Firebase ID token: https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-with-oauth-credential