Ejemplo n.º 1
0
 @Override
 protected void onResume() {
   super.onResume();
   if (oauthView == null || !oauthView.getUrl().startsWith("http")) {
     startOAuth();
   }
 }
Ejemplo n.º 2
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:
   }
 }
Ejemplo n.º 3
0
  private void clearCachedAuthenticationData() {
    if (oauthView != null) {
      oauthView.clearCache(true);
      oauthView.clearFormData();
      oauthView.clearHistory();
    }
    // wipe out cookies.
    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();

    deleteDatabase("webview.db");
    deleteDatabase("webviewCache.db");
    File cacheDirectory = getCacheDir();
    SdkUtils.deleteFolderRecursive(cacheDirectory);
    cacheDirectory.mkdir();
  }
Ejemplo n.º 4
0
 @Override
 public void onReceive(Context context, Intent intent) {
   if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)
       && SdkUtils.isInternetAvailable(context)) {
     // if we are not showing a web page then redo the authentication.
     if ((oauthView != null)
         && (oauthView.getUrl() != null)
         && !oauthView.getUrl().startsWith("http")) {
       startOAuth();
     }
   }
 }
Ejemplo n.º 5
0
 protected OAuthWebView createOAuthView() {
   OAuthWebView webview = (OAuthWebView) findViewById(getOAuthWebViewRId());
   webview.setVisibility(View.VISIBLE);
   webview.getSettings().setJavaScriptEnabled(true);
   return webview;
 }
Ejemplo n.º 6
0
 /**
  * Callback method to be called when authentication code is received along with a base domain. The
  * code will then be used to make an API call to create OAuth tokens.
  */
 public void onReceivedAuthCode(String code, String baseDomain) {
   if (authType == AUTH_TYPE_WEBVIEW) {
     oauthView.setVisibility(View.INVISIBLE);
   }
   startMakingOAuthAPICall(code, baseDomain);
 }