跳到正文
FunCoding

搜索

搜索文档、Skill 和 MCP

firebase-app-check

Use when implementing app attestation, configuring App Check providers, setting up debug tokens, enabling backend enforcement, or managing token refresh.

AI 与智能体650skills/firebase-app-check/SKILL.md

安装

把这段话发给 Claude Code、Codex 或 Cursor。智能体会先检查安全性,你确认后才安装。

读取 https://funcoding.ai/skills/evanca/flutter-ai-rules/firebase-app-check/install.md ,按里面的步骤帮我安装这个 Skill。

SKILL.md

Firebase App Check Skill

This skill defines how to correctly implement Firebase App Check in Flutter applications, covering provider selection, debug configuration, enforcement rollout, and security hardening.

When to Use

Use this skill when:

  • Setting up and activating Firebase App Check in a Flutter project.
  • Selecting the right attestation provider for each platform.
  • Configuring debug providers for development, testing, and CI.
  • Enabling enforcement and monitoring App Check metrics.
  • Implementing token refresh handling and custom TTL configuration.

1. Setup and Configuration

flutter pub add firebase_app_check
import 'package:firebase_app_check/firebase_app_check.dart';

Initialize App Check after Firebase.initializeApp() and before using any Firebase services:

await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
  webProvider: ReCaptchaV3Provider('recaptcha-v3-site-key'),
  androidProvider: AndroidProvider.playIntegrity,
  appleProvider: AppleProvider.deviceCheck,
);

Setup Checklist

  1. Register apps in the Firebase console under Project Settings > App Check.
  2. For web, obtain a reCAPTCHA v3 site key from the Firebase console.
  3. Confirm activation completes before any Firestore, Storage, or RTDB calls.
  4. Consider setting a custom TTL — shorter TTLs are more secure but consume quota faster.

Native FirebaseApp.configure() on Apple Platforms

Avoid calling FirebaseApp.configure() natively in your AppDelegate — Firebase.initializeApp() already configures the native default app. If you must call it, install your AppCheckProviderFactory before configure(); otherwise the Apple SDK locks in DeviceCheck on physical devices and the appleProvider passed to activate() (including AppleProvider.debug) is silently ignored. This is easiest to miss because simulators already default to the debug provider. activate() on Android is unaffected. See flutterfire#18613.


2. Provider Selection

Android:

ProviderUse case
AndroidProvider.playIntegrityProduction (default)
AndroidProvider.debugDevelopment / CI only

Apple (iOS / macOS):

ProviderUse case
AppleProvider.deviceCheckProduction default (iOS 11+, macOS 10.15+)
AppleProvider.appAttestEnhanced security (iOS 14+, macOS 14+)
AppleProvider.appAttestWithDeviceCheckFallbackApp Attest with Device Check fallback
AppleProvider.debugDevelopment / CI only

Web:

ProviderUse case
ReCaptchaV3ProviderStandard reCAPTCHA v3
ReCaptchaEnterpriseProviderEnhanced with additional features

Android note: For certain Android devices, enable "Meets basic device integrity" in the Google Play console to ensure proper App Check functionality.


3. Development and Testing

Use debug providers during development to run in emulators or CI environments:

await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate(
  androidProvider: AndroidProvider.debug,
  appleProvider: AppleProvider.debug,
);

Platform-Specific Debug Setup

iOS: Enable debug logging by adding -FIRDebugEnabled to Arguments Passed on Launch in Xcode. The debug token appears in the console output. On physical devices, AppleProvider.debug is ignored if your AppDelegate calls FirebaseApp.configure() natively — see the native configure() note in Setup and Configuration.

Android: The debug token prints to logcat on first run. Filter by DebugAppCheckProvider.

Web: Set self.FIREBASE_APPCHECK_DEBUG_TOKEN = true; in web/index.html before Firebase scripts load.

Register Debug Tokens

  1. Copy the debug token from the device/emulator console output.
  2. In the Firebase console, navigate to App Check > Apps > Manage debug tokens.
  3. Add the token. It is immediately active for that app.

Token Listener for Custom Backends

FirebaseAppCheck.instance.onTokenChange.listen((token) {
  // Attach token to custom backend requests
  // e.g., set as Authorization header
});
  • Never use debug providers or share debug tokens in production builds.
  • Keep debug tokens private — do not commit them to public repositories.
  • Revoke compromised debug tokens immediately from the Firebase console.

4. Enforcement Rollout

Follow this sequence to avoid disrupting legitimate users:

  1. Deploy App Check activation code to all app versions.
  2. Monitor App Check metrics in the Firebase console — wait until most traffic shows valid tokens.
  3. Enable enforcement gradually, starting with non-critical Firebase services (e.g., Cloud Storage before Firestore).
  4. Verify that unverified request percentage drops to near zero before enforcing on critical services.
  • Once enforcement is enabled, only apps with valid App Check tokens can access protected Firebase resources.
  • Use App Check in combination with Firebase Security Rules for defense in depth.
  • Implement proper error handling for App Check verification failures — surface a user-friendly message rather than a raw error.

5. Security Best Practices

  • Never disable App Check in production builds once enabled.
  • Implement a fallback mechanism for App Check verification failures (e.g., retry with exponential backoff).
  • Regularly review App Check metrics to identify potential abuse patterns.
  • App Check tokens are automatically refreshed at approximately half the TTL duration.
  • For high-security applications, use the shortest practical TTL.
  • Implement server-side verification for critical operations using the Firebase Admin SDK:
// Node.js Admin SDK example for verifying App Check tokens
const appCheckToken = req.header('X-Firebase-AppCheck');
const appCheckClaims = await getAppCheck().verifyToken(appCheckToken);

References

相似的 Skill

brand-guidelines
anthropics/skills180k

brand-guidelines

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

AI 与智能体

internal-comms
anthropics/skills180k

internal-comms

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

AI 与智能体

template-skill
anthropics/skills180k

template-skill

Replace with description of the skill and when Claude should use it.

AI 与智能体

mcp-builder
anthropics/skills180k

mcp-builder

Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).

AI 与智能体

algorithmic-art
anthropics/skills180k

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.

AI 与智能体

academy-guide
anthropics/skills180k

academy-guide

Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.

AI 与智能体