Esempio n. 1
0
 @Override
 public void onAuthenticationChosen(BoxAuthenticationInfo authInfo) {
   if (authInfo != null) {
     BoxAuthentication.getInstance().onAuthenticated(authInfo, OAuthActivity.this);
     dismissSpinnerAndFinishAuthenticate(authInfo);
   }
 }
Esempio n. 2
0
 @Override
 public void finish() {
   clearCachedAuthenticationData();
   if (!mAuthWasSuccessful) {
     BoxAuthentication.getInstance().onAuthenticationFailure(null, null);
   }
   super.finish();
 }
Esempio n. 3
0
 protected void startOAuth() {
   // Use already logged in accounts if not disabled in this activity and not already showing this
   // fragment.
   if (authType != AUTH_TYPE_APP
       && !getIntent().getBooleanExtra(EXTRA_DISABLE_ACCOUNT_CHOOSING, false)
       && getSupportFragmentManager().findFragmentByTag(CHOOSE_AUTH_TAG) == null) {
     Map<String, BoxAuthenticationInfo> map =
         BoxAuthentication.getInstance().getStoredAuthInfo(this);
     if (SdkUtils.isEmptyString(getIntent().getStringExtra(EXTRA_USER_ID_RESTRICTION))
         && map != null
         && map.size() > 0) {
       FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
       transaction.replace(
           R.id.oauth_container,
           ChooseAuthenticationFragment.createAuthenticationActivity(this),
           CHOOSE_AUTH_TAG);
       transaction.addToBackStack(CHOOSE_AUTH_TAG);
       transaction.commit();
     }
   }
   switch (authType) {
     case AUTH_TYPE_APP:
       Intent intent = getBoxAuthApp();
       if (intent != null) {
         intent.putExtra(BoxConstants.KEY_CLIENT_ID, mClientId);
         intent.putExtra(BoxConstants.KEY_REDIRECT_URL, mRedirectUrl);
         if (!SdkUtils.isEmptyString(getIntent().getStringExtra(EXTRA_USER_ID_RESTRICTION))) {
           intent.putExtra(
               EXTRA_USER_ID_RESTRICTION, getIntent().getStringExtra(EXTRA_USER_ID_RESTRICTION));
         }
         startActivityForResult(intent, REQUEST_BOX_APP_FOR_AUTH_CODE);
         break;
       }
     case AUTH_TYPE_WEBVIEW:
       showSpinner();
       this.oauthView = createOAuthView();
       this.oauthClient = createOAuthWebViewClient(oauthView.getStateString());
       oauthClient.setOnPageFinishedListener(this);
       oauthView.setWebViewClient(oauthClient);
       if (mSession.getBoxAccountEmail() != null) {
         oauthView.setBoxAccountEmail(mSession.getBoxAccountEmail());
       }
       oauthView.authenticate(mClientId, mRedirectUrl);
       break;
     default:
   }
 }
Esempio n. 4
0
  protected Intent getBoxAuthApp() {
    // ensure that the signature of the Box application has an official signature.
    Intent intent = new Intent(BoxConstants.REQUEST_BOX_APP_FOR_AUTH_INTENT_ACTION);
    List<ResolveInfo> infos =
        getPackageManager()
            .queryIntentActivities(
                intent, PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_RESOLVED_FILTER);

    if (infos == null || infos.size() < 1) {
      return null;
    }
    String officialBoxAppString = getResources().getString(R.string.boxsdk_box_app_signature);
    for (ResolveInfo info : infos) {
      try {
        Signature[] signatures =
            getPackageManager()
                .getPackageInfo(info.activityInfo.packageName, PackageManager.GET_SIGNATURES)
                .signatures;
        if (officialBoxAppString.equals(signatures[0].toCharsString())) {
          intent.setPackage(info.activityInfo.packageName);
          Map<String, BoxAuthenticationInfo> authenticatedMap =
              BoxAuthentication.getInstance().getStoredAuthInfo(this);
          if (authenticatedMap != null && authenticatedMap.size() > 0) {
            ArrayList<String> authenticatedUsers = new ArrayList<String>(authenticatedMap.size());
            for (Map.Entry<String, BoxAuthenticationInfo> set : authenticatedMap.entrySet()) {
              if (set.getValue().getUser() != null) {
                authenticatedUsers.add(set.getValue().getUser().toJson());
              }
            }
            if (authenticatedUsers.size() > 0) {
              intent.putStringArrayListExtra(BoxConstants.KEY_BOX_USERS, authenticatedUsers);
            }
          }

          return intent;
        }
      } catch (Exception e) {

      }
    }

    return null;
  }
Esempio n. 5
0
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (RESULT_OK == resultCode && REQUEST_BOX_APP_FOR_AUTH_CODE == requestCode) {
     String userId = data.getStringExtra(USER_ID);
     String authCode = data.getStringExtra(AUTH_CODE);
     if (SdkUtils.isBlank(authCode) && !SdkUtils.isBlank(userId)) {
       Map<String, BoxAuthenticationInfo> authenticatedMap =
           BoxAuthentication.getInstance().getStoredAuthInfo(this);
       BoxAuthenticationInfo info = authenticatedMap.get(userId);
       if (info != null) {
         onAuthenticationChosen(info);
       } else {
         onAuthFailure(new AuthFailure(AuthFailure.TYPE_USER_INTERACTION, ""));
       }
     } else if (!SdkUtils.isBlank(authCode)) {
       startMakingOAuthAPICall(authCode, null);
     }
   } else if (resultCode == RESULT_CANCELED) {
     finish();
   }
 }