跳过内容

开始使用

  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: primary HTTPS relying-party origin used by the shim and direct API
  • domains: 需要在本地配置中同步的额外依赖方主机名
  • autoShim: defaults to 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

平台指南

平台指南