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.
Sử dụng App Check để bảo mật khoá API
Tính năng Kiểm tra ứng dụng của Firebase giúp bảo vệ các lệnh gọi từ ứng dụng của bạn đến Google Maps Platform bằng cách chặn lưu lượng truy cập đến từ các nguồn không phải là ứng dụng hợp lệ. Việc này được thực hiện bằng cách kiểm tra mã thông báo của một nhà cung cấp chứng thực như reCAPTCHA Enterprise. Việc tích hợp ứng dụng của bạn với tính năng Kiểm tra ứng dụng giúp bảo vệ khỏi các yêu cầu độc hại, nhờ đó bạn không bị tính phí cho các lệnh gọi API trái phép.
Tính năng Kiểm tra ứng dụng có phù hợp với tôi không?
Bạn nên dùng App Check trong hầu hết các trường hợp. Tuy nhiên, bạn không cần hoặc không được hỗ trợ dùng App Check trong các trường hợp sau:
Bạn đang sử dụng Places SDK ban đầu. App Check chỉ được hỗ trợ cho Places SDK (Mới).
Ứng dụng riêng tư hoặc ứng dụng thử nghiệm. Nếu ứng dụng của bạn không truy cập được công khai, thì bạn không cần App Check.
Nếu ứng dụng của bạn chỉ được dùng cho máy chủ với máy chủ, thì bạn không cần App Check. Tuy nhiên, nếu máy chủ giao tiếp với GMP được dùng bởi các ứng dụng công khai (chẳng hạn như ứng dụng di động), hãy cân nhắc sử dụng App Check để bảo vệ máy chủ đó thay vì GMP.
Tổng quan về các bước triển khai
Nhìn chung, đây là các bước bạn sẽ thực hiện để tích hợp ứng dụng của mình với App Check:
Thêm Firebase vào ứng dụng của bạn.
Thêm và khởi chạy thư viện Kiểm tra ứng dụng.
Thêm nhà cung cấp mã thông báo vào ứng dụng của bạn.
Khởi chạy API Địa điểm và API Kiểm tra ứng dụng.
Bật tính năng gỡ lỗi.
Giám sát các yêu cầu của ứng dụng và quyết định thực thi.
Sau khi tích hợp với tính năng Kiểm tra ứng dụng, bạn sẽ có thể xem các chỉ số lưu lượng truy cập phụ trợ trên bảng điều khiển của Firebase. Các chỉ số này cung cấp thông tin chi tiết về các yêu cầu theo việc yêu cầu đó có đi kèm với mã thông báo App Check hợp lệ hay không. Hãy xem tài liệu về tính năng Kiểm tra ứng dụng của Firebase để biết thêm thông tin.
Khi chắc chắn rằng hầu hết các yêu cầu đều đến từ các nguồn hợp lệ và người dùng đã cập nhật lên phiên bản mới nhất của ứng dụng (có bao gồm việc triển khai App Check), bạn có thể bật chế độ thực thi. Sau khi bạn bật chế độ thực thi, App Check sẽ từ chối tất cả lưu lượng truy cập không có mã thông báo App Check hợp lệ.
Những điều cần cân nhắc khi lên kế hoạch tích hợp App Check
Sau đây là một số điều cần cân nhắc khi bạn lên kế hoạch tích hợp:
Một trong những nhà cung cấp chứng thực mà chúng tôi đề xuất là reCAPTCHA Enterprise. Nhà cung cấp này tính phí cho hơn 10.000 lượt đánh giá mỗi tháng.
Nhà cung cấp chứng thực khác mà chúng tôi đề xuất là reCAPTCHA v3. Nhà cung cấp này có hạn mức, sau đó lưu lượng truy cập sẽ không được đánh giá.
Bạn có thể chọn sử dụng một nhà cung cấp chứng thực tuỳ chỉnh, mặc dù đây là một trường hợp sử dụng nâng cao. Hãy xem tài liệu về App Check để biết thêm thông tin.
Người dùng ứng dụng của bạn sẽ gặp phải một số độ trễ khi khởi động. Tuy nhiên, sau đó, mọi quy trình chứng thực lại định kỳ sẽ diễn ra trong nền và người dùng sẽ không còn gặp phải bất kỳ độ trễ nào nữa. Độ trễ chính xác khi khởi động phụ thuộc vào nhà cung cấp chứng thực mà bạn chọn.
Khoảng thời gian mà mã thông báo App Check có hiệu lực (thời gian tồn tại hoặc TTL) xác định tần suất chứng thực lại. Bạn có thể định cấu hình khoảng thời gian này trong bảng điều khiển của Firebase. Quy trình chứng thực lại xảy ra khi khoảng một nửa thời gian TTL đã trôi qua. Để biết thêm thông tin, hãy xem tài liệu của Firebase cho trình chứng thực của bạn.
Bước 2: Thêm thư viện Kiểm tra ứng dụng và khởi chạy Kiểm tra ứng dụng
Firebase cung cấp hướng dẫn cho từng trình chứng thực mặc định. Các hướng dẫn này cho bạn biết cách thiết lập một dự án Firebase và thêm thư viện App Check vào ứng dụng của bạn. Hãy làm theo các mẫu mã được cung cấp để khởi chạy App Check.
Đảm bảo rằng các yêu cầu đến Maps JS API đi kèm với mã thông báo của tính năng Kiểm tra ứng dụng:
asyncfunctioninit(){const{Settings}=awaitgoogle.maps.importLibrary('core');const{Map}=awaitgoogle.maps.importLibrary('maps');const{Place}=awaitgoogle.maps.importLibrary('places');constapp=initializeApp({// Your firebase configuration object});// Pass your reCAPTCHA Enterprise site key to initializeAppCheck().constappCheck=initializeAppCheck(app,{provider:newReCaptchaEnterpriseProvider('abcdefghijklmnopqrstuvwxy-1234567890abcd',),// Optional argument. If true, the SDK automatically refreshes App Check// tokens as needed.isTokenAutoRefreshEnabled:true,});Settings.getInstance().fetchAppCheckToken=()=>
getToken(appCheck,/* forceRefresh = */false);// Make a Places JS requestconstplace=newPlace({id:'ChIJN5Nz71W3j4ARhx5bwpTQEGg'});awaitplace.fetchFields({fields:['*']});// Load a mapmap=newMap(document.getElementById("map"),{center:{lat:37.4161493,lng:-122.0812166},zoom:8,});}
Bước 5: Bật chế độ gỡ lỗi (không bắt buộc)
Nếu muốn phát triển và kiểm thử ứng dụng cục bộ hoặc chạy ứng dụng trong môi trường 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 một khoá bí mật gỡ lỗi để lấy mã thông báo App Check hợp lệ. Điều này giúp bạn tránh sử dụng trình cung cấp chứng thực thực trong bản gỡ lỗi.
Cách kiểm thử ứng dụng cục bộ:
Kích hoạt trình cung cấp gỡ lỗi cho mục đích phát triển.
Bạn sẽ nhận được một UUID4 ngẫu nhiên được tạo tự động (gọi là _mã gỡ lỗi_ trong tài liệu App Check) từ nhật ký gỡ lỗi của SDK. Thêm mã thông báo này vào bảng điều khiển của Firebase.
Bước 6: Giám sát các yêu cầu của ứng dụng và quyết định về việc thực thi
Trước khi bắt đầu thực thi, bạn cần đảm bảo rằng bạn sẽ không làm gián đoạn người dùng hợp pháp của ứng dụng. Để làm việc này, hãy truy cập vào màn hình chỉ số App Check để xem tỷ lệ phần trăm lưu lượng truy cập của ứng dụng được xác minh, đã lỗi thời hoặc không hợp pháp. Sau khi thấy rằng phần lớn lưu lượng truy cập của bạn đã được xác minh, bạn có thể bật chế độ thực thi.
[[["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-27 UTC."],[[["\u003cp\u003eFirebase App Check protects your Google Maps Platform API key by verifying app requests and blocking unauthorized traffic.\u003c/p\u003e\n"],["\u003cp\u003eApp Check integrates with attestation providers like reCAPTCHA Enterprise to validate requests, reducing fraudulent API usage and associated costs.\u003c/p\u003e\n"],["\u003cp\u003eImplementation involves adding Firebase and App Check libraries, initializing them, and enabling App Check for the Places API.\u003c/p\u003e\n"],["\u003cp\u003eYou should monitor App Check metrics in the Firebase console and enable enforcement after confirming most traffic is verified to block unverified requests.\u003c/p\u003e\n"],["\u003cp\u003ereCAPTCHA Enterprise charges beyond 10,000 assessments/month, reCAPTCHA v3 has usage quotas, and custom attestation is an advanced option.\u003c/p\u003e\n"]]],[],null,["Use App Check to secure your API key\n====================================\n\n\n[Firebase App Check](https://firebase.google.com/docs/app-check) provides protection for calls from your app to Google Maps Platform by blocking traffic that comes from sources other than legitimate apps. It does this by checking for a token from an attestation provider like [reCAPTCHA Enterprise](https://cloud.google.com/recaptcha-enterprise). Integrating your apps with App Check helps to protect against malicious requests, so you're not charged for unauthorized API calls.\n\nIs App Check right for me?\n--------------------------\n\n\nApp Check is recommended in most cases, however App Check is not needed or is not supported in the following cases:\n\n- You are using the original Places SDK. **App Check is only supported for Places SDK (New)**.\n- Private or experimental apps. If your app is not publicly accessible, App Check is not needed.\n- If your app is only used server-to-server, App Check is not needed. However, if the server that communicates with GMP is used by public clients (such as mobile apps), consider [using App Check to protect that server](https://firebase.google.com/docs/app-check/custom-resource-backend) instead of GMP.\n\nOverview of implementation steps\n--------------------------------\n\nAt a high level, these are the steps you'll follow to integrate your app with App Check:\n\n1. Add Firebase to your app.\n2. Add and initialize the App Check library.\n3. Add the token provider to your app.\n4. Initialize the Places and App Check APIs.\n5. Enable debugging.\n6. Monitor your app requests and decide on enforcement.\n\n\nOnce you've integrated with App Check, you'll be able to see backend traffic metrics on the Firebase console. These metrics provide breakdown of requests by whether they are accompanied by a valid App Check token. See the [Firebase App Check documentation](https://firebase.google.com/docs/app-check/monitor-metrics) for more information.\n\n\nWhen you're sure that most requests are from legitimate sources and that users have updated to the latest version of your app that includes your implementation of App Check, you can turn on enforcement. Once enforcement is on, App Check will reject all traffic without a valid App Check token.\n| **Note:** App check enforcement is not turned on by default.\n\nConsiderations when planning an App Check integration\n-----------------------------------------------------\n\n\nHere are some things to consider as you plan your integration:\n\n- One of the attestation providers we recommend, [reCAPTCHA Enterprise](https://cloud.google.com/recaptcha-enterprise) charges for more than 10,000 assessments per month.\n\n The other attestation provider we recommend, [reCAPTCHA v3](/recaptcha/docs/v3) has a quota, after which traffic won't be evaluated.\n\n You can choose to use a custom attestation provider, though this is an advanced use case. See the [App Check documentation](https://firebase.google.com/docs/app-check/custom-provider) for more information.\n- Users of your app will experience some latency on startup. However, afterwards, any periodic re-attestation will occur in the background and users should no longer experience any latency. The exact amount of latency at startup depends on the attestation provider you choose.\n\n The amount of time that the App Check token is valid (the *time to live* , or TTL) determines the frequency of re-attestations. This duration can be configured in the Firebase console. Re-attestation occurs when approximately halkf of the TTL has elapsed. For more information, see the [Firebase docs](https://firebase.google.com/docs/app-check#get_started) for your attestation provider.\n\nIntegrate your app with App Check\n---------------------------------\n\n| Note: Get help faster! For support regarding the Firebase-related portions of this process, see [Firebase support](https://firebase.google.com/support). For support regarding the Google Places API, see [Google Maps Platform support](/maps/support).\n\n### Prerequisites and requirements\n\n- An app with the [the latest weekly or quarterly version of the Maps JS API](/maps/documentation/javascript/versions), Core, and Places libraries loaded.\n- A Cloud project with the Maps JS and the Places API (New) APIs enabled.\n- You must be the owner of the app in Cloud Console.\n- You will need the app's project ID from the Cloud Console\n\n### Step 1: Add Firebase to your app\n\n\nFollow [the instructions in the Firebase developer documentation](https://firebase.google.com/docs/web/setup) to add Firebase to your app.\n\n\n### Step 2: Add the App Check library and initialize App Check\n\nFirebase provides instructions for each default attestation provider. These instructions show you how to set up a Firebase project and add the App Check library to your app. Follow the code samples provided to initialize App Check.\n\n- [Instructions for reCAPTCHA Enterprise](https://firebase.google.com/docs/app-check/web/recaptcha-enterprise-provider).\n- [Instructions for reCAPTCHA v3](https://firebase.google.com/docs/app-check/web/recaptcha-provider).\n\n | You must register your site for reCAPTCHA v3 and get your reCAPTCHA v3 site key and secret key using the reCAPTCHA site registration tool before you enable the API on the Cloud Console. See the [reCAPTCHA v3 documentation](/recaptcha/intro) for more information and instructions.\n\n### Step 3: Load Maps JS API libraries\n\n1. Load the core, Maps, and Places libraries as shown in the following snippet. For more information and instructions, see the [Maps JavaScript API Place Class documentation](/maps/documentation/javascript/place-get-started#load-the-places-library).\n\n ```javascript\n async function init() {\n const {Settings} = await google.maps.importLibrary('core');\n const {Map} = await google.maps.importLibrary('maps');\n const {Place} = await google.maps.importLibrary('places');\n } \n ```\n\n### Step 4: Initialize the Places and App Check APIs\n\n1. Initialize App Check using the config provided by the Firebase console.\n - [reCAPTCHA v3 instructions](https://firebase.google.com/docs/app-check/web/recaptcha-provider).\n - [reCAPTCHA Enterprise instructions.](https://firebase.google.com/docs/app-check/web/recaptcha-enterprise-provider)\n2. Ensure that requests to the Maps JS API are accompanied by App Check tokens: \n\n ```javascript\n async function init() {\n const {Settings} = await google.maps.importLibrary('core');\n const {Map} = await google.maps.importLibrary('maps');\n const {Place} = await google.maps.importLibrary('places');\n \n const app = initializeApp({\n // Your firebase configuration object\n });\n \n // Pass your reCAPTCHA Enterprise site key to initializeAppCheck().\n const appCheck = initializeAppCheck(app, {\n provider: new ReCaptchaEnterpriseProvider(\n 'abcdefghijklmnopqrstuvwxy-1234567890abcd',\n ),\n \n // Optional argument. If true, the SDK automatically refreshes App Check\n // tokens as needed.\n isTokenAutoRefreshEnabled: true,\n });\n \n Settings.getInstance().fetchAppCheckToken = () =\u003e\n getToken(appCheck, /* forceRefresh = */ false);\n \n // Make a Places JS request\n const place = new Place({id: 'ChIJN5Nz71W3j4ARhx5bwpTQEGg'});\n await place.fetchFields({fields: ['*']});\n \n // Load a map\n map = new Map(document.getElementById(\"map\"), {\n center: { lat: 37.4161493, lng: -122.0812166 },\n zoom: 8,\n });\n } \n \n ```\n\n### Step 5: Enable debugging (optional)\n\nIf you'd like to develop and test your app locally, or run it in a continuous integration (CI) environment, you can create a debug build of your app that uses a debug secret to obtain valid App Check tokens. This lets you avoid using real attestation providers in your debug build.\n\nTo test your app locally:\n\n- Activate the debug provider for development purposes.\n- You will receive an automatically generated random UUID4 (called the _debug token_ in the App Check documentation) from the SDK's debug logs. Add this token to the Firebase console.\n- For more information and instructions, see the [App Check documentation](https://firebase.google.com/docs/app-check/web/debug-provider#localhost).\n\nTo run your app in a CI environment:\n\n- Generate a random UUID4 from the Firebase console.\n- Add the UUID4 as a debug token, and then copy it into a secret store that the CI tests will access per test run.\n- For more information and instructions, see the [App Check documentation](https://firebase.google.com/docs/app-check/web/debug-provider#ci).\n\n### Step 6: Monitor your app requests and decide on enforcement\n\n\nBefore you begin enforcement, you'll want to make sure that you won't disrupt legitimate users of your app. To do this, visit the App Check metrics screen to see what percentage of your app's traffic is verified, outdated, or illegitimate. Once you see that the majority of your traffic is verified, you can enable enforcement.\n\n\nSee the [Firebase App Check documentation](https://firebase.google.com/docs/app-check/monitor-metrics) for more information and instructions.\n| Before you enforce App Check, make sure any Web Service calls in your Cloud project use [OAuth](/maps/documentation/places/web-service/oauth-token)."]]