Coder Social home page Coder Social logo

f_grecaptcha's Introduction

f_grecaptcha

This simple flutter plugin allows using the SafetyNet API on Android devices to verify that the user is human.

Using the plugin

Preparations

First, include the plugin in your project's dependencies by including it in the relevant section of your pubspec.yaml:

dependencies:
  f_grecaptcha: ^1.0.0

Next, you wil need to register your app in the reCAPTCHA admin console. Go to https://www.google.com/recaptcha/admin#list and register by filling out the form. Be sure to select "reCAPTCHA-Android" as the type. A form field asking for your Android package name will appear. You can copy it from the manifest file located under android/app/src/main/AndroidManifest.xml in your project directory. It is the value of the package attribute of the root XML-tag. You can also visit the instructions page from the android documentation for a more detailed guide, only the section "Adding a SafetyNet API dependency" is relevant, the plugin will do the rest.

Verifying users

After having your app registered with the reCAPTCHA API, you can invoke the following method anywhere in your dart code, most commonly after a button has been pressed. Replace SITE_KEY with the site key the admin interface shows after registering your app.

 FGrecaptcha.verifyWithRecaptcha(SITE_KEY).then((result) {
    // You can send the result token, along with some form fields, to your
    // server, which can verify the token using an endpoint proved by the
    // reCAPTCHA API for servers, see https://developers.google.com/recaptcha/docs/verify
    }, onError: (e, s) {
    // An error doesn't have to mean that the user is not a human. Errors
    // can also occur when the sitekey is invalid or does not match your
    // application, when the device is not supported or when a network
    // error occurs.
    // You should inform the user of errors, explaining why they can't
    // proceed. As the plugin is not available for iOS, you might consider
    // skipping the reCAPTCHA step when FGrecaptcha.isAvailable is false.
    print("Could not verify:\n $e at $s");
    }
);

Server-side verification

Simply checking that FGrecaptcha.verifyWithRecaptcha returned a value is not enough to be sure that the user is a human. Instead, you would have to verify the token returned in your applications backend server. You can accomplish that by following the instructions at https://developers.google.com/recaptcha/docs/verify.

f_grecaptcha's People

Contributors

daadu avatar simolus3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

f_grecaptcha's Issues

PlatformException(f_grecaptcha, Verification using reCaptcha has failed, null)

There is no problem with the internet, but still getting same issue

W/System.err(16290): com.google.android.gms.common.api.ApiException: 12013: Invalid Package Name for App
W/System.err(16290): at com.google.android.gms.common.internal.zzb.zzy(Unknown Source:14)
W/System.err(16290): at com.google.android.gms.common.internal.zzbk.zzz(Unknown Source:0)
W/System.err(16290): at com.google.android.gms.common.internal.zzbl.zzr(Unknown Source:32)
W/System.err(16290): at com.google.android.gms.common.api.internal.BasePendingResult.zzc(Unknown Source:81)
W/System.err(16290): at com.google.android.gms.common.api.internal.BasePendingResult.setResult(Unknown Source:41)
W/System.err(16290): at com.google.android.gms.internal.zzcwk.zza(Unknown Source:7)
W/System.err(16290): at com.google.android.gms.internal.zzcvw.onTransact(Unknown Source:101)
W/System.err(16290): at android.os.Binder.execTransact(Binder.java:697)
I/flutter (16290): Could not verify:
�[38;5;244mI/flutter (16290): PlatformException(f_grecaptcha, Verification using reCaptcha has failed, null) at #0 StandardMethodCodec.decodeEnvelope�[39;49m
�[38;5;244mI/flutter (16290): #1 MethodChannel._invokeMethod�[39;49m
I/flutter (16290):
�[38;5;244mI/flutter (16290): #2 MethodChannel.invokeMethod�[39;49m
�[38;5;248mI/flutter (16290): #3 FGrecaptcha.verifyWithRecaptcha�[39;49m
I/flutter (16290):
�[38;5;248mI/flutter (16290): #4 _MyAppState._startVerification�[39;49m
�[38;5;244mI/flutter (16290): #5 _InkResponseState._handleTap�[39;49m
�[38;5;244mI/flutter (16290): #6 _InkResponseState.build.�[39;49m
�[38;5;244mI/flutter (16290): #7 GestureRecognizer.invokeCallback�[39;49m
�[38;5;244mI/flutter (16290): #8 TapGestureRecognizer.handleTapUp�[39;49m
I/flutter (16290): #9 BaseTapGestureRecognizer

flutter: Could not verify:

flutter: Could not verify:
Instance of 'ReCaptchaNotAvailableException' at #0 FGrecaptcha.verifyWithRecaptcha (package:f_grecaptcha/f_grecaptcha.dart:32:13)

#1 new LoginUIState. (package:betdip/src/ui/login_ui.dart:131:47)
#2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:511:14)
#3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:566:30)
#4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:166:24)
#5 TapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:240:9)
#6 TapGestureRecognizer.handlePrimaryPointer (package:flutter/src/gestures/tap.dart:177:9)
#7 PrimaryPointerGestureRecognizer.handleEvent (package:flutter/src/gestures/recognizer.dart:436:9)
#8 PointerRouter._dispatch (package:flutter/src/gestures/pointer_router.dart:73:12)
#9 PointerRouter.route (package:flutter/src/gestures/pointer_router.dart:101:11)
#10 _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:221:19)
#11 _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:199:22)
#12 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:156:7)
#13 _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:102:7)
#14 _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:86:7)
#15 _rootRunUnary (dart:async/zone.dart:1136:13)
#16 _CustomZone.runUnary (dart:async/zone.dart:1029:19)
#17 _CustomZone.runUnaryGuarded (dart:async/zone.dart:931:7)
#18 _invoke1 (dart:ui/hooks.dart:233:10)
#19 _dispatchPointerDataPacket (dart:ui/hooks.dart:154:5)

iOS version

I would like to port this library to iOS (using web tokens) using this library: https://github.com/fjcaetano/ReCaptcha

This library accomplish this with WebViews so the user will need to apply for two keys, one for Android and one for iOS (actually, web).

If I would to submit a PR, will you merge it or is it not a goal for this project?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.