Token导航 LogoToken导航TokenDH.com
开发敏感数据github未标认证来源可访问许可证需确认审计通过

firebase-authFirebase auth 安全

Agent Skill

用于辅助安全审计、权限检查、凭据风险、认证流程和常见漏洞排查。它适合让 Agent 梳理敏感配置、检查依赖风险、分析鉴权逻辑或生成安全复核清单。使用时不能把工具输出直接当最终结论,涉及密钥、令牌、用户数据或生产系统时,应先确认最小权限、脱敏方式和操作边界。

总安装

220

周安装

9

GitHub Stars

537

下载量

71
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:firebase-auth(Firebase auth 安全)
来源仓库:https://github.com/evanca/flutter-ai-rules
仓库路径:skills/firebase-auth
安装命令:
npx skills add https://github.com/evanca/flutter-ai-rules --skill firebase-auth
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/evanca/flutter-ai-rules --skill firebase-auth

简介

firebase-auth 指导 Flutter 应用正确使用 Firebase 身份认证,涵盖设置、状态监听和安全实践。

  • 适用于用户登录、社交授权、MFA 管理等认证场景,提供安全的鉴权流程实现方案。
  • 使用时需按步骤配置 providers、处理错误和状态变化,遵循最小权限原则管理凭据。
  • 安装前请确认仓库权限和维护状态,涉及密钥或用户数据时应先脱敏并限制操作边界。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Firebase Authentication Skill

This skill defines how to correctly use Firebase Authentication in Flutter applications.

When to Use

Use this skill when:

  • Setting up Firebase Authentication in a Flutter project.
  • Listening to authentication state changes.
  • Implementing email/password or social sign-in.
  • Managing user profiles, account linking, or MFA.
  • Handling authentication errors.
  • Applying security best practices for auth flows.

1. Setup and Configuration

flutter pub add firebase_auth
import 'package:firebase_auth/firebase_auth.dart';
  • Enable desired authentication providers in the Firebase console before using them.
  • Initialize Firebase before using any Firebase Authentication features.

Local emulator for testing:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
  // ...
}

2. Authentication State Management

Use the appropriate stream based on what you need to observe:

StreamFires when
authStateChanges()User signs in or out
idTokenChanges()ID token changes (including custom claims)
userChanges()User data changes (e.g., profile updates)
FirebaseAuth.instance
  .authStateChanges()
  .listen((User? user) {
    if (user == null) {
      print('User is currently signed out!');
    } else {
      print('User is signed in!');
    }
  });
  • Listen to these streams immediately when the app starts to handle the initial auth state.
  • Custom claims are only available after sign-in, re-authentication, token expiration, or manual token refresh.

3. Email and Password Authentication

Create a new account:

try {
  final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
    email: emailAddress,
    password: password,
  );
} on FirebaseAuthException catch (e) {
  if (e.code == 'weak-password') {
    print('The password provided is too weak.');
  } else if (e.code == 'email-already-in-use') {
    print('The account already exists for that email.');
  }
} catch (e) {
  print(e);
}

Sign in:

try {
  final credential = await FirebaseAuth.instance.signInWithEmailAndPassword(
    email: emailAddress,
    password: password,
  );
} on FirebaseAuthException catch (e) {
  if (e.code == 'invalid-credential') {
    // Email enumeration protection enabled (default since Sep 2023):
    // replaces 'user-not-found' and 'wrong-password'.
    print('Invalid email or password.');
  } else if (e.code == 'user-not-found') {
    print('No user found for that email.');
  } else if (e.code == 'wrong-password') {
    print('Wrong password provided for that user.');
  }
}
  • Verify the user's email address after account creation.
  • Firebase rate-limits new email/password sign-ups from the same IP to protect against abuse.
  • On iOS/macOS, authentication state persists between app re-installs via the system keychain.
  • Since September 2023, Firebase enables email enumeration protection by default on new projects, replacing user-not-found and wrong-password with invalid-credential. Manage this in the Firebase console under Authentication > Settings.

4. Social Authentication

Google Sign-In (native platforms):

Future<UserCredential> signInWithGoogle() async {
  final GoogleSignInAccount? googleUser = await GoogleSignIn.instance.authenticate();
  final GoogleSignInAuthentication googleAuth = googleUser.authentication;
  final credential = GoogleAuthProvider.credential(idToken: googleAuth.idToken);
  return await FirebaseAuth.instance.signInWithCredential(credential);
}

