title: Authenticate with signInWithCredential()
body: <p>I'm trying to connect to the second Firebase app and authenticate with <code>signInWithCredential()</code>, but I don't know how to get valid <strong><code>idToken</code></strong> for the second app: </p>
  
  <pre><code>  connect(accessToken: string, config: FirebaseAppConfig) {
      let one: firebase.app.App = this.angularFireTwo.database["fbApp"];
      one.auth().currentUser.getToken()
        .then(idToken =&gt; firebase.auth.GoogleAuthProvider.credential(idToken, accessToken))
        .then(credential =&gt; {
          let two = firebase.initializeApp(config, `[${config.apiKey}]`);
          return two.auth().signInWithCredential(credential);
        })
        .catch(console.warn)
        .then(console.info);
    }
  </code></pre>
  
  <p>I'm getting and error from <code>https://www.googleapis.com/identitytoolkit/v3/</code>:</p>
  
  <blockquote>
    <p>Invalid id_token in IdP response</p>
  </blockquote>
  
  <p>If I use <code>signInWithPopup()</code> I can authenticate and connection is working:</p>
  
  <pre><code>        two.auth().signInWithPopup(new firebase.auth.GoogleAuthProvider())
  </code></pre>
  
  <p>Anyone knows what should I do to get valid idToken?</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I've been trying to figure out authentication process and, as far I understand it , it's something like this:</p>
  
  <ol>
  <li>from <code>config: FirebaseAppConfig</code> firebase reads <code>apiKey</code> and <code>authDomain</code></li>
  <li>it contacts the servers and gets <strong>Web Client ID</strong> for enabled Google provider <code>123.apps.googleusercontent.com</code></li>
  <li>with this <code>Web Client ID</code> and <code>authDomain</code> it contacts www.googleapis.com, which returns <code>idToken</code></li>
  <li>this <code>idToken</code> is then used to identify the app that's asking user for permission to access user's profile, etc.</li>
  <li>when user agrees, callback returns user details + credential used for this authentication, which contains <code>idToken</code> of the web app and <code>accessToken</code> of the user</li>
  </ol>
  
  <p>Now, if I use <code>signInWithPopup()</code> steps 2-3-4 are done in the background (popup window). I just need a way to generate <code>idToken</code> for the step 4, so I can use it to generate credential <code>firebase.auth.GoogleAuthProvider.credential(idToken, accessToken)</code> and sign-in using <code>signInWithCredential()</code>.</p>
  
  <p>I have access to everything I need to sign-in to the second app - it's; <code>apiKey</code>, <code>authDomain</code>, Web Client id <code>456.apps.googleusercontent.com</code>, and user's unique <code>accessToken</code>.</p>
  
  <p>But still can't figure out how to do it. I tried white-listing apps' <strong>one</strong> and <strong>two</strong> Web client IDs in their auth configurations, hoping that will allow them to accept each others <code>idToken</code>s, but that didn't work...</p>