Search in sources :

Example 1 with AuthFailure

use of com.box.androidsdk.content.auth.OAuthWebView.AuthFailure in project box-android-sdk by box.

the class OAuthActivity method onActivityResult.

@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();
    }
}
Also used : BoxAuthenticationInfo(com.box.androidsdk.content.auth.BoxAuthentication.BoxAuthenticationInfo) AuthFailure(com.box.androidsdk.content.auth.OAuthWebView.AuthFailure)

Example 2 with AuthFailure

use of com.box.androidsdk.content.auth.OAuthWebView.AuthFailure in project box-android-sdk by box.

the class OAuthActivity method getAuthFailure.

/**
     * Takes an auth exception and converts it to an AuthFailure so it can be properly handled
     *
     * @param e The auth exception
     * @return The typed AuthFailure
     */
private OAuthWebView.AuthFailure getAuthFailure(Exception e) {
    String error = getString(R.string.boxsdk_Authentication_fail);
    if (e != null) {
        // Get the proper exception
        Throwable ex = e instanceof ExecutionException ? ((ExecutionException) e).getCause() : e;
        if (ex instanceof BoxException) {
            BoxError boxError = ((BoxException) ex).getAsBoxError();
            if (boxError != null) {
                if (((BoxException) ex).getResponseCode() == HttpURLConnection.HTTP_FORBIDDEN || ((BoxException) ex).getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED || boxError.getError().equals("unauthorized_device")) {
                    error += ":" + getResources().getText(R.string.boxsdk_Authentication_fail_forbidden) + "\n";
                } else {
                    error += ":";
                }
                error += boxError.getErrorDescription();
                return new OAuthWebView.AuthFailure(OAuthWebView.AuthFailure.TYPE_AUTHENTICATION_UNAUTHORIZED, error);
            }
        }
        error += ":" + ex;
    }
    return new OAuthWebView.AuthFailure(OAuthWebView.AuthFailure.TYPE_GENERIC, error);
}
Also used : BoxException(com.box.androidsdk.content.BoxException) AuthFailure(com.box.androidsdk.content.auth.OAuthWebView.AuthFailure) BoxError(com.box.androidsdk.content.models.BoxError) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with AuthFailure

use of com.box.androidsdk.content.auth.OAuthWebView.AuthFailure in project box-android-sdk by box.

the class OAuthActivity method dismissSpinnerAndFailAuthenticate.

protected void dismissSpinnerAndFailAuthenticate(final Exception e) {
    final OAuthWebView.AuthFailure authFailure = getAuthFailure(e);
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            dismissSpinner();
            onAuthFailure(authFailure);
            setResult(Activity.RESULT_CANCELED);
        }
    });
}
Also used : AuthFailure(com.box.androidsdk.content.auth.OAuthWebView.AuthFailure)

Aggregations

AuthFailure (com.box.androidsdk.content.auth.OAuthWebView.AuthFailure)3 BoxException (com.box.androidsdk.content.BoxException)1 BoxAuthenticationInfo (com.box.androidsdk.content.auth.BoxAuthentication.BoxAuthenticationInfo)1 BoxError (com.box.androidsdk.content.models.BoxError)1 ExecutionException (java.util.concurrent.ExecutionException)1