Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Mobile app showing the AeroGear Authz feature on Android

Author: Daniel Passos (dpassos) & Summers Pittman (supittma)
Level: Beginner
Technologies: Java, Android
Summary: A basic example of OAuth2 : Login and retrieve data.
Source: https://github.com/aerogear/aerogear-android-cookbook/tree/master/GDrive

What is it?

GDrive project demonstrates how to include Authz/OAuth2 functionality in Android applications.

This simple project consists of a ready-to-build Android application. Before building the application, you must create an OAuth2 credential in Google's console. The credentials must then be inserted into the application source code. After this is complete, the application can be built and deployed to Android devices.

When the application is deployed to an Android device, the application will ask for your Google credentials, ask permission to access your account and retrieve your documents.

How do I run it?

System Requirements


The project source code must be customized with your Google credentials.

  1. Open /path/to/gdrive/src/org/jboss/aerogear/android/example/gdrive/Constants.java for editing.

  2. Enter the client id, client secret and redirect url for the following constants:

    String AUTHZ_CLIENT_ID = "";
    String AUTHZ_CLIENT_SECRET = "";
    String AUTHZ_REDIRECT_URL = "";

For the complete instructions about how to setup Google credentials, visit our OAuth2 documentation guide

Build Application

$ cd /path/to/gdrive/
$ ./gradlew clean build

Running the app

To deploy, run and debug the application on an Android device attached to your system, on the command line enter the following:

  1. Install generated apk to device

    $ cd /path/to/gdrive
    $ ./gradlew installDebug
  2. Open app on device

How does it work?

MainActivity is invoked. The Activity life cycle onStart is called first invoking the authz method — attempting to display a Google login screen.

authzModule = AuthorizationManager.config("GoogleDriveAuthz", OAuth2AuthorizationConfiguration.class)
        .setBaseURL(new URL(AUTHZ_URL))
        .setAdditionalAuthorizationParams(ImmutableSet.of(Pair.create("access_type", "offline")))

authzModule.requestAccess(this, new Callback<String>() {
    public void onSuccess(String o) {
        Log.d("TOKEN ++ ", o);

    public void onFailure(Exception e) {
        Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();