از اطلاعات کاربری Cloud برنامه Firebase ML Apple خود محافظت کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اگر برنامه Apple شما از یکی از APIهای ابری Firebase ML استفاده می کند، قبل از اینکه برنامه خود را در مرحله تولید راه اندازی کنید، باید اقدامات دیگری را برای جلوگیری از دسترسی غیرمجاز API انجام دهید.
1. دامنه کلیدهای API موجود را کاهش دهید
ابتدا کلیدهای API موجود خود را پیکربندی کنید تا دسترسی به Cloud Vision API ممنوع شود:
صفحه اعتبارنامه کنسول Google Cloud را باز کنید. وقتی از شما خواسته شد، پروژه خود را انتخاب کنید.
برای هر کلید API موجود در لیست، نمای ویرایش را باز کنید.
در بخش محدودیتهای API ، Restrict key را انتخاب کنید، سپس همه APIهایی را که میخواهید کلید API به آنها دسترسی داشته باشد، به لیست اضافه کنید. اطمینان حاصل کنید که Cloud Vision API را شامل نمی شود.
وقتی محدودیتهای API کلید API را پیکربندی میکنید، به صراحت APIهایی را که کلید به آنها دسترسی دارد، اعلام میکنید. بهطور پیشفرض، زمانی که در بخش محدودیتهای APIکلید Don't limited key انتخاب شده باشد، میتوان از یک کلید API برای دسترسی به هر API که برای پروژه فعال است استفاده کرد.
اکنون، کلیدهای API موجود شما امکان دسترسی به خدمات ابر ML را نمیدهند، اما هر کلید برای هر APIهایی که به لیست محدودیتهای API خود اضافه کردهاید به کار خود ادامه میدهد.
توجه داشته باشید که اگر در آینده هر API دیگری را فعال کنید، باید آنها را به لیست محدودیت های API برای کلید API قابل اجرا اضافه کنید.
2. یک کلید API جدید برای استفاده با Firebase ML ایجاد کنید
در مرحله بعد، یک کلید API جدید برای Firebase ML ایجاد کنید که فقط به Cloud Vision API اجازه تماس را می دهد:
به صفحه اعتبارنامه بازگردید. مطمئن شوید که پروژه Firebase شما هنوز انتخاب شده است.
روی ایجاد اعتبارنامه > کلید API کلیک کنید. کلید API جدید را یادداشت کنید، سپس روی Restrict key کلیک کنید.
در بخش محدودیتهای API ، Restrict key را انتخاب کنید، سپس فقط Cloud Vision API را به لیست اضافه کنید.
این کلید API فقط به Cloud Vision API دسترسی می دهد و می تواند توسط Firebase ML برای دسترسی به مدل های مبتنی بر ابر استفاده شود.
3. توصیه می شود: سهمیه Cloud Vision API را کاهش دهید
برای کمک به کاهش پیامدهای یک کلید در معرض خطر، باید سهمیه هر کاربر Cloud Vision API را از تنظیمات پیشفرض آن کاهش دهید. برای انجام این کار:
صفحه Cloud Vision API Quotas کنسول Google Cloud را باز کنید. وقتی از شما خواسته شد، پروژه خود را انتخاب کنید.
در بخش درخواستها ، سهمیه درخواستها در دقیقه برای هر کاربر را روی چیزی معقول برای برنامه خود تنظیم کنید. به عنوان مثال، اگر برنامه شما شامل آپلود تصویر یک سند برای بازگرداندن متن آن باشد، بعید است که کاربر این کار را بیش از هر چند ثانیه یک بار انجام دهد، بنابراین سهمیه 30-40 احتمالاً ایمن خواهد بود.
توجه داشته باشید که در این زمینه "درخواست برای هر کاربر" به درخواست هایی از یک آدرس IP واحد اشاره دارد. اگر انتظار دارید چندین کاربر به طور همزمان از برنامه شما از پشت NAT استفاده کنند، ممکن است لازم باشد این را در نظر بگیرید.
4. با استفاده از کلید Firebase ML API خود، APIهای Cloud را فراخوانی کنید
در نهایت، در برنامه خود، Firebase ML برای استفاده از کلید API جدید خود پیکربندی کنید.
از آنجایی که کلید Firebase ML API امکان دسترسی غیرمجاز به Cloud Vision API را می دهد، مهم است که کلید را محرمانه نگه دارید تا از استفاده غیرمجاز و کسر هزینه از حساب صورتحساب خود جلوگیری کنید. برای انجام این کار، باید از قرار دادن کلید API خود در باینری برنامه خودداری کنید. در عوض، در زمان اجرای برنامه، بررسی کنید که یک کاربر خوب شناخته شده وارد سیستم شده باشد و تنها پس از آن، کلید API را از یک سرور بازیابی کنید.
حتی زمانی که این اقدامات مشاهده می شود، ممکن است یک کلید API به خطر بیفتد. شما باید اقداماتی را برای کمک به کاهش پیامدهای یک کلید در معرض خطر انجام دهید، مانند کاهش سهمیه API برای هر کاربر همانطور که در بالا توضیح داده شد، اجرای سیاستهای چرخش کلید، و صدور کلیدهای مختلف برای گروههای مختلف کاربران.
پس از اینکه برنامه شما با خیال راحت کلید API را به دست آورد، هنگامی که می خواهید یک Firebase ML Cloud API را فراخوانی کنید، کلید را مشخص کنید:
سویفت
ifletcloudVisionKey=getYourApiKey(){// See note above about securing your API keyletoptions=VisionCloudDetectorOptions()options.apiKeyOverride=cloudVisionKeyletcloudDetector=Vision.vision().cloudLandmarkDetector(options:options)}
هدف-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."]]