Firebaseui-android: IdpResponse.fromResultIntent(data) return null

Created on 21 Dec 2016  路  4Comments  路  Source: firebase/FirebaseUI-Android

Step 3: Describe the problem:

IdpResponse.fromResultIntent(data) return null in onActivityResult

I launch Firebase UI with

            AuthUI.SignInIntentBuilder signInBuilder = AuthUI.getInstance().createSignInIntentBuilder();
            List<AuthUI.IdpConfig> idpConfigs = new ArrayList<>();
            AuthUI.IdpConfig googleProvider = new AuthUI.IdpConfig.Builder(AuthUI.GOOGLE_PROVIDER).build();
            idpConfigs.add(googleProvider);

            signInBuilder.setProviders(idpConfigs);
            signInBuilder.setIsSmartLockEnabled(false);
            startActivityForResult(signInBuilder.build(), REQUEST_CODE_FIREBASE_UI_AUTH);

then in

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_FIREBASE_UI_AUTH) {
        if (resultCode == RESULT_OK) {
            IdpResponse idpResponse = IdpResponse.fromResultIntent(data);

idpResponse is null.

Debugger get me to SaveSmartLock#idpResponse where smartLockEnabled is false. Then finish is called without IdpResponse parameter being set to the SaveSmartLock object. The IdpResponse parameter holds the correct values at this point according to debugger, but is not returned.

Traversing with debugger in SaveSmartLock gives me:

 private void finish() {
     **I end up here, with mResponse being null**
    Intent resultIntent = new Intent().putExtra(ExtraConstants.EXTRA_IDP_RESPONSE, mResponse);
    finish(RESULT_OK, resultIntent);
}

/**
 * If SmartLock is enabled and Google Play Services is available, save the credentials.
 * Otherwise, finish the calling Activity with RESULT_OK.
 *
 * Note: saveCredentialsOrFinish cannot be called immediately after getInstance because
 * onCreate has not yet been called.
 *
 * @param firebaseUser Firebase user to save in Credential.
 * @param password     (optional) password for email credential.
 * @param response     (optional) an {@link IdpResponse} representing the result of signing in.
 */
public void saveCredentialsOrFinish(FirebaseUser firebaseUser,
                                    @Nullable String password,
                                    @Nullable IdpResponse response) {
    if (!mHelper.getFlowParams().smartLockEnabled
            || !PlayServicesHelper.getInstance(getContext()).isPlayServicesAvailable()
            || getActivity().isFinishing()) {
        finish(); **I end up here, with response holding my stuff**
        return;
    }

    mName = firebaseUser.getDisplayName();
    mEmail = firebaseUser.getEmail();
    mPassword = password;
    mResponse = response;
    mProfilePictureUri = firebaseUser.getPhotoUrl() != null ? firebaseUser.getPhotoUrl()
            .toString() : null;

    mGoogleApiClient = new Builder(getContext().getApplicationContext())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Auth.CREDENTIALS_API)
            .enableAutoManage(getActivity(), GoogleApiConstants.AUTO_MANAGE_ID2, this)
            .build();
    mGoogleApiClient.connect();
}

Observed Results:

Let me know if logcat or other is needed

Expected Results:

I expect to IdpResponse.fromResultIntent(data) to return an IdpResponse that is not null

auth fix-implemented bug

All 4 comments

@joknu1 This is expected behavior (IdpResponse#fromResultIntent(Intent) is annotated with @Nullable) though I agree with you that losing the intent because smart lock was disabled is a mistake.

I've created #469 to fix this issue which should be available in FirebaseUI v1.1.0. Cheers!

Hi @SUPERCILEX,
Thanks for the quick reply.

In what way is it expected behavior in this case, if I may ask? Is there a workaround for FirebaseUI version:1.0.1? I tried version:1.0.0 and downgrading google play services to 9.8.0, but then onActivityResult was not called at all.

@joknu1 I believe @SUPERCILEX means this is expected behavior in that your code should not rely on getting a non-null IdpResponse. But it's not desired behavior and we will fix it in the next version.

A fix for this issue has been released in version 1.1.0

Was this page helpful?
0 / 5 - 0 ratings