/**
   * Shows keeping the access keys returned from Trusted Authenticator in a local store, rather than
   * storing user name & password, and re-authenticating each time (which is not to be done, ever).
   */
  private void storeAuth(AndroidAuthSession session) {
    // Store the OAuth 2 access token, if there is one.
    String oauth2AccessToken = session.getOAuth2AccessToken();
    Log.d(TAG, oauth2AccessToken);

    if (oauth2AccessToken != null) {
      SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
      Editor edit = prefs.edit();
      edit.putString(ACCESS_KEY_NAME, "oauth2:");
      edit.putString(ACCESS_SECRET_NAME, oauth2AccessToken);
      edit.commit();
      return;
    }
    // Store the OAuth 1 access token, if there is one.  This is only necessary if
    // you're still using OAuth 1.
    AccessTokenPair oauth1AccessToken = session.getAccessTokenPair();
    if (oauth1AccessToken != null) {
      SharedPreferences prefs = getSharedPreferences(ACCOUNT_PREFS_NAME, 0);
      Editor edit = prefs.edit();
      edit.putString(ACCESS_KEY_NAME, oauth1AccessToken.key);
      edit.putString(ACCESS_SECRET_NAME, oauth1AccessToken.secret);
      edit.commit();
      return;
    }
  }
 @Override
 public void onResume() {
   super.onResume();
   // refresh login state when coming back to the fragment
   refreshLoginState();
   // if already loggedin we don't need to continue
   if (authenticating) {
     // The next part must be inserted in the onResume() method of the
     // fragment from which session.startAuthentication() was called, so
     // that Dropbox authentication completes properly.
     AndroidAuthSession session = mApi.getSession();
     if (session.authenticationSuccessful()) {
       authenticating = false;
       try {
         // Mandatory call to complete the auth
         session.finishAuthentication();
         // Store it locally in the app for later use
         TokenPair tokens = session.getAccessTokenPair();
         storeKeys(tokens.key, tokens.secret);
         // set the preference flag
         setLoggedin(true);
         getDropboxAccountInfo();
       } catch (IllegalStateException e) {
         Toast.makeText(parentActivity, "Couldn't authenticate with Dropbox:", Toast.LENGTH_LONG)
             .show();
       }
     } // end of if authentication successful
   } else {
     // refresh Menu
     refreshMenus();
   }
 }
 @Override
 protected void onResume() {
   super.onResume();
   // Toast.makeText(ActivityTracksListView.this, "After onResume", Toast.LENGTH_SHORT).show();
   if (dropboxAuthenticationTry) {
     AndroidAuthSession session = dropbox.getSession();
     if (session.authenticationSuccessful()) {
       try {
         // Required to complete auth, sets the access token on the session
         session.finishAuthentication();
         TokenPair tokens = session.getAccessTokenPair();
         // String accessToken = dropbox.getSession().getOAuth2AccessToken();
         SharedPreferences prefs = getSharedPreferences(DROPBOX_PREF, 0);
         SharedPreferences.Editor editor = prefs.edit();
         editor.putString(APP_KEY, tokens.key);
         editor.putString(APP_SECRET, tokens.secret);
         editor.apply();
         Toast.makeText(
                 ActivityTracksListView.this, "Authentication successful", Toast.LENGTH_LONG)
             .show();
         // dropboxLoggedIn = true;
         uploadToDropbox();
       } catch (IllegalStateException e) {
         Log.i("DbAuthLog", "Error authenticating", e);
         Toast.makeText(
                 getApplicationContext(),
                 "Error during Dropbox authentication",
                 Toast.LENGTH_SHORT)
             .show();
       }
     }
     dropboxAuthenticationTry = false;
   }
 }
  @Override
  protected void onResume() {
    super.onResume();
    Toast.makeText(this, "PhotoShareActivity.onResume", Toast.LENGTH_SHORT).show();

    AndroidAuthSession session = mApi.getSession();

    // The next part must be inserted in the onResume() method of the
    // activity from which session.startAuthentication() was called, so
    // that Dropbox authentication completes properly.
    if (session.authenticationSuccessful()) {
      try {
        // Mandatory call to complete the auth
        session.finishAuthentication();

        // Store it locally in our app for later use
        TokenPair tokens = session.getAccessTokenPair();
        storeKeys(tokens.key, tokens.secret);

        uploadFiles();
        setLoggedIn(true);
      } catch (IllegalStateException e) {
        showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
        Log.i(TAG, "Error authenticating", e);
      }
    } else {
      Toast.makeText(this, "PhotoShareActivity.onResume: failed to auth", Toast.LENGTH_LONG).show();
    }
  }
Exemple #5
0
  public boolean FinishAuthorization() {
    AndroidAuthSession session = dropboxApi.getSession();
    if (!session.isLinked() && session.authenticationSuccessful()) {
      // Mandatory call to complete the auth
      session.finishAuthentication();

      // Store it locally in our app for later use
      TokenPair tokens = session.getAccessTokenPair();
      storeKeys(tokens.key, tokens.secret);
      return true;
    }

    return false;
  }
Exemple #6
0
 public void receiveTokenAndConnect() {
   // Dropbox API - recibe el token y se conecta
   AndroidAuthSession session = mApi.getSession();
   if (session.authenticationSuccessful()) {
     try {
       // Mandatory call to complete the auth
       session.finishAuthentication();
       // Store it locally in our app for later use
       TokenPair tokens = session.getAccessTokenPair();
       storeKeys(tokens.key, tokens.secret);
       setLoggedIn(true);
       // showToast("Logueado bien" + tokens.key + " - " + tokens.secret);
     } catch (IllegalStateException e) {
       showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
       Log.i(DropboxUtil.TAG, "Error authenticating", e);
     }
   }
 }
Exemple #7
0
  @Override
  protected void onResume() {
    super.onResume();

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onResume();

    try {
      /* Only activate FaceBook publish install if the user has the FaceBook app installed */
      if (com.facebook.Settings.getAttributionId(getContentResolver()) != null) {
        com.facebook.AppEventsLogger.activateApp(this);
      }
    } catch (IllegalStateException e) {
      Log.d(TAG, "Facebook Setting Exception again!");
    }

    AndroidAuthSession session = mApi.getSession();

    // The next part must be inserted in the onResume() method of the
    // activity from which session.startAuthentication() was called, so
    // that Dropbox authentication completes properly.
    if (session.authenticationSuccessful()) {
      try {
        // Mandatory call to complete the auth
        session.finishAuthentication();

        // Store it locally in our app for later use
        TokenPair tokens = session.getAccessTokenPair();
        storeKeys(tokens.key, tokens.secret);
        setLoggedIn(true);
      } catch (IllegalStateException e) {
        showToast("Couldn't authenticate with Dropbox:" + e.getLocalizedMessage());
        Log.i(TAG, "Error authenticating", e);
      }
    }
  }