title: Google Sign-In using Firebase in React Native
body: <p><strong><em>Note the question might be long because of the need for explanation otherwise it might be very vague and lead to same old answers.</em></strong></p>
  
  <p>I am having problem in creating a <code>Google Sign-In</code> page in <code>React Native</code> using <strong><em>firebase</em></strong>. Based on <strong>firebase</strong> documentation:</p>
  
  <blockquote>
    <p>With the updates in the 3.1.0 SDK, almost all of the JavaScript SDK’s
    functionality should now work smoothly in React Native. But there are
    a couple caveats:</p>
    
    <ul>
    <li>"Headful" auth methods such as signInWithPopup(), signInWithRedirect(), linkWithPopup(), and linkWithRedirect() do not
    work in React Native (or Cordova, for that matter). You can still sign
    in or link with a federated provider by using <code>signInWithCredential()</code>
    with an OAuth token from your provider of choice.</li>
    </ul>
  </blockquote>
  
  <p>which means I <strong><em>cannot</em></strong> use following code in my <strong>React Native</strong> project:</p>
  
  <pre><code>var provider = new firebase.auth.GoogleAuthProvider();
  
  firebase.auth().signInWithPopup(provider).then(function(result) {
  
    // This gives you a Google Access Token. You can use it to access the Google API.
    var token = result.credential.accessToken;
    // The signed-in user info.
    var user = result.user;
    // ...
  
  }).catch(function(error) {
    // Handle Errors here.
    var errorCode = error.code;
    var errorMessage = error.message;
    // The email of the user's account used.
    var email = error.email;
    // The firebase.auth.AuthCredential type that was used.
    var credential = error.credential;
    // ...
  });
  </code></pre>
  
  <p>Then with some googling and searching over dozens of stackoverflow, I found following way to use use <strong>Google SignIn</strong> using <strong><em>Firebase API</em></strong>
  in <strong>React Native</strong> project as:</p>
  
  <pre><code>const provider = firebase.auth.GoogleAuthProvider;
  const credential = provider.credential(token);
  
    firebase.auth().signInWithCredential(credential)
      .then((data) =&gt; {
        console.log('SUCCESS', data);
      })
      .catch((error) =&gt; {
        console.log('ERROR', error)
      });
  </code></pre>
  
  <p>Now in <strong>just above code</strong>, you might have noticed <strong>token</strong> in following line:</p>
  
  <blockquote>
    <p>const credential = provider.credential(<strong>token</strong>);</p>
  </blockquote>
  
  <p>So based on <strong><em>firebase</em></strong> documentation, <strong>token</strong> is obtained as follows:</p>
  
  <pre><code>// `googleUser` from the onsuccess Google Sign In callback.
  var token = googleUser.getAuthResponse().id_token;
  </code></pre>
  
  <p>So my question is how do I obtain that <strong>token</strong> using GoogleUser object or whatever it is in <strong>React Native?</strong> Or is there another way?</p>