تأمين النهاية الخلفية
يؤمن هذا البرنامج النصي النموذجي الواجهة الخلفية بمصادقة شهادة متبادلة.
ملاحظة
تستخدم هذه المقالة الوحدة النمطية Azure Az PowerShell، وهي الوحدة النمطية PowerShell الموصى بها للتفاعل مع Azure. لبدء استخدام الوحدة النمطية Az PowerShell، راجع تثبيت Azure PowerShell. لمعرفة كيفية الترحيل إلى الوحدة النمطية Az PowerShell، راجع ترحيل Azure PowerShell من AzureRM إلى Az.
استخدام Azure Cloud Shell
Azure يستضيف Azure Cloud Shell، بيئة تفاعلية يمكن استخدامها من خلال المستعرض. يمكنك استخدام Bash أو PowerShell مع Cloud Shell للعمل مع خدمات Azure. يمكنك استخدام أوامر Cloud Shell المثبتة مسبقًا لتشغيل التعليمات البرمجية في هذه المقالة دون الحاجة إلى تثبيت أي شيء على البيئة المحلية.
لبدء Azure Cloud Shell:
| خيار | مثال/ رابط |
|---|---|
| انقر فوق جربه في الزاوية العلوية اليسرى من كتلة التعليمات البرمجية. تحديد جربه لا يقوم بنسخ التعليمات البرمجية تلقائيًا إلى Cloud Shell. | ![]() |
| انتقل إلى https://shell.azure.com، أو حدد زر تشغيل Cloud Shell لفتح Cloud Shell في المتصفح لديك. | ![]() |
| حدد زر Cloud Shell في شريط القوائم في أعلى اليمين في مدخل Azure. | ![]() |
لتشغيل التعليمة البرمجية في هذا المقال في Azure Cloud Shell:
ابدأ تشغيل Cloud Shell.
حدد الزر نسخ على كتلة التعليمات البرمجية لنسخ التعليمات البرمجية.
ألصق تعليمة البرمجية في جلسة Cloud Shell بتحديد Ctrl+Shift+Vعلى Windows وLunix، أو بتحديد Cmd+Shift+Vعلى macOS.
اكتب "Enter" لتشغيل الأمر.
إذا اخترت تثبيت PowerShell واستخدامه محلياً، فإن هذا البرنامج التعليمي يتطلب إصدار الوحدة النمطية Azure PowerShell 1.0 أو إصدار أحدث. قم بتشغيل Get-Module -ListAvailable Az للعثور على الإصدار. إذا كنت بحاجة إلى الترقية، فراجع تثبيت الوحدة النمطية Azure PowerShell. إذا كنت تقوم بتشغيل PowerShell محلياً، تحتاج أيضاً إلى تشغيل Connect-AzAccount لإنشاء اتصال مع Azure.
عينة برنامج نصي
##########################################################
# Script to setup backend mutual authentication using certificates
###########################################################
$random = (New-Guid).ToString().Substring(0,8)
#Azure specific details
$subscriptionId = "my-azure-subscription-id"
# Api Management service specific details
$apimServiceName = "apim-$random"
$resourceGroupName = "apim-rg-$random"
$location = "Japan East"
$organisation = "Contoso"
$adminEmail = "admin@contoso.com"
# Certificate needed for Custom Domain Setup
$certificateFilePath = "<Replace with path to the Certificate to be used for Mutual Authentication>"
$certificatePassword = '<Password used to secure the Certificate>'
# Set the context to the subscription Id where the cluster will be created
Select-AzSubscription -SubscriptionId $subscriptionId
# Create a resource group.
New-AzResourceGroup -Name $resourceGroupName -Location $location
# Create the Api Management service. Since the SKU is not specified, it creates a service with Developer SKU.
New-AzApiManagement -ResourceGroupName $resourceGroupName -Name $apimServiceName -Location $location -Organization $organisation -AdminEmail $adminEmail
# Create the api management context
$context = New-AzApiManagementContext -ResourceGroupName $resourceGroupName -ServiceName $apimServiceName
# upload the certificate
$cert = New-AzApiManagementCertificate -Context $context -PfxFilePath $certificateFilePath -PfxPassword $certificatePassword
# create an authentication-certificate policy with the thumbprint of the certificate
$apiPolicy = "<policies><inbound><base /><authentication-certificate thumbprint=""" + $cert.Thumbprint + """ /></inbound><backend><base /></backend><outbound><base /></outbound><on-error><base /></on-error></policies>"
$echoApi = Get-AzApiManagementApi -Context $context -Name "Echo API"
# setup Policy at the Product Level. Policies can be applied at entire API Management Service Scope, Api Scope, Product Scope and Api Operation Scope
Set-AzApiManagementPolicy -Context $context -Policy $apiPolicy -ApiId $echoApi.ApiId
تنظيف الموارد
عندما لم تعد هناك حاجة، يمكنك استخدام الأمر Remove- AzResourceGroup لإزالة مجموعة الموارد وجميع الموارد ذات الصلة.
Remove-AzResourceGroup -Name myResourceGroup
الخطوات التالية
لمزيد من المعلومات حول وحدة Azure PowerShell، راجع وثائق Azure PowerShell.
يمكن العثور على عينات Azure PowerShell الإضافية لإدارة Azure API في عينات PowerShell.


