开始
复制安装指南和完整的Markdown指南。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-app-check`
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/firebase-app-check/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
安装您可以使用我们的AI辅助设置来安装插件。将Capgo技能添加到您的AI工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-app-check` plugin in my project.如果您更喜欢手动设置,请通过运行以下命令安装插件,并按照以下平台特定的说明进行操作:
bun add @capgo/capacitor-firebase-app-checknpx cap sync导入
导入部分import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';快速入门
快速入门部分import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
const result = await FirebaseAppCheck.getToken();// The result holds sensitive values: use it without logging it.示例:初始化
示例:初始化import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.initialize();示例:设置令牌自动刷新
示例:设置令牌自动刷新import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.setTokenAutoRefreshEnabled({ enabled: true });常见问题
示例:设置令牌自动刷新- 监听器: 移除屏幕卸载时的句柄。
- : 只初始化一次。: 在应用程序引导期间运行设置。
- 真实来源: 信任
src/definitions.ts在 GitHub 仓库中。
API 概览
标题:API 概览getToken
标题:getToken获取当前 App Check token。
import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
const result = await FirebaseAppCheck.getToken();// The result holds sensitive values: use it without logging it.标题:initialize
import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.initialize();setTokenAutoRefreshEnabled
为给定应用激活 App Check。
仅能在应用激活一次后调用。设置 App Check token 是否自动刷新。
import { FirebaseAppCheck } from '@capgo/capacitor-firebase-app-check';
await FirebaseAppCheck.setTokenAutoRefreshEnabled({ enabled: true });类型参考
类型参考GetTokenOptions
获取 App Check token 选项export interface GetTokenOptions { /** * If `true`, will always try to fetch a fresh token. * If `false`, will use a cached token if found in storage. * * @since 1.3.0 * @default false */ forceRefresh?: boolean;}GetTokenResult
获取 App Check token 结果export interface GetTokenResult { /** * The App Check token in JWT format. * * @since 1.3.0 */ token: string; /** * The timestamp after which the token will expire in milliseconds since epoch. * * Only available for Android and iOS. * * @since 1.3.0 */ expireTimeMillis?: number;}InitializeOptions
初始化选项export interface InitializeOptions { /** * If `true`, the debug provider is used. * * ⚠️ **Attention**: The debug provider allows access to your Firebase resources from unverified devices. * Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties. * * ⚠️ **Deprecated**: Use `debugToken` instead. This option will be removed in the next major version. * * Read more: https://firebase.google.com/docs/app-check/web/debug-provider * * @since 1.3.0 * @deprecated Use `debugToken` instead. This option will be removed in the next major version. * @default false */ debug?: boolean; /** * If `true`, the debug provider is used. * * On **Web**, you can also set a predefined debug token string instead of `true`. On Android and iOS, you have to use environment variables for this. * * ⚠️ **Attention**: The debug provider allows access to your Firebase resources from unverified devices. * Don't use the debug provider in production builds of your app, and don't share your debug builds with untrusted parties. * * @since 7.1.0 * @default false * @see https://firebase.google.com/docs/app-check/android/debug-provider#ci * @see https://firebase.google.com/docs/app-check/ios/debug-provider#ci * @see https://firebase.google.com/docs/app-check/web/debug-provider */ debugToken?: boolean | string; /** * If `true`, the SDK automatically refreshes App Check tokens as needed. * * @since 1.3.0 * @default false */ isTokenAutoRefreshEnabled?: boolean; /** * The provider to use for App Check. Must be an instance of * `ReCaptchaV3Provider`, `ReCaptchaEnterpriseProvider`, or `CustomProvider`. * * Only available for Web. * * @since 7.1.0 * @default ReCaptchaV3Provider * @see https://firebase.google.com/docs/app-check/web/custom-provider */ provider?: any; /** * The reCAPTCHA v3 site key (public key). This option is ignored when `provider` is set. * * Only available for Web. * * @deprecated Use `provider` instead. * @since 1.3.0 */ siteKey?: string;}SetTokenAutoRefreshEnabledOptions
设置 App Check token 自动刷新选项export interface SetTokenAutoRefreshEnabledOptions { /** * If `true`, the SDK automatically refreshes App Check tokens as needed. * This overrides any value set during initializeAppCheck(). * * @since 1.3.0 */ enabled: boolean;}TokenChangedListener
TokenChangedListener接收令牌变化事件的回调。
export type TokenChangedListener = (event: TokenChangedEvent) => void;GetPluginVersionResult
contextexport interface GetPluginVersionResult { /** * The semantic version of this plugin. * * @since 8.0.1 */ version: string;}TokenChangedEvent
TokenChanged事件export interface TokenChangedEvent { /** * The App Check token in JWT format. * * @since 1.3.0 */ token: string;}GetPluginVersionResult
TokenChangedEvent真实来源 src/definitions.ts重新同步时,當上游的公共API發生變化時,重新執行同步。
本页由插件生成的。重新同步公共__CAPGO_KEEP_0__时,重新运行上游的同步。
Section titled “继续从 Getting Started”如果您正在使用 开始使用 来规划仪表板和API操作,连接它与 API 简介 查看API Overview中的实施细节 介绍 查看介绍中的实施细节 API 键 查看API Keys中的实施细节 设备 查看设备中的实施细节 【插件】 为插件详细信息。