跳过内容

开始使用

  1. 安装包

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

    终端窗口
    bunx cap sync
  3. 添加插件配置

    import type { CapacitorConfig } from '@capacitor/cli';
    const config: CapacitorConfig = {
    appId: 'app.capgo.passkey.example',
    appName: 'My App',
    webDir: 'dist',
    plugins: {
    CapacitorPasskey: {
    origin: 'https://signin.example.com',
    autoShim: true,
    domains: ['signin.example.com'],
    },
    },
    };
    export default config;
  4. 在引导期间安装 shim

    import { CapacitorPasskey } from '@capgo/capacitor-passkey';
    await CapacitorPasskey.autoShimWebAuthn();
  5. 保持正常的 WebAuthn 流程

    const registration = await navigator.credentials.create({
    publicKey: registrationOptions,
    });
    const authentication = await navigator.credentials.get({
    publicKey: requestOptions,
    });

插件配置的作用

关于插件配置的说明

配置文件来源于 plugins.CapacitorPasskeycapacitor.config.*.

  • origin: shim 和直接 API 使用的主要 HTTPS 依赖方源
  • domains: 用于补充本地配置的额外依赖方主机名
  • autoShim: 默认值 true 并控制本地 cap sync 自动配置钩子

当你运行时 bunx cap sync该插件会更新生成的本机主机项目:

  • iOS:需要时会将域名关联和 Xcode 权限绑定
  • Android: asset_statements 元数据和生成的资源

钩子不会为您发布网站的信任文件。您仍然需要托管:

  • https://your-domain/.well-known/apple-app-site-association
  • https://your-domain/.well-known/assetlinks.json

平台指南

iOS 配置