使用 Google 身份验证
有关使用 @react-native-google-signin/google-signin 库将 Google 身份验证集成到 Expo 项目中的指南。
@react-native-google-signin/google-signin
库提供了一种在 Expo 应用中集成 Google 身份验证的方法。它还提供原生登录按钮,并支持对用户进行身份验证以及获取用户使用 Google API 的授权。你可以通过在 应用配置 中添加 配置插件 来在项目中使用该库。
¥The @react-native-google-signin/google-signin
library provides a way integrate Google authentication in your Expo app. It also provides native sign-in buttons and supports authenticating the user as well as obtaining their authorization to use Google APIs. You can use the library in your project by adding the config plugin in the app config.
本指南提供了有关如何为你的项目配置库的信息。
¥This guide provides information on how to configure the library for your project.
先决条件
¥Prerequisites
@react-native-google-signin/google-signin
库无法在 Expo Go 应用中使用,因为它需要自定义原生代码。了解有关 将自定义原生代码添加到你的应用 的更多信息。
¥The @react-native-google-signin/google-signin
library can't be used in the Expo Go app because it requires custom native code. Learn more about adding custom native code to your app.
安装
¥Installation
有关如何安装和配置库的说明,请参阅 @react-native-google-signin/google-signin
文档:
¥See @react-native-google-signin/google-signin
documentation for instructions on how to install and configure the library:
为 Android 和 iOS 配置 Google 项目
¥Configure Google project for Android and iOS
以下是有关如何为 Android 和 iOS 配置 Google 项目的说明。
¥Below are instructions on how to configure your Google project for Android and iOS.
将应用上传到 Google Play 商店
¥Upload app to Google Play Store
如果你的应用打算在生产环境中运行,我们建议将应用上传到 Google Play 商店。即使你的项目仍在开发中,你也可以将你的应用提交到商店进行测试。这允许你在应用通过 EAS 签名进行测试时以及通过 Google Play 应用签名 签名进行商店部署时测试 Google 登录。要了解有关应用提交流程的更多信息,请按指定顺序参阅以下指南:
¥We recommend uploading the app to the Google Play Store if your app intends to run in production. You can submit your app to the stores for testing even if your project is still in development. This allows you to test Google Sign In when your app is signed by EAS for testing, and when it is signed by Google Play App Signing for store deployment. To learn more about the app submission process, see the guides below in the order they are specified:
配置你的 Firebase 或 Google Cloud Console 项目
¥Configure your Firebase or Google Cloud Console project
有关更深入的配置指南,请参阅 库的文档。
¥Refer to the library's documentation for a more in-depth configuration guide.
对于 Android,上传应用后,你需要在 Firebase 或 Google Cloud Console 中配置项目时提供 SHA-1 证书指纹值。你可以提供两种类型的值:
¥For Android, once you have uploaded your app, you need to provide the SHA-1 certificate fingerprint values when asked while configuring the project in Firebase or Google Cloud Console. There are two types of values that you can provide:
-
你构建的 .apk 的指纹(在你的计算机上或使用 EAS Build)。你可以在 Google Play Console 的“发布”>“设置”>“应用完整性”>“上传密钥证书”下找到 SHA-1 证书指纹。
¥Fingerprint of the .apk you built (on your machine or using EAS Build). You can find the SHA-1 certificate fingerprint in the Google Play Console under Release > Setup > App Integrity > Upload key certificate.
-
从 Play 商店下载的生产应用的指纹。你可以在 Google Play 控制台的“发布”>“设置”>“应用完整性”>“应用签名密钥证书”下找到 SHA-1 证书指纹。
¥Fingerprint(s) of a production app downloaded from the play store. You can find the SHA-1 certificate fingerprint(s) in the Google Play Console under Release > Setup > App Integrity > App signing key certificate.
使用 Firebase
¥With Firebase
有关如何使用 Firebase 配置你的 Android 和 iOS 项目的更多说明:
¥For more instructions on how to configure your project for Android and iOS with Firebase:
将 google-services.json 和 GoogleService-Info.plist 上传到 EAS
¥Upload google-services.json and GoogleService-Info.plist to EAS
如果你在 Android 和 iOS 系统中使用 Firebase 方法(如上文所述),则需要确保 google-services.json 和 GoogleService-Info.plist 在 EAS 中可用,以便构建应用。你可以将它们签入到你的代码库中,因为这些文件不应包含敏感值;或者,你可以将这些文件视为密钥信息,将其添加到 .gitignore 文件,然后使用以下指南使其在 EAS 中可用。
¥If you use the Firebase method for Android and iOS (as shared in sections above), you'll need to make sure google-services.json and GoogleService-Info.plist are available in EAS for building the app. You can check them into your repository because the files should not contain sensitive values, or you can treat the files as secrets, add them to .gitignore and use the guide below to make them available in EAS.
使用 Google Cloud Console
¥With Google Cloud Console
这是当你不使用 Firebase 时配置 Google 项目的另一种方法。
¥This is an alternate method to configure a Google project when you are not using Firebase.
有关如何使用 Google Cloud Console 配置你的 Google Android 和 iOS 项目的更多说明:
¥For more instructions on how to configure your Google project Android and iOS with Google Cloud Console: