حماية بيانات اعتماد السحابة الإلكترونية لتطبيق Firebase ML Apple
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
إذا كان تطبيق Apple يستخدم إحدى واجهات برمجة التطبيقات السحابية الخاصة بـ Firebase ML، عليك اتّخاذ بعض الخطوات الإضافية قبل إطلاق تطبيقك في مرحلة الإنتاج لمنع الوصول غير المصرّح به إلى واجهة برمجة التطبيقات.
1. تقليل نطاق مفاتيح واجهة برمجة التطبيقات الحالية
أولاً، اضبط مفاتيح واجهة برمجة التطبيقات الحالية لرفض الوصول إلى Cloud Vision API باتّباع الخطوات التالية:
افتح صفحة بيانات الاعتماد في
Google Cloud. اختَر مشروعك عندما يُطلب منك ذلك.
بالنسبة إلى كل مفتاح حالي لواجهة برمجة التطبيقات في القائمة، افتح طريقة عرض التعديل.
في قسم قيود واجهة برمجة التطبيقات، انقر على تقييد المفتاح، ثم أضِف إلى القائمة جميع واجهات برمجة التطبيقات التي تريد أن يتمكّن مفتاح واجهة برمجة التطبيقات من الوصول إليها. احرص على عدم تضمين Cloud Vision API.
عند ضبط قيود واجهة برمجة التطبيقات لمفتاح واجهة برمجة التطبيقات، فإنّك تحدّد بشكل صريح واجهات برمجة التطبيقات التي يمكن للمفتاح الوصول إليها. تلقائيًا، عندما يكون الخيار عدم تقييد المفتاح محدّدًا في قسم قيود واجهة برمجة التطبيقات، يمكن استخدام مفتاح واجهة برمجة التطبيقات للوصول إلى أي واجهة برمجة تطبيقات مفعَّلة للمشروع.
لن تمنح مفاتيح واجهة برمجة التطبيقات الحالية إذن الوصول إلى خدمات تعلُّم الآلة على السحابة الإلكترونية، ولكن سيستمر عمل كل مفتاح مع أي واجهات برمجة تطبيقات أضفتها إلى قائمة قيود واجهة برمجة التطبيقات.
يُرجى العِلم أنّه في حال تفعيل أي واجهات برمجة تطبيقات إضافية في المستقبل، عليك إضافتها إلى قائمة القيود المفروضة على واجهة برمجة التطبيقات لمفتاح واجهة برمجة التطبيقات المعنيّ.
2- إنشاء مفتاح واجهة برمجة تطبيقات جديد لاستخدامه مع Firebase ML
بعد ذلك، أنشئ مفتاح واجهة برمجة تطبيقات جديدًا لـ Firebase ML لا يسمح إلا بإجراء طلبات إلى Cloud Vision API:
ارجع إلى صفحة بيانات الاعتماد. تأكَّد من أنّ مشروعك على Firebase لا يزال محدّدًا.
انقر على إنشاء بيانات اعتماد > مفتاح API. دوِّن مفتاح واجهة برمجة التطبيقات الجديد، ثم انقر على تقييد المفتاح.
في قسم قيود واجهة برمجة التطبيقات، انقر على فرض قيود على المفتاح، ثم أضِف فقط Cloud Vision API إلى القائمة.
يمنح مفتاح واجهة برمجة التطبيقات هذا إذن الوصول إلى Cloud Vision API فقط، ويمكن أن يستخدمه
Firebase ML للوصول إلى النماذج المستندة إلى السحابة الإلكترونية.
3- إجراء يُنصح به: تقليل حصة Cloud Vision API
للمساعدة في الحدّ من عواقب اختراق المفتاح، عليك خفض حصة Cloud Vision API المخصّصة لكل مستخدم من الإعداد التلقائي. ولإجراء ذلك، يُرجى اتّباع الخطوات التالية:
افتح صفحة حصص Cloud Vision API في وحدة تحكّم Google Cloud. اختَر مشروعك عندما يُطلب منك ذلك.
في قسم الطلبات، اضبط حصة الطلبات في الدقيقة لكل مستخدم على قيمة معقولة لتطبيقك. على سبيل المثال، إذا كان تطبيقك يتضمّن تحميل صورة لمستند لاسترداد النص منه، من غير المحتمل أن ينفّذ المستخدم هذا الإجراء أكثر من مرة كل بضع ثوانٍ، لذا من المحتمل أن تكون الحصة البالغة 30 إلى 40 طلبًا آمنة.
يُرجى العِلم أنّ "الطلبات لكل مستخدم" في هذا السياق تشير إلى الطلبات الواردة من عنوان IP واحد. قد تحتاج إلى أخذ ذلك في الاعتبار إذا كنت تتوقّع أن يستخدم العديد من المستخدمين تطبيقك في الوقت نفسه من خلال NAT.
4. استدعاء واجهات برمجة التطبيقات على السحابة الإلكترونية باستخدام مفتاح واجهة برمجة التطبيقات Firebase ML
أخيرًا، في تطبيقك، اضبط Firebase ML لاستخدام مفتاح واجهة برمجة التطبيقات الجديد.
بما أنّ مفتاح واجهة برمجة التطبيقات Firebase ML يتيح الوصول غير المصادق عليه إلى Cloud Vision API، من المهم الحفاظ على سرية المفتاح لمنع الاستخدام غير المصرَّح به والرسوم في حساب الفوترة. لإجراء ذلك، عليك تجنُّب تضمين مفتاح واجهة برمجة التطبيقات في البرنامج الثنائي لتطبيقك. بدلاً من ذلك، تحقَّق أثناء تشغيل التطبيق من أنّ مستخدمًا معروفًا وموثوقًا به قد سجّل الدخول، ثم استردِد مفتاح واجهة برمجة التطبيقات من الخادم.
حتى عند اتّباع هذه الممارسات، من المحتمل أن يتم اختراق مفتاح واجهة برمجة التطبيقات. عليك اتّخاذ خطوات للمساعدة في الحدّ من عواقب المفتاح المخترَق، مثل تقليل الحصة المخصّصة لكل مستخدم في واجهة برمجة التطبيقات كما هو موضّح أعلاه، وتنفيذ سياسات تغيير المفاتيح، وإصدار مفاتيح مختلفة لمجموعات مختلفة من المستخدمين.
بعد أن يحصل تطبيقك على مفتاح واجهة برمجة التطبيقات بشكل آمن، يمكنك تحديد المفتاح عند استدعاء إحدى
Firebase ML واجهات Cloud API:
Swift
ifletcloudVisionKey=getYourApiKey(){// See note above about securing your API keyletoptions=VisionCloudDetectorOptions()options.apiKeyOverride=cloudVisionKeyletcloudDetector=Vision.vision().cloudLandmarkDetector(options:options)}
Objective-C
NSString*cloudVisionKey=[selfgetYourApiKey];// See note above about securing your API keyif(cloudVisionKey!=nil){FIRVisionCloudDetectorOptions*options=[[FIRVisionCloudDetectorOptionsalloc]init];options.APIKeyOverride=cloudVisionKey;FIRVisionCloudLandmarkDetector*landmarkDetector=[visioncloudLandmarkDetectorWithOptions:options];}
تاريخ التعديل الأخير: 2025-07-25 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","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-07-25 (حسب التوقيت العالمي المتفَّق عليه)"],[],[],null,["\u003cbr /\u003e\n\nIf your Apple app uses one of Firebase ML's cloud APIs, before you launch your app\nin production, you should take some additional steps to prevent unauthorized\nAPI access.\n\n1. Reduce the scope of existing API keys\n\nFirst, configure your existing API keys to disallow access to the Cloud Vision\nAPI:\n\n1. Open the [Credentials](https://console.cloud.google.com/apis/credentials?project=_) page of the\n Google Cloud console. When prompted, select your project.\n\n2. For each existing API key in the list, open the editing view.\n\n3. In the *API restrictions* section, select **Restrict key** , then add to the\n list all of the APIs to which you want the API key to have access. Make sure\n to ***not*** include the Cloud Vision API.\n\n When you configure an API key's *API restrictions* , you are explicitly\n declaring the APIs to which the key has access. **By default, when the *API\n restrictions* section has *Don't restrict key* selected, an API key can be\n used to access any API that is enabled for the project.**\n\nNow, your existing API keys will not grant access to cloud ML services, but each\nkey will continue to work for any APIs that you added to its *API restrictions*\nlist.\n\nNote that if you enable any additional APIs in the future, you must add them to\nthe *API restrictions* list for the applicable API key.\n\n2. Create a new API key for use with Firebase ML\n\nNext, create a new API key for Firebase ML that only allows calls to the\nCloud Vision API:\n\n1. Return to the [Credentials](https://console.cloud.google.com/apis/credentials) page. Be sure your\n Firebase project is still selected.\n\n2. Click **Create credentials \\\u003e API key** . Take note of the new API key, then\n click **Restrict key**.\n\n3. In the *API restrictions* section, select **Restrict key** , then add to the\n list ***only*** the Cloud Vision API.\n\nThis API key grants access only to the Cloud Vision API and can be used by\nFirebase ML to access cloud-based models.\n\n3. Recommended: Reduce the Cloud Vision API's quota\n\nTo help mitigate the consequences of a compromised key, you should reduce the\nCloud Vision API's per-user quota from its default setting. To do so:\n\n1. Open the [Cloud Vision API Quotas](https://console.cloud.google.com/apis/api/vision.googleapis.com/quotas?project=_) page of the\n Google Cloud console. When prompted, select your project.\n\n2. In the **Requests** section, set the **Requests per minute per user** quota\n to something reasonable for your app. For example, if your app involves\n uploading a picture of a document to get back its text, it's unlikely that a\n user will do that more than once every few seconds, so a quota of 30-40\n would probably be safe.\n\n Note that in this context \"requests per user\" refers to requests from a\n single IP address. You might need to consider this if you expect multiple\n users to use your app at the same time from behind a NAT.\n\n4. Call Cloud APIs using your Firebase ML API key\n\nFinally, in your app, configure Firebase ML to use your new API key.\n\nBecause the Firebase ML API key allows unauthenticated access to the Cloud Vision\nAPI, it's important to keep the key confidential to prevent unauthorized use and\ncharges to your billing account. To do so, you should refrain from including\nyour API key in your app binary. Instead, at app runtime, verify that a known\ngood user is signed in, and only then, retrieve the API key from a server.\n\nEven when these practices are observed, it is possible for an API key to be\ncompromised. You should take steps to help mitigate the consequences of a\ncompromised key, such as reducing the API's per-user quota as described above,\nimplementing key rotation policies, and issuing different keys to different\ngroups of users.\n\nAfter your app has safely acquired the API key, when you want to call an\nFirebase ML Cloud API, specify the key: \n\nSwift \n\n if let cloudVisionKey = getYourApiKey() { // See note above about securing your API key\n let options = VisionCloudDetectorOptions()\n options.apiKeyOverride = cloudVisionKey\n let cloudDetector = Vision.vision().cloudLandmarkDetector(options: options)\n }\n\nObjective-C \n\n NSString *cloudVisionKey = [self getYourApiKey]; // See note above about securing your API key\n if (cloudVisionKey != nil) {\n FIRVisionCloudDetectorOptions *options =\n [[FIRVisionCloudDetectorOptions alloc] init];\n options.APIKeyOverride = cloudVisionKey;\n FIRVisionCloudLandmarkDetector *landmarkDetector =\n [vision cloudLandmarkDetectorWithOptions:options];\n }\n\nIn addition, you should follow the general advice in\n[Securing an API key](https://cloud.google.com/docs/authentication/api-keys#securing_an_api_key).\n\nNext steps\n\nSee the [launch checklist](/support/guides/launch-checklist) for information on\npreparing your app to launch when using other Firebase features."]]