title: Migrating from Google Sign-In for Android to Firebase Authentication
body: <p>Currently, we plan to use <a href="https://developers.google.com/identity/sign-in/android/backend-auth" rel="noreferrer">Google Sign-In for Android</a>, as our server authentication method.</p>
  
  <p>This is what we plan to do.</p>
  
  <h2>Client side (Google Sign-In for Android)</h2>
  
  <pre><code>GoogleSignInAccount account = completedTask.getResult(ApiException.class);
  // This idToken will sent to backend server.
  String idToken = account.getIdToken();
  </code></pre>
  
  <h2>Server side (Google Sign-In for Android)</h2>
  
  <pre><code>// Based on received idToken from client, backend server will call https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=... 
  // to identify who is this user.
  
  {
   // These six fields are included in all Google ID Tokens.
   "iss": "https://accounts.google.com",
   "sub": "110169484474386276334",
   "azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
   "aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
   "iat": "1433978353",
   "exp": "1433981953",
  
   // These seven fields are only included when the user has granted the "profile" and
   // "email" OAuth scopes to the application.
   "email": "testuser@gmail.com",
   "email_verified": "true",
   "name" : "Test User",
   "picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
   "given_name": "Test",
   "family_name": "User",
   "locale": "en"
  }
  </code></pre>
  
  <hr>
  
  <p>In the future, we might want to migrate to provide more login option. This is my future migration plan, to migrate from Google Sign-In for Android to Firebase Authentication.</p>
  
  <h2>Client side (Firebase Authentication)</h2>
  
  <pre><code>FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
  mUser.getIdToken(true)
      .addOnCompleteListener(new OnCompleteListener&lt;GetTokenResult&gt;() {
          public void onComplete(@NonNull Task&lt;GetTokenResult&gt; task) {
              if (task.isSuccessful()) {
                  // This idToken will sent to backend server.
                  String idToken = task.getResult().getToken();
  
              } else {
                  // Handle error -&gt; task.getException();
              }
          }
      });
  </code></pre>
  
  <h2>Server side (Google Sign-In for Android)</h2>
  
  <pre><code># idToken comes from the client app (shown above)
  decoded_token = auth.verify_id_token(idToken)
  uid = decoded_token['uid']
  </code></pre>
  
  <hr>
  
  <p>My questions are</p>
  
  <ol>
  <li><p>For <strong>Google Sign-In for Android</strong>, We plan to store <code>"sub": "110169484474386276334"</code>, as an unique identifier to represent a user. Is that a correct field to be used? Is it unique per user? My testing so far is, at client side, we might get different <code>idToken</code> for a same user (At different day). Different <code>idToken</code> from same user, will <strong>still</strong> yield same <code>sub</code> at server side.</p></li>
  <li><p>One day, we might migrate to <strong>Firebase Authentication</strong> to support more login methods. Is it still backward compatible with <code>Google Sign-In for Android</code>. Is <code>Firebase Authentication</code> able to return same <code>"sub"</code> as what is previously returned by <code>Google Sign-In for Android</code>? As you can see in the code example, <code>Firebase Authentication</code> is returning <code>uid</code>. </p></li>
  </ol>
  
  <p>How can I compare new <code>Firebase Authentication</code>'s <code>uid</code>, with previous stored <code>Google Sign-In</code>'s <code>sub</code>?</p>