1

I am using Firebase Auth for login and sign up. I am trying to integrate google sign in. Now I have gotten a google Oauth ID that I need to convert into a Firebase ID token so that I can sign in using the authroization header.

const FirebaseIdToken = `Bearer ${token}`;
  localStorage.setItem("FirebaseIdToken", FirebaseIdToken);
  API.defaults.headers.common["Authorization"] = FirebaseIdToken;

I am following this link: https://firebase.google.com/docs/reference/rest/auth/#section-sign-in-with-oauth-credential to get a post request but I am having trouble doing it.

  const data = {
    postBody: token, //Google Oauth token
  };

  API.post(
    `https://identitytoolkit.googleapis.com/v1/accounts:signInWithIdp?key=[API-KEY]`,
    { data }
  ).then((res) => {
    console.log(res);
    console.log(res.data);
  });

I just get a Post 400 error. The body also asks for a requestUri which I'm not sure what that is.

EnglishBanana
  • 121
  • 1
  • 8

1 Answers1

2

You need to pass the following data:

const data = {
  returnSecureToken: true,
  requestUri: 'url-where-your-app-is-served-eg-http://localhost',
  postBody:`id_token=${token}&providerId=google.com`,
};
bojeil
  • 29,642
  • 4
  • 69
  • 76