googlesamples / android-play-safetynet

Samples for the Google SafetyNet Attestation API
Apache License 2.0
285 stars 133 forks source link

addOnFailureListener not trigger when user dismiss the verify dialog #12

Open vsay01 opened 6 years ago

vsay01 commented 6 years ago

library version used: com.google.android.gms:play-services-safetynet:11.4.2

I am using safety net captcha API. everything working as expected meaning, both are detected:

However, Here steps produce issue where on success and on failure are not detected:

Expected: addOnFailureListener should be triggered because user didn't response to the verification steps when detected as robot

Actual: both OnSuccessListener and addOnFailureListener are not detected

Code:

SafetyNet.getClient(this).verifyWithRecaptcha(YOUR_API_SITE_KEY)
            .addOnSuccessListener((Executor) this,
            new OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse>() {
                @Override
                public void onSuccess(SafetyNetApi.RecaptchaTokenResponse response) {
                    // Indicates communication with reCAPTCHA service was
                    // successful.
                    String userResponseToken = response.getTokenResult();
                    if (!userResponseToken.isEmpty()) {
                        // Validate the user response token using the
                        // reCAPTCHA siteverify API.
                    }
                }
        })
        .addOnFailureListener((Executor) this, new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    if (e instanceof ApiException) {
                        // An error occurred when communicating with the
                        // reCAPTCHA service. Refer to the status code to
                        // handle the error appropriately.
                        ApiException apiException = (ApiException) e;
                        int statusCode = apiException.getStatusCode();
                        Log.d(TAG, "Error: " + CommonStatusCodes
                                .getStatusCodeString(statusCode));
                    } else {
                        // A different, unknown type of error occurred.
                        Log.d(TAG, "Error: " + e.getMessage());
                    }
                }
        });

Questions:

Thanks

iiw commented 5 years ago

Hello. Did you found solution for that?

vsay01 commented 5 years ago

@iiw what we end up doing is dismiss all dialogs in onResume. I still think it would be nice to have the listener for this though. Hope it help.

iiw commented 5 years ago

I did same. Thanks.

gildor commented 3 years ago

I'm pretty sure it's a bug, Recaptcha should support or pass cancellation to addOnFailureListener, which I believe correct approach (because it's also the result of the operation), or at least trigger addOnCanceledListener, which also a solution, but I think it not so straightforward, an internal result of the task shouldn't cancel it

vedraj360 commented 2 years ago

@vsay01 can you explain it more clearly when you are dismissing the dialog and how you know dialog is dismissed.

mayuce commented 2 years ago

It has been years over it but still it's an open issue, that is nasty...

chowdarym05 commented 1 year ago

addOnCanceledListener is still not triggered. Not sure when this issue will be addressed.

TareqAmenahDev commented 1 year ago

5 years and still have this issue..