Skip to content

Instantly share code, notes, and snippets.

@prasannajeet
Last active September 5, 2018 04:52
Show Gist options
  • Save prasannajeet/5864528456f581cdaf71896eba790da1 to your computer and use it in GitHub Desktop.
Save prasannajeet/5864528456f581cdaf71896eba790da1 to your computer and use it in GitHub Desktop.
public class SuccessListener implements OnSuccessListener<SafetyNetApi.RecaptchaTokenResponse> {
@Override
public void onSuccess(final SafetyNetApi.RecaptchaTokenResponse recaptchaTokenResponse) {
String userResponseToken = recaptchaTokenResponse.getTokenResult();
if (!userResponseToken.isEmpty()) {
RecaptchaResponseViewModel mViewModel = ViewModelProviders.of(MainActivity.this).get(RecaptchaResponseViewModel.class);
mViewModel.getmRecaptchaObservable("https://www.google.com", userResponseToken, **SECRET KEY GOES HERE**).observe(MainActivity.this, new Observer<RecaptchaVerifyResponse>() {
@Override
public void onChanged(@Nullable RecaptchaVerifyResponse recaptchaVerifyResponse) {
if (recaptchaVerifyResponse != null && recaptchaVerifyResponse.isSuccess()) {
// User is a human. Congratulations!
} else {
// Response validation failed. Handle scenario
}
}
});
} else {
// Device side validation resulted in no token. Failure
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment