搜索插件、代码仓与 APP 分类

插件详情v18.9.3

recaptcha_enterprise_flutter

一个用于 reCAPTCHA Enterprise 的 Flutter 插件。

AndroidiOS
近 30 天下载
15.6万
喜欢数
55
Pub 分数
150

安装插件

flutter pub add recaptcha_enterprise_flutter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个将 Google reCAPTCHA Enterprise 集成到 Android 和 iOS 移动应用中的 Flutter 插件。它通过先进的风险分析验证用户交互,帮助开发者保护其应用免受机器人和自动化威胁。该插件简化了企业级 CAPTCHA 挑战的实现,支持无缝的身份验证流程,同时不损害用户体验。它利用 Google Cloud 的基础设施,在配置最少的情况下提供强大的安全防护。适用于需要在敏感环境中进行高安全性验证的应用。

适合场景

  • 保护登录表单免受机器人攻击
  • 防止自动化请求攻击API端点
  • 防止欺诈性注册
  • 增强金融或医疗应用的安全性
  • 在关键操作期间验证人类用户

主要特点

  • 与 Google reCAPTCHA Enterprise 集成
  • 支持 Android 和 iOS 平台
  • 使用 Flutter 友好的 API 进行最小化设置
  • 提供风险分析和挑战处理
  • 通过令牌验证启用服务器端验证

适合对象

  • 需要强大反机器人保护的移动应用
  • 企业级安全要求
  • 处理敏感用户数据的应用程序
  • 使用 Google Cloud 服务的开发人员
  • 需要符合安全标准的项目

使用建议

  • 需要一个启用了 reCAPTCHA Enterprise 的 Google Cloud 项目
  • 需要服务器端令牌验证以确保完全安全
  • 如果使用过度,可能会影响用户体验
  • 依赖网络连接以传递挑战
  • 与网页实现相比,自定义选项有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

reCAPTCHA Enterprise Flutter Module

Please note that issues filed in this repository are not an official Google support channel and are answered on a best effort basis. For official support, please visit: https://cloud.google.com/support-hub.

If you have an issue with the Flutter plugin please post issues in this repository. If you are having issues with the underlying SDK, please post issues in https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk.

For general documentation on reCAPTCHA Enterprise for mobile applications, see Android and iOS.

Integrating reCAPTCHA Enterprise with your Flutter Application

This guide outlines the steps to integrate reCAPTCHA Enterprise into your Flutter application for enhanced security.

1. Environment Setup
  1. Add the reCAPTCHA Enterprise Flutter library:

    Execute the following command in your Flutter project's root directory:

    flutter pub add recaptcha_enterprise_flutter
    

    Note: This library supports only iOS and Android platforms.

2. Client Initialization
  1. Obtain Site Keys:

    Acquire your reCAPTCHA Enterprise site keys for both Android and iOS platforms from the Google Cloud Console.

  2. Instantiate the RecaptchaClient:

    Initialize the client using the appropriate site key based on the platform. It's crucial to initialize the client as early as possible within your application's lifecycle to minimize latency.

    import 'package:flutter/material.dart';
    import 'package:recaptcha_enterprise_flutter/recaptcha_enterprise_flutter.dart';
    import 'dart:io' show Platform;
    
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
    
      final siteKey = Platform.isAndroid
          ? "<ANDROID_SITE_KEY>"
          : "<IOS_SITE_KEY>";
    
      RecaptchaClient client = await Recaptcha.fetchClient(siteKey);
    
      runApp(MyApp(client: client));
    }
    
    class MyApp extends StatelessWidget {
      final RecaptchaClient client;
    
      const MyApp({super.key, required this.client});
    
      // ... other code ...
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          home: MyHomePage(title: 'reCAPTCHA Demo', client: client),
        );
      }
    }
    

    Important:

    • Replace <ANDROID_SITE_KEY> and <IOS_SITE_KEY> with your actual reCAPTCHA Enterprise site keys.
    • The example above demonstrates platform-specific site key selection. You can adopt alternative strategies, such as using asset files, to manage your site keys.
    • Initialization of the SDK can take several seconds to complete. To mitigate this latency, initialize the client as early as possible,
3. Executing reCAPTCHA Actions
  1. Invoke the execute method:

    For each action within your application that requires reCAPTCHA protection (e.g., login, registration), call the execute method of the RecaptchaClient, passing a RecaptchaAction instance.

    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title, required this.client});
    
      final String title;
      final RecaptchaClient client;
    
      Future<bool> _login() async {
        try {
          String token = await client.execute(RecaptchaAction.LOGIN());
          // Send the token to your server for assessment.
          return await handleToken(token); // handleToken is a function that sends the token to your backend.
        } catch (err) {
          // Handle reCAPTCHA execution errors.
          print('reCAPTCHA execution error: $err');
          return false;
        }
      }
    
      // ... other code ...
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                // ... other UI elements ...
                ElevatedButton(
                  onPressed: () async {
                    bool loginSuccess = await widget._login();
                    if(loginSuccess){
                      // handle successful login
                    } else {
                      // handle failed login
                    }
                  },
                  child: const Text('Login'),
                ),
              ],
            ),
          ),
        );
      }
    
    }
    Future<bool> handleToken(String token) async{
      // sends token to your backend.
      // this is a placeholder function, and needs to be implemented.
      return true;
    }
    
    • Replace handleToken(token) with your server-side logic for assessing the reCAPTCHA token.
4. Error Handling
  1. Implement Robust Error Handling:

    Your application must gracefully handle potential errors during reCAPTCHA service communication. Implement appropriate error handling mechanisms to manage scenarios where the API encounters issues.

  2. Refer to Official Documentation:

    Consult the official Google Cloud reCAPTCHA Enterprise documentation for detailed information on error codes and best practices:

Sample App

Copy example/assets/configs/dev.json.example to example/assets/configs/dev.json and add your sitekeys to the file.

Change ios bundle id in example/ios/Runner.xcodeproj/project.pbxproj from google.FlutterTestApp in three places to your own bundle id.

Change the Android bundle id in example/android/app/build.gradle from google.FlutterTestApp to your own.

Start an emulator, e.g. open -a Simulator or ~/Library/Android/sdk/emulator/emulator -avd Pixel_4_API_32

Run app:
cd example && flutter run
Run unit tests:
flutter test
Running Integration Tests
cd example && flutter test integration_test/app_test.dart

所属分类

依赖

依赖清单 1 项

  • plugin_platform_interface^2.0.2

源码仓库

使用此插件的项目