Skip to content

Fix NoClassDefFoundErrors logspam for missing providers #1201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 56 additions & 54 deletions auth/src/main/java/com/firebase/ui/auth/provider/FacebookProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import java.util.ArrayList;
import java.util.List;

public class FacebookProvider implements IdpProvider, FacebookCallback<LoginResult> {
public class FacebookProvider implements IdpProvider {
private static final String TAG = "FacebookProvider";
private static final String EMAIL = "email";
private static final String PUBLIC_PROFILE = "public_profile";
Expand All @@ -60,7 +60,7 @@ public class FacebookProvider implements IdpProvider, FacebookCallback<LoginResu
// DO NOT USE DIRECTLY: see onSuccess(String, LoginResult) and onFailure(Bundle) below
private IdpCallback mCallbackObject;

public FacebookProvider(AuthUI.IdpConfig idpConfig, @StyleRes int theme) {
public FacebookProvider(AuthUI.IdpConfig idpConfig, @StyleRes int theme) {
List<String> scopes = idpConfig.getParams()
.getStringArrayList(ExtraConstants.EXTRA_FACEBOOK_PERMISSIONS);
if (scopes == null) {
Expand Down Expand Up @@ -93,7 +93,7 @@ public int getButtonLayout() {
public void startLogin(Activity activity) {
sCallbackManager = CallbackManager.Factory.create();
LoginManager loginManager = LoginManager.getInstance();
loginManager.registerCallback(sCallbackManager, this);
loginManager.registerCallback(sCallbackManager, callback);

List<String> permissionsList = new ArrayList<>(mScopes);

Expand Down Expand Up @@ -122,62 +122,64 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

@Override
public void onSuccess(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
FacebookRequestError requestError = response.getError();
if (requestError != null) {
Log.e(TAG, "Received Facebook error: " + requestError.getErrorMessage());
onFailure(requestError.getException());
return;
}
if (object == null) {
Log.w(TAG, "Received null response from Facebook GraphRequest");
onFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR));
} else {
String email = null;
String name = null;
Uri photoUri = null;

try {
email = object.getString("email");
} catch (JSONException e) {
Log.e(TAG, "Failure retrieving Facebook email", e);
private final FacebookCallback<LoginResult> callback = new FacebookCallback<LoginResult>(){
@Override
public void onSuccess(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
FacebookRequestError requestError = response.getError();
if (requestError != null) {
Log.e(TAG, "Received Facebook error: " + requestError.getErrorMessage());
onFailure(requestError.getException());
return;
}
if (object == null) {
Log.w(TAG, "Received null response from Facebook GraphRequest");
onFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR));
} else {
String email = null;
String name = null;
Uri photoUri = null;

try {
email = object.getString("email");
} catch (JSONException e) {
Log.e(TAG, "Failure retrieving Facebook email", e);
}
try {
name = object.getString("name");
} catch (JSONException ignored) {}
try {
photoUri = Uri.parse(object.getJSONObject("picture")
.getJSONObject("data")
.getString("url"));
} catch (JSONException ignored) {}

FacebookProvider.this.onSuccess(loginResult, email, name, photoUri);
}
try {
name = object.getString("name");
} catch (JSONException ignored) {}
try {
photoUri = Uri.parse(object.getJSONObject("picture")
.getJSONObject("data")
.getString("url"));
} catch (JSONException ignored) {}

onSuccess(loginResult, email, name, photoUri);
}
}
});
});

Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,picture");
request.setParameters(parameters);
request.executeAsync();
}
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,picture");
request.setParameters(parameters);
request.executeAsync();
}

@Override
public void onCancel() {
onFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR));
}
@Override
public void onCancel() {
onFailure(new FirebaseUiException(ErrorCodes.UNKNOWN_ERROR));
}

@Override
public void onError(FacebookException e) {
Log.e(TAG, "Error logging in with Facebook. " + e.getMessage());
onFailure(e);
}
@Override
public void onError(FacebookException e) {
Log.e(TAG, "Error logging in with Facebook. " + e.getMessage());
onFailure(e);
}
};

private void onSuccess(LoginResult loginResult,
@Nullable String email,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.twitter.sdk.android.core.identity.TwitterAuthClient;
import com.twitter.sdk.android.core.models.User;

public class TwitterProvider extends Callback<TwitterSession> implements IdpProvider {
public class TwitterProvider implements IdpProvider {
private static final String TAG = "TwitterProvider";

private IdpCallback mCallbackObject;
Expand Down Expand Up @@ -87,38 +87,42 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {

@Override
public void startLogin(Activity activity) {
mTwitterAuthClient.authorize(activity, this);
mTwitterAuthClient.authorize(activity, callback);
}

@Override
public void success(final Result<TwitterSession> sessionResult) {
TwitterCore.getInstance()
.getApiClient()
.getAccountService()
.verifyCredentials(false, false, true)
.enqueue(new Callback<User>() {
@Override
public void success(Result<User> result) {
User user = result.data;
mCallbackObject.onSuccess(createIdpResponse(
sessionResult.data,
user.email,
user.name,
Uri.parse(user.profileImageUrlHttps)));
}

@Override
public void failure(TwitterException e) {
mCallbackObject.onFailure(e);
}
});
}
private final Callback<TwitterSession> callback = new Callback<TwitterSession>(){
@Override
public void success(final Result<TwitterSession> sessionResult) {
TwitterCore.getInstance()
.getApiClient()
.getAccountService()
.verifyCredentials(false, false, true)
.enqueue(new Callback<User>() {
@Override
public void success(Result<User> result) {
User user = result.data;
mCallbackObject.onSuccess(createIdpResponse(
sessionResult.data,
user.email,
user.name,
Uri.parse(user.profileImageUrlHttps)));
}

@Override
public void failure(TwitterException e) {
mCallbackObject.onFailure(e);
}
});
}

@Override
public void failure(TwitterException e) {
Log.e(TAG, "Failure logging in to Twitter. " + e.getMessage());
mCallbackObject.onFailure(e);
}
};


@Override
public void failure(TwitterException e) {
Log.e(TAG, "Failure logging in to Twitter. " + e.getMessage());
mCallbackObject.onFailure(e);
}

private IdpResponse createIdpResponse(TwitterSession session,
String email,
Expand Down