跳过内容

Getting Started

  1. 安装包

    终端窗口
    bun add @capgo/capacitor-app-attest
  2. 同步本机项目

    终端窗口
    bunx cap sync
  3. 配置平台要求

    • 完成 iOS 设置 用于 App Attest 能力和后端验证流程
    • 完成 安卓设置 用于Play Integrity Standard和后端验证流程。

这个插件提供了一个跨平台的API,同时保持了原生平台的安全性:

  • iOS:Apple App Attest (DeviceCheck)
  • 安卓:Google Play Integrity Standard API
  • 不需要自定义客户端端口
  • 标准化的输出用于后端检查
import { AppAttest } from '@capgo/capacitor-app-attest';
const support = await AppAttest.isSupported();
if (!support.isSupported) {
throw new Error(`Attestation not supported on ${support.platform}`);
}
const prepared = await AppAttest.prepare();
const registration = await AppAttest.createAttestation({
keyId: prepared.keyId,
challenge: 'backend-one-time-registration-challenge',
});
const assertion = await AppAttest.createAssertion({
keyId: prepared.keyId,
payload: 'backend-one-time-request-payload',
});
console.log(registration.platform, registration.format, registration.token);
console.log(assertion.platform, assertion.format, assertion.token);

统一响应形状

统一响应形状

createAttestation() 并且 createAssertion() 在 iOS 和 Android 上返回相同的键字段:

字段类型描述
platform'ios' | 'android' | 'web'生成令牌的原生平台
formatAttestationFormatapple-app-attestgoogle-play-integrity-standard
keyIdstring用于证明的密钥/提供者句柄
tokenstring用于在您的后端验证的令牌

后端要求

后端需求

只有在服务器端验证时,才能对证明有效。

  • 不要相信客户端成功的结果。
  • 要求您的后端提供一次性挑战/载荷值。
  • 验证 token在后端逻辑中验证应用程序身份和重放保护。

使用以下平台特定的后端指南:

继续从Getting Started

如果您正在使用

继续从Getting Started 开始使用 连接它以规划安全性和合规性 使用 @capgo/capacitor-app-attest 使用 @capgo/capacitor-app-attest 加密 加密 合规 合规 Capgo 安全扫描器 了解 Capgo 安全扫描器的产品工作流程 Capgo 安全 了解 Capgo 安全的产品工作流程