@Override
    protected JSONObject doInBackground(Void... params) {
      JSONObject json = null;
      try {
        authToken = GoogleAuthUtil.getToken(main, "*****@*****.**", "oauth2:email");

        String path = "submitWhite/" + gameId;

        ArrayList<BasicNameValuePair> values = new ArrayList<BasicNameValuePair>();
        values.add(
            new BasicNameValuePair("whiteCardIdsJson", new JSONArray(whiteCardIds).toString()));

        json = httpEndpointsHandler.post(path, authToken, true, values);
      } catch (UserRecoverableAuthException e) {
        main.startActivityForResult(e.getIntent(), MainActivity.AUTH_REQUEST_CODE);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return json;
    }
    @Override
    protected String doInBackground(Void... params) {
      try {
        if (isCancelled()) {
          LOGD(TAG, "doInBackground: task cancelled, so giving up on auth.");
          return null;
        }

        LOGD(TAG, "Starting background auth for " + mAccountName);
        final String token = GoogleAuthUtil.getToken(mAppContext, mAccountName, AUTH_TOKEN_TYPE);

        // Save auth token.
        LOGD(
            TAG,
            "Saving token: "
                + (token == null ? "(null)" : "(length " + token.length() + ")")
                + " for account "
                + mAccountName);
        AccountUtils.setAuthToken(mAppContext, mAccountName, token);
        return token;
      } catch (GooglePlayServicesAvailabilityException e) {
        postShowRecoveryDialog(e.getConnectionStatusCode());
      } catch (UserRecoverableAuthException e) {
        postShowAuthRecoveryFlow(e.getIntent());
      } catch (IOException e) {
        LOGE(TAG, "IOException encountered: " + e.getMessage());
      } catch (GoogleAuthException e) {
        LOGE(TAG, "GoogleAuthException encountered: " + e.getMessage());
      } catch (RuntimeException e) {
        LOGE(TAG, "RuntimeException encountered: " + e.getMessage());
      }
      return null;
    }
Beispiel #3
0
 @Override
 protected String doInBackground(String... params) {
   String accountName = params[0];
   String scopes = "oauth2:profile email";
   String token = null;
   try {
     token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
   } catch (IOException e) {
     Log.e(TAG, e.getMessage());
   } catch (UserRecoverableAuthException e) {
     startActivityForResult(e.getIntent(), REQUEST_CODE_TOKEN_AUTH);
   } catch (GoogleAuthException e) {
     Log.e(TAG, e.getMessage());
   }
   return token;
 }
Beispiel #4
0
    @Override
    protected String doInBackground(Void... params) {
      String token = null;

      try {
        token =
            GoogleAuthUtil.getToken(
                getApplicationContext(),
                mPlusClient.getAccountName(),
                "oauth2:" + Scopes.PLUS_LOGIN);
      } catch (Exception e) {
        Log.e("getTokenError", e.getMessage());
      }

      return token;
    }
 private String getAccessToken(final String syncAccount) {
   try {
     return GoogleAuthUtil.getToken(
         getApplicationContext(), syncAccount, OAUTH_SCOPE_PREFIX + DriveScopes.DRIVE_FILE);
   } catch (UserRecoverableAuthException e) {
     Intent authRequiredIntent = new Intent(HomeActivity.LB_AUTH_APP);
     authRequiredIntent.putExtra(HomeActivity.EXTRA_AUTH_APP_INTENT, e.getIntent());
     LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(authRequiredIntent);
     stopSelf();
   } catch (IOException e) {
     // FIXME do exponential backoff
   } catch (GoogleAuthException e) {
     Log.e(getClass().getSimpleName(), "Fatal authorization exception", e);
   }
   return null;
 }
  public static String getAuthToken(Context context) {
    if (!mGoogleApiClient.isConnected()) {
      mGoogleApiClient.connect();
    }
    String accountName = Plus.AccountApi.getAccountName(mGoogleApiClient);
    Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    String scopes = "audience:server:client_id:" + SERVER_CLIENT_ID; // Not the app's client ID.

    try {
      return GoogleAuthUtil.getToken(context, account, scopes);
    } catch (IOException e) {
      Log.e(TAG, "Error retrieving ID token.", e);
      return null;
    } catch (GoogleAuthException e) {
      Log.e(TAG, "Error retrieving ID token.", e);
      return null;
    }
  }
    @Override
    protected JSONObject doInBackground(Void... params) {
      JSONObject json = null;
      try {
        authToken = GoogleAuthUtil.getToken(main, "*****@*****.**", "oauth2:email");

        String path = "fetchPlayers/" + gameId;

        json = httpEndpointsHandler.get(path, authToken, true, null);
      } catch (UserRecoverableAuthException e) {
        main.startActivityForResult(e.getIntent(), MainActivity.AUTH_REQUEST_CODE);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return json;
    }
    @Override
    protected JSONObject doInBackground(String... params) {
      String path = "fetchCurrentSubmissions/" + gameId;

      JSONObject json = null;
      try {
        authToken = GoogleAuthUtil.getToken(main, "*****@*****.**", "oauth2:email");

        ArrayList<BasicNameValuePair> values = new ArrayList<BasicNameValuePair>();
        values.add(new BasicNameValuePair("status", Integer.toString(1)));

        json = httpEndpointsHandler.get(path, authToken, true, values);
      } catch (UserRecoverableAuthException e) {
        main.startActivityForResult(e.getIntent(), MainActivity.AUTH_REQUEST_CODE);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (GoogleAuthException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      return json;
    }