The newest version of Google Identity Toolkit has been released as Firebase Authentication. It includes upgraded client SDKs, open source UI libraries, session management and integrated email sending service for forgotten password flows.

New projects should use Firebase Authentication. To migrate an existing project from Identity Toolkit to Firebase Authentication, see the migration guide.

GitkitClient

public class GitkitClient

The main entry for identitytoolkit integration.

GitkitClient is used in the login activity, which is usually the first activity of the application. the following example shows how to integrate with it.

 public class MyLoginActivity extends Activity {

     private GitkitClient client;

     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         // If there is no signed in user, create a GitkitClient to start sign in flow.
         SignInCallbacks callbacks = new SignInCallbacks() {
             // Implement the onSignIn method of GitkitClient.SignInCallbacks interface.
             @Override
             public void onSignIn(IdToken idToken, GitkitUser gitkitUser) {
                 // Send the idToken to the server. The server should issue a session cookie/token
                 // for the app if the idToken is verified.
                 authenticate(idToken.getTokenString());
                 ...
             }

             // Implement the onSignInFailed method of GitkitClient.SignInCallbacks interface.
             @Override
             public void onSignInFailed() {
                 // Handle the sign in failure.
                 ...
             }
         }
         // The example suppose all necessary configurations are set in the AndroidManifest.xml.
         // You can also set or overwrite them by calling the corresponding setters on the
         // GitkitClientBuilder.
         client = GitkitClient.newBuilder(this, callbacks).build();
         // Start sign in flow.
         client.startSignIn();
     }

     @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent data) {
         if (client.handleActivityResult(requestCode, resultCode, data)) {
             // result is handled by GitkitClient.
             return;
         }
         // Otherwise, the result is not returned to GitkitClient and should be handled by the
         // activity.
         ...
     }

     @Override
     protected void onNewIntent(Intent intent) {
         if (client.handleIntent(intent)) {
             // intent is handled by the GitkitClient.
             return;
         }
         // Otherwise, the intent is not for GitkitClient and should be handled by the activity.
         ...
     }
 }
 

Nested Class Summary

interface GitkitClient.SignInCallbacks Interface for callback methods which are called when the sign in process is finished. 

Public Method Summary

void
boolean
handleActivityResult(int requestCode, int resultCode, Intent data)
boolean
handleIntent(Intent intent)
static GitkitClientBuilder
newBuilder(Activity activity, GitkitClient.SignInCallbacks callbacks)
void

Public Methods

public void destroy ()

Destroys the client. It should be called from Activity.onDestroy() such that pending requests get canceled.

public boolean handleActivityResult (int requestCode, int resultCode, Intent data)

Handles the result returned from other activities. During the sign in flow, other activities may be launched to help complete the authentication flow. After the result is returned, this method should be called from Activity.onActivityResult() to handle the result and continue the process. For example,

 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
     if (client.handleActivityResult(requestCode, resultCode, intent)) {
         // The result is returned to and handled by the GitkitClient.
         return;
     }
     // Not a result returned to the GitkitClient. It should be handled by the app.
     ...
 }
 

Parameters
requestCode the requestCode passed to Activity.onActivityResult(int, int, Intent)
resultCode the resultCode passed to Activity.onActivityResult(int, int, Intent)
data the data passed to Activity.onActivityResult(int, int, Intent)
Returns
  • true if the data is returned to and handled by the client successfully.

public boolean handleIntent (Intent intent)

Handles the result returned from other activities. During the sign in flow, the system web browser may be launched to help complete the authentication flow. After the user finishes it in the web browser, a result is redirected back to the activity via custom scheme URL. Normally the activity should be started with singleTask launch mode so it can receive the result in its Activity.onNewIntent(Intent). For example,

 @Override
 protected void onNewIntent(Intent intent) {
     if (client.handleIntent(intent)) {
         // The result is returned to and handled by the GitkitClient.
         return;
     }
     // Not a result returned to the GitkitClient. It should be handled by the app.
     ...
 }
 

Parameters
intent the intent passed to Activity.onNewIntent(Intent)
Returns
  • true if the intent is returned to and handled by the client successfully.

public static GitkitClientBuilder newBuilder (Activity activity, GitkitClient.SignInCallbacks callbacks)

Parameters
activity the activity that is creating the client.
callbacks the GitkitClient.SignInCallbacks that handles sign in result.

public void startSignIn ()

Starts the sign in process.