Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ build/
**/example/ios/.symlinks/
**/example/ios/Pods/

**/example/android/app/.cxx

**/ios/Flutter/ephemeral
43 changes: 25 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# reCAPTCHA Enterprise Flutter Module

Please note that issues filed in this repository are not an official Google
Expand All @@ -11,9 +10,9 @@ in
[https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk](https://github.com/GoogleCloudPlatform/recaptcha-enterprise-mobile-sdk).

For general documentation on reCAPTCHA Enterprise for mobile applications, see
[Android](https://cloud.google.com/recaptcha-enterprise/docs/instrument-android-apps)
and
[iOS](https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps).
[Android](https://cloud.google.com/recaptcha-enterprise/docs/instrument-android-apps),
[iOS](https://cloud.google.com/recaptcha-enterprise/docs/instrument-ios-apps),
and [Web](https://cloud.google.com/recaptcha-enterprise/docs/instrument-web-apps).

## Integrating reCAPTCHA Enterprise with your Flutter Application

Expand All @@ -30,16 +29,25 @@ Flutter application for enhanced security.
flutter pub add recaptcha_enterprise_flutter
```

**Note:** This library supports only iOS and Android platforms.
**Note:** This library supports iOS, Android, and Web platforms.

### 2. Client Initialization

1. **Obtain Site Keys:**

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

2. **Instantiate the `RecaptchaClient`:**
2. **Web Setup:**

For web, you must include the reCAPTCHA Enterprise script in your
`index.html` file. Replace `[MYWEBSITEKEY]` with your actual web site key:

```html
<script src="https://www.google.com/recaptcha/enterprise.js?render=[MYWEBSITEKEY]"></script>
```

3. **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
Expand All @@ -53,9 +61,11 @@ Flutter application for enhanced security.
void main() async {
WidgetsFlutterBinding.ensureInitialized();

final siteKey = Platform.isAndroid
? "<ANDROID_SITE_KEY>"
: "<IOS_SITE_KEY>";
final siteKey = kIsWeb
? "<WEB_SITE_KEY>"
: Platform.isAndroid
? "<ANDROID_SITE_KEY>"
: "<IOS_SITE_KEY>";

RecaptchaClient client = await Recaptcha.fetchClient(siteKey);

Expand All @@ -78,15 +88,12 @@ Flutter application for enhanced security.
```

**Important:**
* Replace `<ANDROID_SITE_KEY>`, `<IOS_SITE_KEY>`, and `<WEB_SITE_KEY>` with your actual reCAPTCHA Enterprise site keys.
* For web, make sure the `<script>` tag in `index.html` is properly configured.
* The example above demonstrates platform-specific site key selection. You can adopt alternative, 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.

* 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:**
Expand Down
45 changes: 45 additions & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.build/
.buildlog/
.history
.svn/
.swiftpm/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
3 changes: 2 additions & 1 deletion example/assets/config/dev.json.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"androidSiteKey": "MYANDROIDSITEKEY",
"iosSiteKey": "MYIOSSITEKEY"
"iosSiteKey": "MYIOSSITEKEY",
"webSiteKey": "MYWEBSITEKEY"
}
12 changes: 10 additions & 2 deletions example/lib/app_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ import 'package:flutter/services.dart';
class AppConfig {
final String androidSiteKey;
final String iosSiteKey;
final String webSiteKey;

const AppConfig({required this.androidSiteKey, required this.iosSiteKey});
const AppConfig({
required this.androidSiteKey,
required this.iosSiteKey,
required this.webSiteKey,
});

static Future<AppConfig> forEnvironment(String? env) async {
env = env ?? 'dev';
Expand All @@ -33,6 +38,9 @@ class AppConfig {

final json = jsonDecode(contents);
return AppConfig(
androidSiteKey: json['androidSiteKey'], iosSiteKey: json['iosSiteKey']);
androidSiteKey: json['androidSiteKey'],
iosSiteKey: json['iosSiteKey'],
webSiteKey: json['webSiteKey'],
);
}
}
Loading