Sử dụng tính năng Kiểm tra ứng dụng bằng trình cung cấp gỡ lỗi trong các ứng dụng web
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 App Check, bạn muốn chạy ứng dụng trong một môi trường mà App Check thường không phân loại là hợp lệ, chẳng hạn như cục bộ trong quá trình phát triển hoặc từ môi trường tích hợp liên tục (CI), bạn có thể tạo bản gỡ lỗi của ứng dụng sử dụng trình cung cấp gỡ lỗi App Check thay vì trình cung cấp chứng thực thực.
Sử dụng trình cung cấp gỡ lỗi trên localhost
Để sử dụng trình cung cấp gỡ lỗi trong khi chạy ứng dụng từ localhost (ví dụ: trong quá trình phát triển), hãy làm như sau:
Trong bản gỡ lỗi, hãy bật chế độ gỡ lỗi bằng cách đặt self.FIREBASE_APPCHECK_DEBUG_TOKEN thành true trước khi bạn khởi chạy App Check. Ví dụ:
self.FIREBASE_APPCHECK_DEBUG_TOKEN=true;firebase.appCheck().activate(/* site key or provider */);
Truy cập vào ứng dụng web của bạn trên thiết bị và mở công cụ dành cho nhà phát triển của trình duyệt. Trong bảng điều khiển gỡ lỗi, bạn sẽ thấy một mã gỡ lỗi:
AppCheck debug token: "123a4567-b89c-12d3-e456-789012345678". You will
need to safelist it in the Firebase console for it to work.
Trong phần App Check của bảng điều khiển Firebase, hãy chọn Quản lý mã gỡ lỗi trong trình đơn tràn của ứng dụng. Sau đó, hãy đăng ký mã thông báo gỡ lỗi mà bạn đã đăng nhập ở bước trước.
Sau khi bạn đăng ký mã thông báo, các dịch vụ phụ trợ của Firebase sẽ chấp nhận mã thông báo đó là hợp lệ.
Vì mã thông báo này cho phép truy cập vào các tài nguyên Firebase của bạn mà không cần thiết bị hợp lệ, nên bạn cần phải giữ bí mật mã thông báo này. Đừng cam kết mã thông báo này với một kho lưu trữ công khai và nếu mã thông báo đã đăng ký bị xâm phạm, hãy thu hồi ngay mã thông báo đó trong bảng điều khiển Firebase.
Mã thông báo này được lưu trữ cục bộ trong trình duyệt của bạn và sẽ được dùng bất cứ khi nào bạn sử dụng ứng dụng của mình trong cùng một trình duyệt trên cùng một máy. Nếu bạn muốn sử dụng mã thông báo trong một trình duyệt khác hoặc trên một máy khác, hãy đặt self.FIREBASE_APPCHECK_DEBUG_TOKEN thành chuỗi mã thông báo thay vì true.
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 làm như sau:
Trong phần App Check của bảng điều khiển Firebase, hãy chọn Quản lý mã gỡ lỗi trong trình đơn tràn của ứng dụng. Sau đó, hãy tạo một mã thông báo gỡ lỗi mới. Bạn sẽ cần mã thông báo này trong bước tiếp theo.
Vì mã thông báo này cho phép truy cập vào các tài nguyên Firebase của bạn mà không cần thiết bị hợp lệ, nên bạn cần phải giữ bí mật mã thông báo này. Đừng cam kết mã thông báo này với một kho lưu trữ công khai và nếu mã thông báo đã đăng ký bị xâm phạm, hãy thu hồi ngay mã thông báo đó trong bảng điều khiển 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 được mã hoá của GitHub Actions hoặc biến được 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 một biến môi trường. Đặt tên cho biến, chẳng hạn như APP_CHECK_DEBUG_TOKEN_FROM_CI.
Trong bản gỡ lỗi, hãy bật chế độ gỡ lỗi bằng cách đặt self.FIREBASE_APPCHECK_DEBUG_TOKEN thành giá trị của biến môi trường mã thông báo gỡ lỗi trước khi bạn nhập App Check. Ví dụ:
self.FIREBASE_APPCHECK_DEBUG_TOKEN=process.env.APP_CHECK_DEBUG_TOKEN_FROM_CI;firebase.appCheck().activate(/* site key or provider */);
Khi ứng dụng của bạn chạy trong môi trường CI, các dịch vụ phụ trợ của Firebase sẽ chấp nhận mã thông báo mà ứng dụng gửi dưới dạng mã thông báo hợp lệ.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-30 UTC."],[],[],null,["If, 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 locally 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 a real attestation provider.\n| **Warning:** The debug provider allows access to your Firebase resources from unverified devices. **Don't** use the debug provider in production builds of your app, and **don't** share your debug builds with untrusted parties.\n\nUse the debug provider on localhost\n\nTo use the debug provider while running your app from `localhost` (during\ndevelopment, for example), do the following:\n| **Warning:** *Do not* try to enable `localhost` debugging by adding `localhost` to reCAPTCHA's allowed domains. Doing so would allow anyone to run your app from their local machines!\n\n1. In your debug build, enable debug mode by setting\n `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to `true` before you initialize\n App Check. For example:\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;\n initializeAppCheck(app, { /* App Check options */ });\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;\n firebase.appCheck().activate(/* site key or provider */);\n\n | **Note:** In Firebase Web SDK versions before v9, `self.FIREBASE_APPCHECK_DEBUG_TOKEN` is read at import time, and not at initialization/activation time. This required it to be set in `index.html` before the code bundle is loaded. To avoid this restriction, upgrade to v9.\n2. Visit your web app locally and open the browser's developer tool. In the\n debug console, you'll see a debug token:\n\n ```\n AppCheck debug token: \"123a4567-b89c-12d3-e456-789012345678\". You will\n need to safelist it in the Firebase console for it to work.\n ```\n3. In the [**App Check**](//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, Firebase backend services will accept it as valid.\n\nBecause this token allows access to your Firebase resources 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\nThis token is stored locally in your browser and will be used whenever you use\nyour app in the same browser on the same machine. If you want to use the\ntoken in another browser or on another machine, set\n`self.FIREBASE_APPCHECK_DEBUG_TOKEN` to the token string instead of `true`.\n\nUse the debug provider in a CI environment\n\nTo use the debug provider in a continuous integration (CI) environment, do the following:\n\n1. In the [**App Check**](//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 Firebase resources 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 your debug build, enable debug mode by setting\n `self.FIREBASE_APPCHECK_DEBUG_TOKEN` to the value of the debug token\n environment variable before you import App Check. For example:\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = process.env.APP_CHECK_DEBUG_TOKEN_FROM_CI;\n initializeAppCheck(app, { /* App Check options */ });\n\n Web \n\n self.FIREBASE_APPCHECK_DEBUG_TOKEN = process.env.APP_CHECK_DEBUG_TOKEN_FROM_CI;\n firebase.appCheck().activate(/* site key or provider */);\n\nWhen your app runs in a CI environment, Firebase backend services will accept\nthe token it sends as valid."]]