使用 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 to 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
请参阅库文档获取更详细的配置指南。
对于 Android,一旦你上传了应用,在使用 Firebase 或 Google Cloud 控制台配置项目时,需要提供 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 控制台的 发布 > 设置 > 应用完整性 > 上传密钥证书 下找到 SHA-1 证书指纹。
- 从 Play 商店下载的生产应用的指纹。你可以在 Google Play 控制台的 发布 > 设置 > 应用完整性 > 应用签名密钥证书 中找到 SHA-1 证书指纹。
使用 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: