@capacitor-firebase/app-check

中文文档
8.6.0发布于 2026/10/31Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 11.5万

Capacitor plugin for Firebase App Check on Android, iOS, and Web.

原始使用文档
文档目录36 节
  1. Use Cases
  2. Compatibility
  3. Guides
  4. Installation
  5. Android
  6. iOS
  7. Web
  8. Configuration
  9. Firebase JavaScript SDK
  10. Demo
  11. Usage
  12. Initialize App Check
  13. Get the current App Check token
  14. Enable automatic token refresh
  15. Listen for token changes
  16. Remove all listeners
  17. API
  18. getToken(...)
  19. initialize(...)
  20. setTokenAutoRefreshEnabled(...)
  21. addListener('tokenChanged', ...)
  22. removeAllListeners()
  23. Interfaces
  24. Type Aliases
  25. Testing
  26. Android
  27. FAQ
  28. Which attestation providers does this plugin use?
  29. How can I test App Check on emulators and other unverified …
  30. How do I protect my own backend with App Check?
  31. Why is my App Check token not refreshed automatically?
  32. Can I use this plugin with Ionic, React, Vue or Angular?
  33. Related Plugins
  34. Newsletter
  35. Changelog
  36. License

Capacitor Firebase App Check Plugin

Unofficial Capacitor plugin for Firebase App Check.[^1]

Use Cases

The Firebase App Check plugin is typically used to verify that requests to your backend originate from your authentic app, for example:

  • Protecting Firebase resources: Ensure that only your genuine app can access services like Cloud Firestore or Cloud Functions by attesting requests with Play Integrity, App Attest, or reCAPTCHA v3.
  • Securing custom backends: Retrieve an App Check token with getToken(...) and send it along with requests to your own backend for server-side verification.
  • Automatic token refresh: Keep App Check tokens up to date with setTokenAutoRefreshEnabled(...) and react to changes via the tokenChanged listener.
  • Local development: Use the debug provider to test your app on unverified devices such as emulators.

Compatibility

Plugin VersionCapacitor VersionStatus
8.x.x>=8.x.xActive support
7.x.x7.x.xDeprecated
6.x.x6.x.xDeprecated
5.x.x5.x.xDeprecated

