use of com.box.androidsdk.content.auth.BoxAuthentication.BoxAuthenticationInfo in project box-android-sdk by box.
the class OAuthActivity method getBoxAuthApp.
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;
}
use of com.box.androidsdk.content.auth.BoxAuthentication.BoxAuthenticationInfo 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();
}
}
use of com.box.androidsdk.content.auth.BoxAuthentication.BoxAuthenticationInfo in project box-android-sdk by box.
the class OAuthActivity method startOAuth.
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) && getFragmentManager().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 = getFragmentManager().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));
}
mIsLoggingInViaBoxApp = true;
startActivityForResult(intent, REQUEST_BOX_APP_FOR_AUTH_CODE);
break;
}
case AUTH_TYPE_WEBVIEW:
showSpinner();
this.oauthView = createOAuthView();
this.oauthClient = createOAuthWebViewClient();
oauthClient.setOnPageFinishedListener(this);
oauthView.setWebViewClient(oauthClient);
if (mSession.getBoxAccountEmail() != null) {
oauthView.setBoxAccountEmail(mSession.getBoxAccountEmail());
}
oauthView.authenticate(mClientId, mRedirectUrl);
break;
default:
}
}
Aggregations