استخدام App Check لتأمين مفتاح واجهة برمجة التطبيقات
توفّر خدمة فحص التطبيقات من Firebase الحماية للمكالمات من تطبيقك إلى "منصة خرائط Google" من خلال حظر الزيارات الواردة من مصادر أخرى غير التطبيقات المشروعة. ويتم ذلك من خلال البحث عن رمز مميّز من موفّر خدمة إثبات صحة مثل Play Integrity. يساعد دمج تطبيقاتك مع App Check في الحماية من الطلبات الضارة، وبالتالي لن يتم تحصيل رسوم منك مقابل طلبات البيانات غير المصرّح بها من واجهة برمجة التطبيقات.
هل خدمة App Check مناسبة لي؟
ننصح باستخدام App Check في معظم الحالات، ولكن لا حاجة إلى استخدامها أو لا تتوفّر في الحالات التالية:
أنت تستخدم الإصدار الأصلي من Places SDK. تتوفّر خدمة App Check فقط لحزمة تطوير البرامج Places SDK (الجديدة).
التطبيقات الخاصة أو التجريبية إذا لم يكن تطبيقك متاحًا للجميع، لن تحتاج إلى استخدام App Check.
إذا كان تطبيقك يُستخدم فقط من خادم إلى خادم، لن تحتاج إلى App Check. ومع ذلك، إذا كان الخادم الذي يتواصل مع "منصة Google للتسويق" يستخدمه عملاء عامون (مثل تطبيقات الأجهزة الجوّالة)، ننصحك باستخدام App Check لحماية هذا الخادم بدلاً من "منصة Google للتسويق".
لن تعمل جهات توفير الشهادات المقترَحة في App Check على الأجهزة التي تعتبرها جهة توفير الشهادات مخترَقة أو غير موثوق بها. إذا كنت بحاجة إلى توفير الدعم لهذه الأجهزة، يمكنك نشر خدمة إثبات صحة مخصّصة. لمزيد من المعلومات، يُرجى الاطّلاع على التعليمات.
نظرة عامة على خطوات التنفيذ
في ما يلي الخطوات التي يجب اتّباعها لدمج تطبيقك مع App Check:
أضِف Firebase إلى تطبيقك.
أضِف مكتبة App Check واضبطها.
أضِف موفّر الرموز المميزة.
فعِّل تصحيح الأخطاء.
مراقبة طلبات تطبيقك وتحديد إجراءات التنفيذ
بعد الدمج مع App Check، ستتمكّن من الاطّلاع على مقاييس عدد الزيارات إلى الخلفية في وحدة تحكّم Firebase. تقدّم هذه المقاييس تفصيلاً للطلبات حسب ما إذا كانت مصحوبة برمز مميّز صالح من App Check. لمزيد من المعلومات، يمكنك الاطّلاع على مستندات ميزة "فحص التطبيقات من Firebase".
عند التأكّد من أنّ معظم الطلبات واردة من مصادر مشروعة وأنّ المستخدمين قد ثبّتوا أحدث إصدار من تطبيقك يتضمّن عملية تنفيذ App Check، يمكنك تفعيل فرض استخدام الخدمة. بعد تفعيل ميزة فرض الاستخدام، سترفض خدمة App Check جميع الزيارات التي لا تتضمّن رمزًا مميزًا صالحًا من App Check.
اعتبارات عند التخطيط لعملية دمج App Check
في ما يلي بعض الأمور التي يجب وضعها في الاعتبار أثناء التخطيط لعملية الدمج:
تفرض خدمة Play Integrity التي ننصحك بها كخدمة للتحقّق من صحة الشهادات حدًا أقصى يوميًا لعدد الطلبات في فئة حصة الاستخدام العادية لواجهة برمجة التطبيقات.
لمزيد من المعلومات حول حدود عدد المكالمات، يُرجى الاطّلاع على صفحة الإعداد في مستندات المطوّرين الخاصة بخدمة Google Play Integrity.
يمكنك أيضًا اختيار استخدام مقدّم خدمة شهادات مخصّص، ولكنّ هذا خيار متقدّم. لمزيد من المعلومات، اطّلِع على تنفيذ موفّر App Check مخصّص.
سيواجه مستخدمو تطبيقك بعض التأخير عند بدء التشغيل. ومع ذلك، بعد ذلك، سيتم إجراء أي عمليات إعادة إثبات هوية دورية في الخلفية ولن يواجه المستخدمون أي تأخير. يعتمد مقدار وقت الاستجابة الدقيق عند بدء التشغيل على مقدّم خدمة الشهادات الذي تختاره.
يحدّد مقدار الوقت الذي يكون فيه رمز App Check المميّز صالحًا (مدة البقاء أو TTL) معدّل تكرار عمليات إثبات صحة الشهادة. يمكن ضبط هذه المدة في وحدة تحكّم Firebase. تحدث إعادة التصديق عندما ينقضي نصف مدة البقاء على قيد الحياة (TTL) تقريبًا. لمزيد من المعلومات، راجِع مستندات Firebase لمزوّد خدمة التصديق.
دمج تطبيقك مع خدمة App Check
المتطلبات الأساسية ومتطلبات الأهلية
تطبيق تم دمج الإصدار 4.1 أو إصدار أحدث من حزمة تطوير البرامج (SDK) الخاصة بـ Places فيه
الملف المرجعي لشهادة SHA-256 لتطبيقك
اسم حزمة تطبيقك
يجب أن تكون مالك التطبيق في Cloud Console.
ستحتاج إلى رقم تعريف مشروع التطبيق من Cloud Console
إذا أردت تطوير تطبيقك واختباره على جهازك أو تشغيله في بيئة دمج مستمر (CI)، يمكنك إنشاء إصدار تصحيح أخطاء من تطبيقك يستخدم سر تصحيح الأخطاء للحصول على رموز مميّزة صالحة من App Check. يتيح لك ذلك تجنُّب استخدام موفّري خدمات تصديق حقيقيين في إصدار التصحيح.
لتشغيل تطبيقك في محاكي أو على جهاز اختبار، اتّبِع الخطوات التالية:
أضِف مكتبة App Check إلى ملف build.gradle.
اضبط App Check لاستخدام مصنع موفّر تصحيح الأخطاء في إصدار تصحيح الأخطاء.
شغِّل التطبيق، ما سيؤدي إلى إنشاء رمز تصحيح أخطاء محلي. أضِف هذا الرمز المميّز إلى وحدة تحكّم Firebase.
لمزيد من المعلومات والتعليمات، يُرجى الاطّلاع على مستندات App Check.
لتشغيل تطبيقك في بيئة دمج متواصل، اتّبِع الخطوات التالية:
أنشئ رمز تصحيح أخطاء في وحدة تحكّم Firebase وأضِفه إلى مخزن مفاتيح الأمان في نظام التكامل المستمر.
أضِف مكتبة App Check إلى ملف build.gradle.
اضبط صيغة الإصدار في عملية الدمج المتواصل لاستخدام رمز تصحيح الأخطاء.
يمكنك تضمين الرمز في فئات الاختبار التي تحتاج إلى رمز مميّز من App Check باستخدام DebugAppCheckTestHelper.
لمزيد من المعلومات والتعليمات، يُرجى الاطّلاع على مستندات App Check.
الخطوة 5: مراقبة طلبات تطبيقك وتحديد إجراء التنفيذ
قبل البدء في فرض استخدام App Check، عليك التأكّد من أنّك لن تعيق المستخدمين الشرعيين لتطبيقك. ولإجراء ذلك، انتقِل إلى شاشة مقاييس App Check لمعرفة النسبة المئوية لعدد الزيارات التي تم التحقّق منها أو التي انتهت صلاحيتها أو غير الشرعية في تطبيقك. بعد التأكّد من أنّ معظم الزيارات تم التحقّق منها، يمكنك تفعيل ميزة "التنفيذ".
تاريخ التعديل الأخير: 2025-09-04 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-04 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eFirebase App Check protects your Google Maps Platform API key by verifying requests and blocking unauthorized traffic.\u003c/p\u003e\n"],["\u003cp\u003eApp Check is recommended for most apps using Places SDK (New) but is not needed for server-to-server apps, private apps, or those using the original Places SDK.\u003c/p\u003e\n"],["\u003cp\u003eIntegrating App Check involves adding Firebase, initializing the library and a token provider, enabling debugging (optional), and monitoring requests before enforcing token validation.\u003c/p\u003e\n"],["\u003cp\u003ePlay Integrity is the recommended attestation provider; consider daily call limits and latency during initial token fetch.\u003c/p\u003e\n"],["\u003cp\u003eBefore enforcing App Check, ensure most requests are verified using the Firebase console metrics and ensure web service calls in your cloud project use OAuth.\u003c/p\u003e\n"]]],["App Check protects Google Maps Platform API keys by verifying requests originate from legitimate apps. Implementation involves: adding Firebase and the App Check library, initializing App Check, adding a token provider, optionally enabling debugging for testing, and monitoring app request metrics before enabling enforcement. App Check is not needed for the original Places SDK, private apps, or server-to-server communication. Play Integrity is the recommended attestation provider. Enforcement blocks requests without valid tokens.\n"],null,["Select platform: [Android](/maps/documentation/places/android-sdk/app-check \"View this page for the Android platform docs.\") [iOS](/maps/documentation/places/ios-sdk/app-check \"View this page for the iOS platform docs.\") [JavaScript](/maps/documentation/javascript/maps-app-check \"View this page for the JavaScript platform docs.\")\n\n\u003cbr /\u003e\n\nUse 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 [Play Integrity](https://developer.android.com/google/play/integrity). 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- App Check's recommended attestation providers won't work on devices deemed compromised or untrustworthy by your attestation provider. If you need to support such devices, you can deploy a custom attestation service. For more information, see the [instructions](https://firebase.google.com/docs/app-check/android/custom-resource).\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.\n4. Enable debugging.\n5. 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- The attestation provider we recommend, [Play Integrity](https://developer.android.com/google/play/integrity), has a daily call limit for its Standard API usage tier.\n For more information about call limits, see the [Setup](https://developer.android.com/google/play/integrity/setup#increase-daily) page in the Google Play Integrity developer documentation.\n\n You can also choose to use a custom attestation provider, though this is an advanced use case. For more information, see [Implement a custom App Check provider](https://firebase.google.com/docs/app-check/custom-provider).\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 SDK for Android, see [Google Maps Platform support](/maps/support).\n\n### Prerequisites and requirements\n\n- An app with the version 4.1 or later Places SDK integrated.\n- The SHA-256 fingerprint for your app.\n- Your app's package name.\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/android/setup) to add Firebase to your app.\n\n### Step 2: Add the App Check library and initialize App Check\n\nFor information on using Play Integrity, the default attestation provider, see [Get started using App Check with Play Integrity on Android](https://firebase.google.com/docs/app-check/android/play-integrity-provider).\n\n1. If you haven't already, [integrate the Places SDK into your app](/maps/documentation/places/android-sdk/config#places-sdk-for-android).\n2. Next, initialize [App Check](https://firebase.google.com/docs/app-check/android/play-integrity-provider#initialize) and the [Places client](/maps/documentation/places/android-sdk/config#connect-client).\n\n ```java\n // Initialize App Check\n FirebaseApp.initializeApp(/* context= */ this);\n FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();\n firebaseAppCheck.installAppCheckProviderFactory(\n PlayIntegrityAppCheckProviderFactory.getInstance());\n \n // Initialize Places SDK\n Places.initializeWithNewPlacesApiEnabled(context, API_KEY);\n PlacesClient client = Places.createClient(context);.\n ```\n\n### Step 3: Add the token provider\n\n\nAfter initializing the Places API, call `setPlacesAppCheckTokenProvider()` to set the `PlacesAppCheckTokenProvider`. \n\n```java\nPlaces.initializeWithNewPlacesApiEnabled(context, API_KEY);\nPlaces.setPlacesAppCheckTokenProvider(new TokenProvider());\nPlacesClient client = Places.createClient(context);.\n```\n\n\nHere is a sample implementation of the token fetcher interface: \n\n```java\n /** Sample client implementation of App Check token fetcher interface. */\n static class TokenProvider implements PlacesAppCheckTokenProvider {\n @Override\n public ListenableFuture\u003cString\u003e fetchAppCheckToken() {\n SettableFuture\u003cString\u003e future = SettableFuture.create();\n FirebaseAppCheck.getInstance()\n .getAppCheckToken(false)\n .addOnSuccessListener(\n appCheckToken -\u003e {\n future.set(appCheckToken.getToken());\n })\n .addOnFailureListener(\n ex -\u003e {\n future.setException(ex);\n });\n\n return future;\n }\n }\n```\n\n### Step 4: 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 run your app in an emulator or on a test device:\n\n- Add the App Check library to your `build.gradle` file.\n- Configure App Check to use the debug provider factory in your debug build.\n- Launch the app, which will create a local debug token. 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/android/debug-provider#emulator).\n\n\nTo run your app in a CI environment:\n\n- Create a debug token in the Firebase console and add it to your CI system's secure key store.\n- Add the App Check library to your `build.gradle` file.\n- Configure your CI build variant to use the debug token.\n- Wrap code in your test classes that needs an App Check toke with `DebugAppCheckTestHelper`.\n- For more information and instructions, see the [App Check documentation](https://firebase.google.com/docs/app-check/android/debug-provider#ci).\n\n### Step 5: 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)."]]