Guides

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capacitor-firebase/app-check` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capacitor-firebase/app-check firebase
npx cap sync

Add Firebase to your project if you haven't already (Android / iOS / Web).

Android

See Set up your Firebase project and follow the instructions to set up your app correctly.

Variables

If needed, you can define the following project variable in your app’s variables.gradle file to change the default version of the dependency:

  • $firebaseAppCheckPlayIntegrityVersion version of com.google.firebase:firebase-appcheck-playintegrity (default: 19.0.1)
  • $firebaseAppCheckDebugVersion version of com.google.firebase:firebase-appcheck-debug (default: 19.0.1)

This can be useful if you encounter dependency conflicts with other plugins in your project.

iOS

On iOS 14 and later, see Set up your Firebase project and follow the instructions to set up your app correctly.

On iOS 13, see Set up your Firebase project and follow the instructions to set up your app correctly.

Make sure that the private key (*.p8) you upload to Firebase has DeviceCheck selected as a service.

Swift Package Manager

Add the following to your capacitor.config.json (or capacitor.config.ts) to avoid a SwiftPM package identity collision:

{
  "experimental": {
    "ios": {
      "spm": {
        "packageOptions": {
          "@capacitor-firebase/app-check": {
            "symlink": true
          }
        }
      }
    }
  }
}

Attention: SPM packageOptions support requires Capacitor CLI 8.4.0+.

Web

See Set up your Firebase project and follow the instructions to set up your app correctly.

Configuration

No configuration required for this plugin.

Firebase JavaScript SDK

Here you can find information on how to use the plugin with the Firebase JS SDK.

Demo

A working example can be found here: robingenz/capacitor-firebase-plugin-demo

Usage

The following examples show how to initialize App Check, get the current token, enable automatic token refresh, and listen for token changes.

Initialize App Check

Activate App Check for your app. This can be called only once per app. On the Web, pass a provider such as ReCaptchaV3Provider; on Android and iOS, the native attestation providers are used:

import { FirebaseAppCheck } from '@capacitor-firebase/app-check';
import { ReCaptchaV3Provider } from '@capacitor-firebase/app-check';
import { Capacitor } from '@capacitor/core';

const initialize = async () => {
  await FirebaseAppCheck.initialize({
    provider: Capacitor.getPlatform() === 'web' ? new ReCaptchaV3Provider('myKey') : undefined,
  });
};

Get the current App Check token

Retrieve the current App Check token, for example to send it to your own backend. Set forceRefresh to true if you always want to fetch a fresh token instead of a cached one:

import { FirebaseAppCheck } from '@capacitor-firebase/app-check';

const getToken = async () => {
  const { token } = await FirebaseAppCheck.getToken({
    forceRefresh: false,
  });
  return token;
};

Enable automatic token refresh

Set whether the App Check token should be refreshed automatically as needed:

import { FirebaseAppCheck } from '@capacitor-firebase/app-check';

const setTokenAutoRefreshEnabled = async () => {
  await FirebaseAppCheck.setTokenAutoRefreshEnabled({ enabled: true });
};

Listen for token changes

Get notified whenever the App Check token changes:

import { FirebaseAppCheck } from '@capacitor-firebase/app-check';

const addTokenChangedListener = async () => {
  await FirebaseAppCheck.addListener('tokenChanged', event => {
    console.log('tokenChanged', { event });
  });
};

Remove all listeners

Remove all listeners for this plugin. Only available on Web:

import { FirebaseAppCheck } from '@capacitor-firebase/app-check';

const removeAllListeners = async () => {
  await FirebaseAppCheck.removeAllListeners();
};

API

getToken(...)

getToken(options?: GetTokenOptions | undefined) => Promise<GetTokenResult>

Get the current App Check token.

ParamType
optionsGetTokenOptions

Returns: Promise<GetTokenResult>

Since: 1.3.0


initialize(...)

initialize(options?: InitializeOptions | undefined) => Promise<void>

Activate App Check for the given app. Can be called only once per app.

ParamType
optionsInitializeOptions

Since: 1.3.0


setTokenAutoRefreshEnabled(...)

setTokenAutoRefreshEnabled(options: SetTokenAutoRefreshEnabledOptions) => Promise<void>

Set whether the App Check token should be refreshed automatically or not.

ParamType
optionsSetTokenAutoRefreshEnabledOptions

Since: 1.3.0


addListener('tokenChanged', ...)

addListener(eventName: 'tokenChanged', listenerFunc: TokenChangedListener) => Promise<PluginListenerHandle>

Called when the App Check token changed.

ParamType
eventName'tokenChanged'
listenerFuncTokenChangedListener

Returns: Promise<PluginListenerHandle>

Since: 1.3.0


removeAllListeners()

removeAllListeners() => Promise<void>

Remove all listeners for this plugin.

Only available for Web.

Since: 1.3.0


Interfaces

GetTokenResult

PropTypeDescriptionSince
tokenstringThe App Check token in JWT format.1.3.0
expireTimeMillisnumberThe timestamp after which the token will expire in milliseconds since epoch. Only available for Android and iOS.1.3.0

GetTokenOptions

PropTypeDescriptionDefaultSince
forceRefreshbooleanIf true, will always try to fetch a fresh token. If false, will use a cached token if found in storage.false1.3.0

InitializeOptions

PropTypeDescriptionDefaultSince
debugbooleanIf 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-providerfalse1.3.0
debugTokenstring | booleanIf 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.false7.1.0
isTokenAutoRefreshEnabledbooleanIf true, the SDK automatically refreshes App Check tokens as needed.false1.3.0
provideranyThe provider to use for App Check. Must be an instance of ReCaptchaV3Provider, ReCaptchaEnterpriseProvider, or CustomProvider. Only available for Web.ReCaptchaV3Provider7.1.0
siteKeystringThe reCAPTCHA v3 site key (public key). This option is ignored when provider is set. Only available for Web.1.3.0

SetTokenAutoRefreshEnabledOptions

PropTypeDescriptionSince
enabledbooleanIf true, the SDK automatically refreshes App Check tokens as needed. This overrides any value set during initializeAppCheck().1.3.0

PluginListenerHandle

PropType
remove() => Promise<void>

TokenChangedEvent

PropTypeDescriptionSince
tokenstringThe App Check token in JWT format.1.3.0

Type Aliases

TokenChangedListener

Callback to receive the token change event.

(event: TokenChangedEvent): void

Testing

Android

Follow these steps to test your implementation on a real device:

  1. Start your app on the Android device.
  2. Run the following command to grab your temporary secret from the android logs:
adb logcat | grep DebugAppCheckProvider

The output should look like this:

D DebugAppCheckProvider: Enter this debug secret into the allow list in
the Firebase Console for your project: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  1. Next, open the App Check project in the Firebase Console and select Manage debug tokens from the overflow menu of your app. Then, register the debug secret from the output.

FAQ

Which attestation providers does this plugin use?

On Android, the plugin uses the Play Integrity provider. On iOS, it uses App Attest on iOS 14 and later and DeviceCheck on iOS 13. On the Web, it uses reCAPTCHA v3 by default, but you can also pass a ReCaptchaEnterpriseProvider or CustomProvider instance via the provider option.

How can I test App Check on emulators and other unverified devices?

Use the debug provider by setting the debugToken option of the initialize(...) method. On Android, you can grab the temporary debug secret from the device logs and register it in the Firebase Console (see Testing). Never use the debug provider in production builds of your app and never share your debug builds with untrusted parties, as it allows access to your Firebase resources from unverified devices.

How do I protect my own backend with App Check?

Call the getToken(...) method to retrieve the current App Check token in JWT format and send it along with requests to your backend, where you can verify it server-side. Use the tokenChanged listener to get notified whenever the token changes.

Why is my App Check token not refreshed automatically?

Automatic token refresh is disabled by default. You can enable it with the isTokenAutoRefreshEnabled option of the initialize(...) method or at any time with the setTokenAutoRefreshEnabled(...) method.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

[^1]: This project is not affiliated with, endorsed by, sponsored by, or approved by Google LLC or any of their affiliates or subsidiaries.

版本与发布记录

@capacitor-firebase/app-check 共发布 38 个版本,首次发布于 2022/11/06;过去 12 个月发布了 13 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.6.0latest2026/10/319 天前
8.5.22026/09/171 个月前
8.5.12026/09/022 个月前
8.5.02026/08/312 个月前
8.4.02026/08/122 个月前
8.3.02026/06/045 个月前

其他发布通道:dev → 7.0.0-dev.1765887457。

关于 @capacitor-firebase/app-check 的常见问题

@capacitor-firebase/app-check 是什么?

Capacitor plugin for Firebase App Check on Android, iOS, and Web.

如何安装 @capacitor-firebase/app-check?

在项目目录运行 npm install @capacitor-firebase/app-check,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capacitor-firebase/app-check 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capacitor-firebase/app-check 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capacitor-firebase/app-check 可以商用吗?

@capacitor-firebase/app-check 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@capacitor-firebase/app-check 的下载量有多少?

根据 npm 官方下载统计,@capacitor-firebase/app-check 在 2026/10/09 – 2026/11/07 这 30 天内被下载 115,106 次,日均约 3,837 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capacitor-firebase/app-check 还在维护吗?

最新版本 8.6.0 发布于 2026/10/31(9 天前);至今共发布 38 个版本,其中过去 12 个月发布了 13 个;首次发布于 2022/11/06。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。