use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class WebLoginMethodHandler method onComplete.
protected void onComplete(LoginClient.Request request, Bundle values, FacebookException error) {
LoginClient.Result outcome;
e2e = null;
if (values != null) {
// Actual e2e we got from the dialog should be used for logging.
if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
}
try {
AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), values, getTokenSource(), request.getApplicationId());
outcome = LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
// Ensure any cookies set by the dialog are saved
// This is to work around a bug where CookieManager may fail to instantiate if
// CookieSyncManager has never been created.
CookieSyncManager syncManager = CookieSyncManager.createInstance(loginClient.getActivity());
syncManager.sync();
saveCookieToken(token.getToken());
} catch (FacebookException ex) {
outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, ex.getMessage());
}
} else {
if (error instanceof FacebookOperationCanceledException) {
outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(), "User canceled log in.");
} else {
// Something went wrong, don't log a completion event since it will skew timing
// results.
e2e = null;
String errorCode = null;
String errorMessage = error.getMessage();
if (error instanceof FacebookServiceException) {
FacebookRequestError requestError = ((FacebookServiceException) error).getRequestError();
errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
errorMessage = requestError.toString();
}
outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, errorMessage, errorCode);
}
}
if (!Utility.isNullOrEmpty(e2e)) {
logWebLoginCompleted(e2e);
}
loginClient.completeAndValidate(outcome);
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class WebLoginMethodHandler method getParameters.
protected Bundle getParameters(final LoginClient.Request request) {
Bundle parameters = new Bundle();
if (!Utility.isNullOrEmpty(request.getPermissions())) {
String scope = TextUtils.join(",", request.getPermissions());
parameters.putString(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
addLoggingExtra(ServerProtocol.DIALOG_PARAM_SCOPE, scope);
}
DefaultAudience audience = request.getDefaultAudience();
parameters.putString(ServerProtocol.DIALOG_PARAM_DEFAULT_AUDIENCE, audience.getNativeProtocolAudience());
parameters.putString(ServerProtocol.DIALOG_PARAM_STATE, getClientState(request.getAuthId()));
AccessToken previousToken = AccessToken.getCurrentAccessToken();
String previousTokenString = previousToken != null ? previousToken.getToken() : null;
if (previousTokenString != null && (previousTokenString.equals(loadCookieToken()))) {
parameters.putString(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, previousTokenString);
// Don't log the actual access token, just its presence or absence.
addLoggingExtra(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, AppEventsConstants.EVENT_PARAM_VALUE_YES);
} else {
// The call to clear cookies will create the first instance of CookieSyncManager if
// necessary
Utility.clearFacebookCookies(loginClient.getActivity());
addLoggingExtra(ServerProtocol.DIALOG_PARAM_ACCESS_TOKEN, AppEventsConstants.EVENT_PARAM_VALUE_NO);
}
return parameters;
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginManager method onActivityResult.
boolean onActivityResult(int resultCode, Intent data, FacebookCallback<LoginResult> callback) {
FacebookException exception = null;
AccessToken newToken = null;
LoginClient.Result.Code code = LoginClient.Result.Code.ERROR;
Map<String, String> loggingExtras = null;
LoginClient.Request originalRequest = null;
boolean isCanceled = false;
if (data != null) {
LoginClient.Result result = data.getParcelableExtra(LoginFragment.RESULT_KEY);
if (result != null) {
originalRequest = result.request;
code = result.code;
if (resultCode == Activity.RESULT_OK) {
if (result.code == LoginClient.Result.Code.SUCCESS) {
newToken = result.token;
} else {
exception = new FacebookAuthorizationException(result.errorMessage);
}
} else if (resultCode == Activity.RESULT_CANCELED) {
isCanceled = true;
}
loggingExtras = result.loggingExtras;
}
} else if (resultCode == Activity.RESULT_CANCELED) {
isCanceled = true;
code = LoginClient.Result.Code.CANCEL;
}
if (exception == null && newToken == null && !isCanceled) {
exception = new FacebookException("Unexpected call to LoginManager.onActivityResult");
}
boolean wasLoginActivityTried = true;
//Sadly, there is no way to get activity context at this point.S
Context context = null;
logCompleteLogin(context, code, loggingExtras, exception, wasLoginActivityTried, originalRequest);
finishLogin(newToken, originalRequest, exception, isCanceled, callback);
return true;
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginManager method createLoginRequestFromResponse.
private LoginClient.Request createLoginRequestFromResponse(final GraphResponse response) {
Validate.notNull(response, "response");
AccessToken failedToken = response.getRequest().getAccessToken();
return createLoginRequest(failedToken != null ? failedToken.getPermissions() : null);
}
use of com.facebook.AccessToken in project facebook-android-sdk by facebook.
the class LoginMethodHandler method createAccessTokenFromNativeLogin.
static AccessToken createAccessTokenFromNativeLogin(Bundle bundle, AccessTokenSource source, String applicationId) {
Date expires = Utility.getBundleLongAsDate(bundle, NativeProtocol.EXTRA_EXPIRES_SECONDS_SINCE_EPOCH, new Date(0));
ArrayList<String> permissions = bundle.getStringArrayList(NativeProtocol.EXTRA_PERMISSIONS);
String token = bundle.getString(NativeProtocol.EXTRA_ACCESS_TOKEN);
if (Utility.isNullOrEmpty(token)) {
return null;
}
String userId = bundle.getString(NativeProtocol.EXTRA_USER_ID);
return new AccessToken(token, applicationId, userId, permissions, null, source, expires, new Date());
}
Aggregations