从何处开始使用 Firebase Authentication?
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
我已经有身份验证系统
如果您的应用已有登录实现,而您想使用它进行 Firebase 后端服务身份验证,请使用自定义身份验证。使用以下任一身份验证方式的应用均可采用此方法:
- 定制解决方案,例如基于密码的自定义系统。
- 第三方身份管理服务,例如 Auth0 或 OKta。
- 与联合身份提供方(如 Google、Facebook 或 Apple)的现有集成。(如果您还不支持联合身份,但希望使用,请参阅下一部分。)
借助自定义身份验证,您可以让用户通过您选择的系统登录,在后端为用户创建 Firebase 令牌,然后使用客户端提供的令牌进行 Firebase 身份验证。
请参阅适用于 iOS+、Android、Web、Flutter、Unity 或 C++ 的文档。
我想使用 Firebase 构建身份验证系统
如果您要构建新应用或向现有应用添加登录机制,可使用 Firebase 提供的库和服务实现安全身份验证,而无需自行构建身份验证后端。Firebase Authentication 是一个完整的后端解决方案,可供用户使用密码、联合身份提供方、电子邮件链接和短信进行登录。
我需要一个易于使用的普适性解决方案
如需向应用添加身份验证,最快捷、简单的方法是使用 FirebaseUI 身份验证,这是一个普适性界面库。FirebaseUI 为 Firebase Authentication 支持的所有登录方法实现了完整的用户流。
由于 FirebaseUI Auth 是普适性解决方案,因此它提供的特定用户体验可能无法满足您的需求。如果要改变用户体验,您可以复刻此开源库,并根据需要进行修改。但是,对于截然不同的登录流程,您可能更希望通过 Firebase SDK 实现自己的流程(如下一部分所述)。
请参阅适用于 iOS、Android 或 Web 的 FirebaseUI Auth 文档。
我想完全掌控登录体验
为了更好地控制您应用的登录体验,您可以实现自己的身份验证流程,并使用 Firebase SDK 来处理 Firebase 的身份验证服务。例如,您可以构建自己的电子邮件地址和密码流程或 Google 登录流程,并将用户的电子邮件地址和密码或 Google ID 令牌传递给 Firebase,以对用户进行身份验证。
请参阅 Firebase Authentication SDK 文档:
我想打造丰富的登录前体验
您可以利用匿名身份验证,让用户在实际登录前就能使用应用的已登录功能。借助匿名“登录”功能,您可以创建临时的单会话账号,将其当作真实账号一样来使用。然后,在用户登录或注册后,将临时账号与真实账号相关联,使其能够从中断的地方继续操作。
“匿名身份验证”可与“自定义身份验证”或 Firebase 的任何身份验证服务搭配使用。
请参阅适用于 iOS+、Android、Web、Flutter、Unity 或 C++ 的文档。
我想从我的后端访问 Firebase 服务
若要从服务器访问 Firebase 服务,您无需使用 Firebase Authentication。请改用 Admin SDK。初始化 Admin SDK 时,请使用服务账号凭证进行身份验证,这些凭证代表您的 Firebase 项目而非特定用户,会授予对项目资源的完整访问权限。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-06。
[null,null,["最后更新时间 (UTC):2025-08-06。"],[],[],null,["I already have an authentication system\n\nIf your app already has a sign-in implementation and you want to use it to\nauthenticate with Firebase backend services, use **Custom Authentication**. This\nincludes apps that use any of the following:\n\n- Custom-built solutions, such as custom password-based systems.\n- Third-party identity management services, such as Auth0 or Okta.\n- Existing integrations with federated identity providers, such as Google, Facebook, or Apple. (And if you don't yet support federated identity, but you want to, see the next section.)\n\nWith custom authentication, you sign users in with the system of your choice,\ncreate a Firebase token for the user on your backend, and then use the token\nfrom the client to authenticate with Firebase.\n\nSee the docs for\n[iOS+](/docs/auth/ios/custom-auth),\n[Android](/docs/auth/android/custom-auth),\n[Web](/docs/auth/web/custom-auth),\n[Flutter](/docs/auth/flutter/custom-auth),\n[Unity](/docs/auth/unity/custom-auth), or\n[C++](/docs/auth/cpp/custom-auth).\n\nI want to build my authentication system with Firebase\n\nIf you're building a new app or adding sign-in to an existing app, Firebase has\nlibraries and services that can help you implement secure authentication without\nhaving to build the authentication backend yourself. Firebase Authentication is a\ncomplete backend solution for signing in with passwords, federated identity\nproviders, email links, and text messages.\n\nI want a drop-in solution that's easy to use\n\nThe fastest and easiest way to add authentication to an app is to use\n**FirebaseUI Auth** , a drop-in UI library. FirebaseUI implements complete user\nflows for all of Firebase Authentication's supported sign-in methods.\n\nBecause FirebaseUI Auth is a drop-in solution, it has a specific UX that might\nnot meet your needs. If you want to change the UX, you can fork the library,\nwhich is open source, and use your own version. However, for substantially\ndifferent sign-in flows, you might prefer to implement your own flows with the\nFirebase SDK as discussed in the next section.\n\nSee the FirebaseUI Auth docs for\n[iOS](/docs/auth/ios/firebaseui),\n[Android](/docs/auth/android/firebaseui), or\n[Web](/docs/auth/web/firebaseui).\n\nI want full control over the sign-in experience\n\nFor more control over your app's sign-in experience, you can implement your own\nauthentication flows and use the Firebase SDK to work with Firebase's\nauthentication services. For example, build your own email address and password\nflow or Google Sign-in flow, and pass the user's email address and password or\nGoogle ID token to Firebase to authenticate the user.\n\nSee the Firebase Authentication SDK docs:\n\n| Firebase services ||\n|----------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **Email address and password sign-in** | [iOS+](/docs/auth/ios/password-auth) \\| [Android](/docs/auth/android/password-auth) \\| [Web](/docs/auth/web/password-auth) \\| [Flutter](/docs/auth/flutter/password-auth) \\| [Unity](/docs/auth/unity/password-auth) \\| [C++](/docs/auth/cpp/password-auth) |\n| **Phone number sign-in** | [iOS+](/docs/auth/ios/phone-auth) \\| [Android](/docs/auth/android/phone-auth) \\| [Web](/docs/auth/web/phone-auth) \\| [Flutter](/docs/auth/flutter/phone-auth) \\| [Unity](/docs/auth/unity/phone-auth) \\| [C++](/docs/auth/cpp/phone-auth) |\n| **Email link sign-in** | [iOS+](/docs/auth/ios/email-link-auth) \\| [Android](/docs/auth/android/email-link-auth) \\| [Web](/docs/auth/web/email-link-auth) \\| [Flutter](/docs/auth/flutter/email-link-auth) \\| [Unity](/docs/auth/unity/email-link-auth) \\| [C++](/docs/auth/cpp/email-link-auth) |\n| **Google** | [iOS+](/docs/auth/ios/google-signin) \\| [Android](/docs/auth/android/google-signin) \\| [Web](/docs/auth/web/google-signin) \\| [Flutter](/docs/auth/flutter/federated-auth#google) \\| [Unity](/docs/auth/unity/google-signin) \\| [C++](/docs/auth/cpp/google-signin) |\n| **Facebook** | [iOS+](/docs/auth/ios/facebook-login) \\| [Android](/docs/auth/android/facebook-login) \\| [Web](/docs/auth/web/facebook-login) \\| [Flutter](/docs/auth/flutter/federated-auth#facebook) \\| [Unity](/docs/auth/unity/facebook-login) \\| [C++](/docs/auth/cpp/facebook-login) |\n| **Apple** | [iOS+](/docs/auth/ios/apple) \\| [Android](/docs/auth/android/apple) \\| [Web](/docs/auth/web/apple) \\| [Flutter](/docs/auth/flutter/federated-auth#apple) \\| [Unity](/docs/auth/unity/apple) \\| [C++](/docs/auth/cpp/apple) |\n| **Play Games** | [Android](/docs/auth/android/play-games) \\| [Unity](/docs/auth/unity/play-games) \\| [C++](/docs/auth/cpp/play-games) |\n| **Game Center** | [iOS+](/docs/auth/ios/game-center) |\n| **GitHub** | [iOS+](/docs/auth/ios/github-auth) \\| [Android](/docs/auth/android/github-auth) \\| [Web](/docs/auth/web/github-auth) \\| [Flutter](/docs/auth/flutter/federated-auth#github) \\| [Unity](/docs/auth/unity/github-auth) \\| [C++](/docs/auth/cpp/github-auth) |\n| **Microsoft** | [iOS+](/docs/auth/ios/microsoft-oauth) \\| [Android](/docs/auth/android/microsoft-oauth) \\| [Web](/docs/auth/web/microsoft-oauth) \\| [Unity](/docs/auth/unity/microsoft-oauth) \\| [C++](/docs/auth/cpp/microsoft-oauth) |\n| **Twitter** | [iOS+](/docs/auth/ios/twitter-login) \\| [Android](/docs/auth/android/twitter-login) \\| [Web](/docs/auth/web/twitter-login) \\| [Flutter](/docs/auth/flutter/federated-auth#twitter) \\| [Unity](/docs/auth/unity/twitter-login) \\| [C++](/docs/auth/cpp/twitter-login) |\n| **Yahoo** | [iOS+](/docs/auth/ios/yahoo-oauth) \\| [Android](/docs/auth/android/yahoo-oauth) \\| [Web](/docs/auth/web/yahoo-oauth) \\| [Unity](/docs/auth/unity/yahoo-oauth) \\| [C++](/docs/auth/cpp/yahoo-oauth) |\n\nI want to build rich pre-sign-in experiences\n\nYou can enable users to use the signed-in features of your app before they\nactually sign in using **Anonymous Auth**. With anonymous \"sign-in\", you create\ntemporary single-session accounts, which you can use like a real account. Then,\nafter the user signs in or signs up, link the temporary account to the real\naccount to let them continue where they left off.\n\nAnonymous Auth works well alongside either Custom Auth or any of Firebase's\nauthentication services.\n\nSee the docs for\n[iOS+](/docs/auth/ios/anonymous-auth),\n[Android](/docs/auth/android/anonymous-auth),\n[Web](/docs/auth/web/anonymous-auth),\n[Flutter](/docs/auth/flutter/anonymous-auth),\n[Unity](/docs/auth/unity/anonymous-auth), or\n[C++](/docs/auth/cpp/anonymous-auth).\n\nI want to access Firebase services from my backend\n\nTo access Firebase services from a server, you don't need to use\nFirebase Authentication. Instead, use the [Admin SDK](/docs/admin/setup). When you\ninitialize the Admin SDK, you authenticate with service account credentials,\nwhich represent your Firebase project rather than a particular user, and which\ngrant full access to your project's resources."]]