Google Sign-In (web):

Future<UserCredential> signInWithGoogle() async {
  GoogleAuthProvider googleProvider = GoogleAuthProvider();
  googleProvider.addScope('https://www.googleapis.com/auth/contacts.readonly');
  googleProvider.setCustomParameters({'login_hint': 'user@example.com'});
  return await FirebaseAuth.instance.signInWithPopup(googleProvider);
}
  • Configure platform-specific settings for each provider (e.g., SHA1 key for Google Sign-In on Android).
  • If a user signs in with a social provider after registering with the same email manually, Firebase's trusted provider concept will automatically change their authentication provider.
  • On Android, signInWithProvider opens a Chrome Custom Tab. If AndroidManifest.xml contains android:taskAffinity="" (Flutter's default), the tab closes when the user switches apps (e.g., to use a password manager), causing a web-context-already-presented error. Remove android:taskAffinity="" to fix this.
  • When signing in with Apple, add the email and name scopes to present the full first-time sign-in UI (including "Share/Hide email"): final appleProvider = AppleAuthProvider(); appleProvider.addScope('email'); appleProvider.addScope('name');

5. Error Handling

Common FirebaseAuthException codes and their recommended handling:

Error codeMeaningAction
weak-passwordPassword does not meet strength requirementsShow password requirements to user
email-already-in-useAccount exists for this emailPrompt sign-in or password reset
user-not-foundNo account for this emailPrompt account creation
wrong-passwordIncorrect passwordShow error, offer password reset
too-many-requestsRate limitedShow cooldown message, retry later
account-exists-with-different-credentialEmail linked to another providerFetch sign-in methods, guide user to correct provider
operation-not-allowedProvider not enabledEnable the provider in the Firebase console
  • Always use try-catch with FirebaseAuthException.
  • Check e.code to identify specific error types and provide actionable user feedback.

6. User Management

// Update profile
await FirebaseAuth.instance.currentUser?.updateProfile(
  displayName: "Jane Q. User",
  photoURL: "https://example.com/jane-q-user/profile.jpg",
);

// Update email (sends verification to new address first)
await user?.verifyBeforeUpdateEmail("newemail@example.com");
  • Use verifyBeforeUpdateEmail()not updateEmail() — to change a user's email. The email only updates after the user verifies it.
  • Store only essential info in the auth profile; use a database for additional user data.
  • Use linkWithCredential() to connect multiple auth providers to a single account.
  • Verify the user's identity before linking new credentials.
  • Use fetchSignInMethodsForEmail() when handling account linking.

7. Security Best Practices

  • Never store sensitive authentication credentials in client-side code.
  • Monitor auth state changes for proper session management.
  • Validate user input before submitting authentication requests to prevent injection attacks.
  • Call FirebaseAuth.instance.signOut() when users exit the app.
  • For sensitive operations, re-authenticate users with reauthenticateWithCredential().
  • Enforce strong password policies for email/password auth.
  • In Realtime Database and Cloud Storage Security Rules, use the auth variable to get the signed-in user's UID for access control.
  • Use multi-factor authentication for sensitive applications.

8. Multi-Factor Authentication

Security warning: Avoid SMS-based MFA. SMS is insecure and easy to compromise or spoof.
Platform limitation: Windows does not support MFA. MFA with multiple tenants is not supported on Flutter.
  • Enable at least one MFA-compatible provider before implementing MFA.

9. Email Link Authentication

Important: Firebase Dynamic Links is deprecated for email link authentication. Firebase Hosting is now used to send sign-in links.
  • Set handleCodeInApp: true in ActionCodeSettings — sign-in must always be completed in the app.
  • Store the user's email locally (e.g., SharedPreferences) when sending the sign-in link.
  • Never pass the user's email in redirect URL parameters — this enables session injection attacks.
  • Use HTTPS URLs in production to prevent link interception.
  • Configure the app to detect incoming links and parse the underlying deep link for sign-in completion.

References

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.58%
按下载量换算27

Claude

30.44%
按下载量换算22

Cursor

17.01%
按下载量换算12

Gemini CLI

8.98%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills