跳过内容

开始入门

Terminal window
npm install @capgo/capacitor-recaptcha
npx cap sync

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 的实现细节, 双因素认证 对于双因素认证的实现细节。