开始入门
复制一个包含安装步骤和本插件的完整 Markdown 指南的配置提示。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-recaptcha`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/recaptcha/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
Section titled “Install”npm install @capgo/capacitor-recaptchanpx cap syncConfigure Site Keys
Section titled “Configure Site Keys”Create platform keys in Google Cloud reCAPTCHA, then add them to capacitor.config.ts.
import type { CapacitorConfig } from '@capacitor/cli';import '@capgo/capacitor-recaptcha';
const config: CapacitorConfig = { appId: 'com.example.app', appName: 'Example', webDir: 'dist', plugins: { Recaptcha: { androidSiteKey: 'ANDROID_SITE_KEY', iosSiteKey: 'IOS_SITE_KEY', webSiteKey: 'WEB_SITE_KEY', enterprise: true, }, },};
export default config;androidSiteKey, iosSiteKey,和 webSiteKey 覆盖共享 siteKey。您还可以将 siteKey 直接传递给 load() 或 execute() 当密钥取决于您的环境时
生成令牌
标题为“生成令牌”import { Recaptcha } from '@capgo/capacitor-recaptcha';
const { token } = await Recaptcha.execute({ action: 'login',});
await fetch('/api/recaptcha-assessment', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ token, action: 'login' }),});execute() 调用 load() 自动调用客户端未准备好时,因此显式预加载步骤是可选的。
Web Standard reCAPTCHA v3
Web Standard reCAPTCHA v3设置 enterprise: false 加载 Google 的标准 Web reCAPTCHA v3 脚本。
const { token } = await Recaptcha.execute({ siteKey: 'WEB_V3_SITE_KEY', enterprise: false, action: 'signup',});在 Android 和 iOS 上,Google 的本机移动 SDK 路径仅限企业版。将此选项传递给本机平台会被拒绝,因此不会意外使用标准 Web v3 密钥。 enterprise: false 迁移说明
并 sitekeyAndroid 在调用选项和 __CAPGO_KEEP_0__ 配置中接受 sitekeyWeb 在调用选项和Capacitor配置中接受 sitekeyIos 作为 iOS 迁移别名。 优先使用 __CAPGO_KEEP_0__ 配置名称为新 __CAPGO_KEEP_1__。 sitekeyIOS as iOS migration aliases. Prefer the Capacitor config names for new code.
标题:继续从 Getting Started
如果您正在使用Getting Started 来规划身份验证和帐户流程,连接它与 使用 @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-recaptcha 为native能力在使用 @capgo/capacitor-recaptcha 中 @capgo/capacitor-social-login 为实现细节在 @capgo/capacitor-social-login 中 @capgo/capacitor-passkey @capgo/capacitor-passkey 对于 @capgo/capacitor-passkey 的实现细节 @capgo/capacitor-native-biometric 对于 @capgo/capacitor-native-biometric 的实现细节, 双因素认证 对于双因素认证的实现细节。