title: Trouble using Firebase Auth to access google API via gapi SDK
body: <p>In my firebase (Angular) app, I'm using firebase authentication to log a user in via their Google Profile. As part of this process, the user gives me permission to access their gmail account (scope <code>'https://www.googleapis.com/auth/gmail.compose'</code>).</p>
  
  <p>After the user has logged in this way, I want to configure the "gapi" google javascript SDK so that the "signed in user" is the user signed in via firebase auth. Here's where I'm having trouble.</p>
  
  <ol>
  <li><p>It appears that I need to set the client token for the <code>gapi</code> sdk like so <code>gapi.client.setToken(userAccessToken)</code> and the token needs to be set before the gapi client is initialized. Attempting to do this doesn't seem to work however (a call to <code>gapi.auth2.getAuthInstance().isSignedIn.get()</code> returns <code>false</code> when it should return <code>true</code>).</p></li>
  <li><p>I also can't figure out a way of changing the "signed in user" if the firebase user logs out and a new one logs in. This is because, again, the gapi client seems to require the <code>gapi.client.setToken()</code> be called before the client is initialized, and I can't see any way of <code>re-initializing</code> and already initialized gapi client.</p></li>
  </ol>
  
  <p>I can get the gapi client working if I use the gapi client's own <code>gapi.auth2.getAuthInstance().signIn()</code> method, but then the user is asked to sign in to my app twice using (from the user's perspective) identical google login popup boxes (one prompt originating from firebase auth and the other from the gapi client).</p>
  
  <p>Does anyone have any suggestions / tips? After someone logs in via firebase auth I can get access to their <code>userAccessToken</code>, I just can't figure out how to programmatically pass that to the gapi client in a clean way.</p>
  
  <h3>Ideally:</h3>
  
  <ul>
  <li>on application load the <code>gapi</code> client would also load and initialize.</li>
  <li>When a user chose to sign in, I would be able to use Firebase Auth to log someone in via their google profile, then get their access token and pass it to the gapi client to make google api calls.
  
  <ul>
  <li>If the firebase user ever logged out, I would clear the gapi client's api token.</li>
  <li>If a new firebase user logged in, I would re-set the gapi client's api token.</li>
  </ul></li>
  </ul>