有关使用 @react-native-google-signin/google-signin 库将 Google 身份验证集成到 Expo 项目中的指南。
@react-native-google-signin/google-signin
库提供了不同的方法(例如 Firebase 和 Google API)来将 Google 身份验证集成到你的 Expo 应用中。它还提供原生登录按钮并支持各种身份验证方法(标准、服务器端验证和离线访问)。你可以通过在 应用配置 中添加 配置插件 来在项目中使用该库。
¥The @react-native-google-signin/google-signin
library provides different ways, such as Firebase and Google API, to integrate Google authentication in your Expo app. It also provides native sign-in buttons and supports various authentication methods (standard, server-side validation, and offline access). You can use the library in your project by adding the config plugin in the app config.
本指南提供了有关如何为你的项目配置库的附加信息,并且根据你选择的身份验证方法,可能需要不同的步骤。
¥This guide provides additional information on how to configure the library for your project, and different steps might be required depending on the authentication method you choose.
¥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:
¥Configure Google project for Android and iOS
以下是有关如何为 Android 和 iOS 配置 Google 项目的说明。
¥Below are instructions on how to configure your Google project for Android and iOS.
¥Upload app to Google Play Store
如果你的应用仍需要投入生产,我们建议你将应用上传到 Google Play 商店。如果你的项目仍处于开发过程中,则无需上传完整的应用。上传应用的单个实例。这将允许你使用所需的证书(例如配置 Android 的 Google 项目时所需的 SHA-1 证书指纹)对你的应用进行签名。要了解有关应用提交流程的更多信息,请按指定顺序参阅以下指南:
¥We recommend uploading the app to the Google Play Store if your app still needs to be in production. It is not necessary to upload the complete app if your project is still in the development process. Upload a single instance of your app. This will allow you to sign your app with the required certificates, such as the SHA-1 certificate fingerprint, which is required when configuring the Google project for Android. To learn more about the app submission process, see the guides below in the order they are specified:
上传应用后,你可以在配置 Google 项目时询问时提供 SHA-1 证书指纹值。你可以提供两个值:
¥Once you have uploaded your app, you can provide an SHA-1 certificate fingerprint value when asked while configuring the Google project. There are two values that you can provide from:
你构建的 .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 Console 的“发布”>“设置”>“应用完整性”>“应用签名密钥证书”下找到 SHA-1 证书指纹。
¥Fingerprint of a production app downloaded from the play store. You can find the SHA-1 certificate fingerprint in the Google Play Console under Release > Setup > App Integrity > App signing key certificate.
¥With Firebase
有关如何使用 Firebase 配置适用于 Android 和 iOS 的 Google 项目的更多说明:
¥For more instructions on how to configure your Google project for Android and iOS with Firebase:
¥Upload google-services.json and GoogleService-Info.plist to EAS
如果你使用适用于 Android 和 iOS 的 Firebase 方法(如上面部分中所共享),则需要将 google-services.json 和 GoogleService-Info.plist 上传到 EAS 并将它们添加到 .gitignore 以避免在存储库中检查它们 。
¥If you use the Firebase method for Android and iOS (as shared in sections above), you'll need to upload google-services.json and GoogleService-Info.plist to EAS and add them to .gitignore to avoid checking them in the repository.
¥With Google API
这是当你不使用 Firebase 时配置 Google 项目的另一种方法。
¥This is an alternate method to configure a Google project when you are not using Firebase.
¥Android
有关如何使用 Google API 配置适用于 Android 的 Google 项目的更多说明:
¥For more instructions on how to configure your Google project for Android with Google API:
¥iOS
对于 iOS,如果你使用 Google API 而不是 Firebase,则需要生成 OAuth 客户端 ID。请按照以下说明生成客户端 ID:
¥For iOS, if you use Google API instead of Firebase, you'll need to generate an OAuth client id. Follow the instructions below to generate the client id:
创建 iOS 客户端 ID 后,你还需要在应用配置中提供 iOS URL 方案值。你可以在 Google API 控制台中的 API 和服务 > 凭据 > OAuth 2.0 客户端 ID > iOS 客户端 ID 名称 > 其他信息 > iOS URL 方案下找到该值。
¥After you have created the iOS client id, you'll also need to provide the iOS URL scheme value in the app config. You can find the value in the Google API console under API and Services > Credentials > OAuth 2.0 Client IDs > name of your iOS client id > Additional information > iOS URL scheme.
然后,在应用配置中的 ios.infoPlist
下添加 iOS URL 方案值,如下所示:
¥Then, add the iOS URL scheme value in the app config under ios.infoPlist
as shown below:
{
"ios": {
%%placeholder-start%%...%%placeholder-end%%
"infoPlist": {
"CFBundleURLTypes": [
{
"CFBundleURLSchemes": ["com.googleusercontent.apps.17898xxxxxx-xxxxxqhqj0exxxxxpl03xxx"]
}
]
}
}
}