Example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential getScope

List of usage examples for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential getScope

Introduction

In this page you can find the example usage for com.google.api.client.googleapis.extensions.android.gms.auth GoogleAccountCredential getScope.

Prototype

public final String getScope() 

Source Link

Document

Returns the scope to use on GoogleAuthUtil#getToken .

Usage

From source file:com.jefftharris.passwdsafe.sync.gdrive.GDriveProvider.java

License:Open Source License

@Override
public void cleanupOnDelete(String acctName) {
    Account acct = getAccount(acctName);
    setAcctName(null);/*w ww .  j a  v  a 2  s. co  m*/
    updateAcct();
    try {
        GoogleAccountCredential credential = getAcctCredential(itsContext);
        String token = GoogleAuthUtil.getTokenWithNotification(itsContext, acct, credential.getScope(), null);
        PasswdSafeUtil.dbginfo(TAG, "Remove token for %s", acctName);
        if (token != null) {
            GoogleAuthUtil.clearToken(itsContext, token);
        }
    } catch (Exception e) {
        PasswdSafeUtil.dbginfo(TAG, e, "No auth token for %s", acctName);
    }
}

From source file:com.jefftharris.passwdsafe.sync.gdrive.GDriveProvider.java

License:Open Source License

/**
 * Retrieve a authorized service object to send requests to the Google
 * Drive API. On failure to retrieve an access token, a notification is
 * sent to the user requesting that authorization be granted for the
 * {@code https://www.googleapis.com/auth/drive} scope.
 *
 * @return An authorized service object and its auth token.
 *///from w  w w .  j a va 2s. com
private static Pair<Drive, String> getDriveService(Account acct, Context ctx) {
    Drive drive = null;
    String token = null;
    try {
        GoogleAccountCredential credential = getAcctCredential(ctx);
        credential.setBackOff(new ExponentialBackOff());
        credential.setSelectedAccountName(acct.name);

        token = GoogleAuthUtil.getTokenWithNotification(ctx, acct, credential.getScope(), null,
                PasswdSafeContract.AUTHORITY, null);

        Drive.Builder builder = new Drive.Builder(AndroidHttp.newCompatibleTransport(),
                JacksonFactory.getDefaultInstance(), credential);
        builder.setApplicationName(ctx.getString(R.string.app_name));
        drive = builder.build();
    } catch (UserRecoverableNotifiedException e) {
        // User notified
        PasswdSafeUtil.dbginfo(TAG, e, "User notified auth exception");
        try {
            GoogleAuthUtil.clearToken(ctx, null);
        } catch (Exception ioe) {
            Log.e(TAG, "getDriveService clear failure", e);
        }
    } catch (GoogleAuthException e) {
        // Unrecoverable
        Log.e(TAG, "Unrecoverable auth exception", e);
    } catch (IOException e) {
        // Transient
        PasswdSafeUtil.dbginfo(TAG, e, "Transient error");
    } catch (Exception e) {
        Log.e(TAG, "Token exception", e);
    }
    return new Pair<>(drive, token);
}