Java Code Examples for com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential#setSelectedAccountName()

The following examples show how to use com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential#setSelectedAccountName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GAEService.java    From security-samples with Apache License 2.0 6 votes vote down vote up
private void initFido2GAEService() {
    if (fido2Service != null) {
        return;
    }
    if (googleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingAudience(
                    context, "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(googleSignInAccount.getEmail());
    Log.d(TAG, "credential account name " + credential.getSelectedAccountName());

    Fido2RequestHandler.Builder builder =
            new Fido2RequestHandler.Builder(
                    AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential)
                    .setGoogleClientRequestInitializer(
                            new GoogleClientRequestInitializer() {
                                @Override
                                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                        throws IOException {
                                    abstractGoogleClientRequest.setDisableGZipContent(true);
                                }
                            });
    fido2Service = builder.build();
}
 
Example 2
Source File: GAEService.java    From android-fido with Apache License 2.0 6 votes vote down vote up
private void initFido2GAEService() {
    if (fido2Service != null) {
        return;
    }
    if (googleSignInAccount == null) {
        return;
    }
    GoogleAccountCredential credential =
            GoogleAccountCredential.usingAudience(
                    context, "server:client_id:" + Constants.SERVER_CLIENT_ID);
    credential.setSelectedAccountName(googleSignInAccount.getEmail());
    Log.d(TAG, "credential account name " + credential.getSelectedAccountName());

    Fido2RequestHandler.Builder builder =
            new Fido2RequestHandler.Builder(
                    AndroidHttp.newCompatibleTransport(), new AndroidJsonFactory(), credential)
                    .setGoogleClientRequestInitializer(
                            new GoogleClientRequestInitializer() {
                                @Override
                                public void initialize(AbstractGoogleClientRequest<?> abstractGoogleClientRequest)
                                        throws IOException {
                                    abstractGoogleClientRequest.setDisableGZipContent(true);
                                }
                            });
    fido2Service = builder.build();
}
 
Example 3
Source File: MessagingService.java    From watchpresenter with Apache License 2.0 6 votes vote down vote up
public static Messaging get(Context context){
    if (messagingService == null) {
        SharedPreferences settings = context.getSharedPreferences(
                "Watchpresenter", Context.MODE_PRIVATE);
        final String accountName = settings.getString(Constants.PREF_ACCOUNT_NAME, null);
        if(accountName == null){
            Log.i(Constants.LOG_TAG, "Cannot send message. No account name found");
        }
        else {
            GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(context,
                    "server:client_id:" + Constants.ANDROID_AUDIENCE);
            credential.setSelectedAccountName(accountName);
            Messaging.Builder builder = new Messaging.Builder(AndroidHttp.newCompatibleTransport(),
                    new GsonFactory(), credential)
                    .setRootUrl(Constants.SERVER_URL);

            messagingService = builder.build();
        }
    }
    return messagingService;
}
 
Example 4
Source File: BaseGmailProvider.java    From PrivacyStreams with Apache License 2.0 5 votes vote down vote up
private void checkGmailApiRequirements() {


        String accountName = PreferenceManager.getDefaultSharedPreferences(getContext())
                .getString(PREF_ACCOUNT_NAME, null);

        if (accountName != null) {
            GoogleAccountCredential mCredential = GoogleAccountCredential.usingOAuth2(
                    getContext().getApplicationContext(), Arrays.asList(SCOPES))
                    .setBackOff(new ExponentialBackOff());
            mCredential.setSelectedAccountName(accountName);

            if (!DeviceUtils.isGooglePlayServicesAvailable(getContext())) {
                DeviceUtils.acquireGooglePlayServices(getContext());
            }
            else{
                mService = new Gmail.Builder(
                        AndroidHttp.newCompatibleTransport(), JacksonFactory.getDefaultInstance(), mCredential)
                        .setApplicationName(AppUtils.getApplicationName(getContext()))
                        .build();
                authorized = true;
            }


        } else {
            GmailAuthorizationActivity.setListener(this);
            getContext().startActivity(new Intent(getContext(), GmailAuthorizationActivity.class));
        }

    }
 
Example 5
Source File: SendToGoogleUtils.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the google account credential.
 * 
 * @param context the context
 * @param accountName the account name
 * @param scope the scope
 */
public static GoogleAccountCredential getGoogleAccountCredential(
    Context context, String accountName, String scope) throws IOException, GoogleAuthException {
  GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
  credential.setSelectedAccountName(accountName);
  credential.getToken();
  return credential;
}
 
Example 6
Source File: ConferenceUtils.java    From conference-central-android-app with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build and returns an instance of {@link com.appspot.udacity_extras.conference.Conference}
 *
 * @param context
 * @param email
 * @return
 */
public static com.appspot.udacity_extras.conference.Conference buildServiceHandler(
        Context context, String email) {
    GoogleAccountCredential credential = GoogleAccountCredential.usingAudience(
            context, AppConstants.AUDIENCE);
    credential.setSelectedAccountName(email);

    com.appspot.udacity_extras.conference.Conference.Builder builder
            = new com.appspot.udacity_extras.conference.Conference.Builder(
            AppConstants.HTTP_TRANSPORT,
            AppConstants.JSON_FACTORY, credential);
    builder.setApplicationName("conference-central-server");
    return builder.build();
}
 
Example 7
Source File: SendToGoogleUtils.java    From mytracks with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the OAuth2 token.
 * 
 * @param context the context
 * @param accountName the account name
 * @param scope the scope
 */
public static String getToken(Context context, String accountName, String scope)
    throws IOException, GoogleAuthException {
  GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
  credential.setSelectedAccountName(accountName);
  return credential.getToken();
}