Quan trọng: Kể từ ngày 1 tháng 5 năm 2024, Apple cần có Tệp kê khai quyền riêng tư và chữ ký đối với những ứng dụng iOS sử dụng SDK thường dùng, bao gồm cả GoogleSignIn-iOS. Nâng cấp GoogleSignIn-iOS phiên bản 7.1.0 trở lên trước ngày 1 tháng 5 năm 2024. Làm theo hướng dẫn nâng cấp của chúng tôi.
Sử dụng tính năng Kiểm tra ứng dụng thông qua trình cung cấp gỡ lỗi
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Nếu sau khi đăng ký ứng dụng cho tính năng Kiểm tra ứng dụng, bạn muốn chạy
ứng dụng trong một môi trường mà tính năng Kiểm tra ứng dụng thường không phân loại là hợp lệ,
chẳng hạn như trình mô phỏng trong quá trình phát triển hoặc từ quá trình tích hợp liên tục (CI)
bạn có thể tạo một bản gỡ lỗi của ứng dụng sử dụng
Trình cung cấp dịch vụ gỡ lỗi Kiểm tra ứng dụng thay vì Kiểm thử ứng dụng.
Sử dụng trình cung cấp gỡ lỗi trong trình mô phỏng
Sử dụng trình cung cấp gỡ lỗi khi chạy ứng dụng trong trình mô phỏng theo cách tương tác
(ví dụ: trong quá trình phát triển), hãy làm như sau:
Tra cứu khoá API iOS cho dự án của bạn trên phần Thông tin xác thực
trang về API & Dịch vụ trong bảng điều khiển Google Cloud.
Trong bản gỡ lỗi, hãy định cấu hình tính năng Kiểm tra ứng dụng để sử dụng trình cung cấp gỡ lỗi. Bạn sẽ
cần chỉ định khoá API bạn có ở bước trước.
#iftargetEnvironment(simulator)GIDSignIn.sharedInstance.configureDebugProvider(withAPIKey:apiKey){errorinifleterror{print("Error configuring `GIDSignIn` for App Check: \(error)")}}#else// Configure App Check for production.#endif
Khởi chạy ứng dụng. Mã gỡ lỗi cục bộ sẽ được ghi vào bảng điều khiển Xcode khi
SDK sẽ cố gắng gửi một yêu cầu đến phần phụ trợ. Ví dụ:
Trong phần Kiểm tra ứng dụng
trong bảng điều khiển của Firebase, hãy chọn Quản lý mã gỡ lỗi từ
trình đơn mục bổ sung. Sau đó, hãy đăng ký mã gỡ lỗi mà bạn đã ghi vào trước đó
.
Sau khi bạn đăng ký mã thông báo, các điểm cuối OAuth 2.0 của Google sẽ chấp nhận mã đó là
cho dự án của bạn.
Vì mã thông báo này cho phép truy cập vào điểm cuối xác thực của bạn mà không cần
thiết bị hợp lệ, điều quan trọng là bạn phải bảo mật thông tin đó. Không cam kết
kho lưu trữ công khai và nếu một mã thông báo đã đăng ký bị xâm phạm, hãy thu hồi mã đó
ngay trong bảng điều khiển của Firebase.
Sử dụng trình cung cấp gỡ lỗi trong môi trường CI
Để sử dụng trình cung cấp gỡ lỗi trong môi trường tích hợp liên tục (CI), hãy thực hiện
sau:
Trong phần Kiểm tra ứng dụng
trong bảng điều khiển của Firebase, hãy chọn Quản lý mã gỡ lỗi từ
trình đơn mục bổ sung. Sau đó, hãy tạo một mã gỡ lỗi mới. Bạn sẽ cần mã thông báo trong
bước tiếp theo.
Vì mã thông báo này cho phép truy cập vào điểm cuối xác thực của bạn mà không cần
một thiết bị hợp lệ, điều quan trọng là bạn phải bảo mật thông tin đó. Không cam kết
kho lưu trữ công khai và nếu một mã thông báo đã đăng ký bị xâm phạm, hãy thu hồi mã đó
ngay trong bảng điều khiển của Firebase.
Thêm mã gỡ lỗi mà bạn vừa tạo vào kho khoá bảo mật của hệ thống CI
(ví dụ: bí mật đã mã hoá của GitHub Actions
hoặc biến đã mã hoá của Travis CI).
Nếu cần, hãy định cấu hình hệ thống CI để cung cấp mã gỡ lỗi
trong môi trường CI dưới dạng biến môi trường. Đặt tên cho biến
chẳng hạn như APP_CHECK_DEBUG_TOKEN_FROM_CI.
Trong Xcode, hãy thêm một biến môi trường vào lược đồ thử nghiệm của bạn bằng tên
FIRAAppCheckDebugToken và một số tham số tương tự như $(APP_CHECK_DEBUG_TOKEN)
giá trị đó.
Định cấu hình tập lệnh thử nghiệm CI để truyền mã gỡ lỗi dưới dạng một môi trường
biến. Ví dụ:
xcodebuild test -scheme YourTestScheme -workspace YourProject.xcworkspace \
APP_CHECK_DEBUG_TOKEN=$(APP_CHECK_DEBUG_TOKEN_FROM_CI)
Tra cứu khoá API iOS cho dự án của bạn trên phần Thông tin xác thực
trang về API & Dịch vụ trong bảng điều khiển Google Cloud.
Trong bản gỡ lỗi, hãy định cấu hình tính năng Kiểm tra ứng dụng để sử dụng trình cung cấp gỡ lỗi. Bạn sẽ
cần chỉ định khoá API bạn có ở bước trước.
#iftargetEnvironment(simulator)GIDSignIn.sharedInstance.configureDebugProvider(withAPIKey:apiKey){errorinifleterror{print("Error configuring `GIDSignIn` for App Check: \(error)")}}#else// Configure App Check for production.#endif
Khi ứng dụng của bạn chạy trong môi trường CI, các điểm cuối OAuth 2.0 của Google sẽ chấp nhận
mã thông báo mà mã đó gửi là hợp lệ cho dự án của bạn.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[[["\u003cp\u003eThe App Check debug provider enables app functionality in test environments like simulators and CI, bypassing the usual App Check verifications.\u003c/p\u003e\n"],["\u003cp\u003eFor simulator use, configure your debug build with the debug provider, obtain a debug token from the Xcode console, and register it in the Firebase console.\u003c/p\u003e\n"],["\u003cp\u003eWhen using the debug provider in a CI environment, create a debug token in the Firebase console, store it securely in your CI system, and configure your CI test script to use it.\u003c/p\u003e\n"],["\u003cp\u003e\u003cstrong\u003eImportant:\u003c/strong\u003e The debug provider bypasses security measures; therefore, debug tokens should be kept confidential and never used in production builds.\u003c/p\u003e\n"]]],[],null,["# Use App Check with the debug provider\n\nIf, after you have registered your app for App Check, you want to run your\napp in an environment that App Check would normally not classify as valid,\nsuch as a simulator during development, or from a continuous integration (CI)\nenvironment, you can create a debug build of your app that uses the\nApp Check debug provider instead of App Attest.\n\n\u003cbr /\u003e\n\n| **Firebase users**: You must follow the steps on this page to configure Google Sign-in to use the App Check debug provider, even if you've already configured Firebase services to use the App Check debug provider.\n\n\u003cbr /\u003e\n\n| **Warning:** The debug provider allows access to your project's auth endpoints from unverified devices. **Don't** use the debug provider in production builds of your app, and be careful not to leak your debug token.\n\nUse the debug provider in a simulator\n-------------------------------------\n\nTo use the debug provider while running your app in a simulator interactively\n(during development, for example), do the following:\n\n1. Look up the iOS API key for your project on the [Credentials](https://console.cloud.google.com/apis/credentials?project=_)\n page of the **APIs \\& Services** section of the Google Cloud console.\n\n2. In your debug build, configure App Check to use the debug provider. You'll\n need to specify the API key you got in the previous step.\n\n #if targetEnvironment(simulator)\n GIDSignIn.sharedInstance.configureDebugProvider(withAPIKey: apiKey) { error in\n if let error {\n print(\"Error configuring `GIDSignIn` for App Check: \\(error)\")\n }\n }\n #else\n // Configure App Check for production.\n #endif\n\n3. Launch the app. A local debug token will be logged to the Xcode console when\n the SDK tries to send a request to the backend. For example:\n\n \u003cWarning\u003e [AppCheckCore][I-GAC004001] App Check debug token:\n '123a4567-b89c-12d3-e456-789012345678'.\n\n4. In the [App Check](https://console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, register the debug token you logged in the previous\n step.\n\nAfter you register the token, Google's OAuth 2.0 endpoints will accept it as\nvalid for your project.\n\nBecause this token allows access to your auth endpoints without a\nvalid device, it is crucial that you keep it private. Don't commit it to a\npublic repository, and if a registered token is ever compromised, revoke it\nimmediately in the Firebase console.\n\nUse the debug provider in a CI environment\n------------------------------------------\n\nTo use the debug provider in a continuous integration (CI) environment, do the\nfollowing:\n\n1. In the [App Check](https://console.firebase.google.com/project/_/appcheck) section\n of the Firebase console, choose **Manage debug tokens** from your app's\n overflow menu. Then, create a new debug token. You'll need the token in the\n next step.\n\n Because this token allows access to your auth endpoints without\n a valid device, it is crucial that you keep it private. Don't commit it to a\n public repository, and if a registered token is ever compromised, revoke it\n immediately in the Firebase console.\n\n2. Add the debug token you just created to your CI system's secure key store\n (for example, GitHub Actions' [encrypted secrets](https://docs.github.com/en/actions/reference/encrypted-secrets)\n or Travis CI's [encrypted variables](https://docs.travis-ci.com/user/environment-variables/#defining-encrypted-variables-in-travisyml)).\n\n3. If necessary, configure your CI system to make your debug token available\n within the CI environment as an environment variable. Name the variable\n something like `APP_CHECK_DEBUG_TOKEN_FROM_CI`.\n\n4. In Xcode, add an environment variable to your testing scheme with the name\n `FIRAAppCheckDebugToken` and something like `$(APP_CHECK_DEBUG_TOKEN)` as\n the value.\n\n5. Configure your CI test script to pass the debug token as an environment\n variable. For example:\n\n ```\n xcodebuild test -scheme YourTestScheme -workspace YourProject.xcworkspace \\\n APP_CHECK_DEBUG_TOKEN=$(APP_CHECK_DEBUG_TOKEN_FROM_CI)\n ```\n6. Look up the iOS API key for your project on the [Credentials](https://console.cloud.google.com/apis/credentials?project=_)\n page of the **APIs \\& Services** section of the Google Cloud console.\n\n7. In your debug build, configure App Check to use the debug provider. You'll\n need to specify the API key you got in the previous step.\n\n #if targetEnvironment(simulator)\n GIDSignIn.sharedInstance.configureDebugProvider(withAPIKey: apiKey) { error in\n if let error {\n print(\"Error configuring `GIDSignIn` for App Check: \\(error)\")\n }\n }\n #else\n // Configure App Check for production.\n #endif\n\nWhen your app runs in a CI environment, Google's OAuth 2.0 endpoints will accept\nthe token it sends as valid for your project."]]