You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-services/authentication.md
+121-2Lines changed: 121 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Each request to an Azure AI service must include an authentication header. This
18
18
19
19
* Authenticate with a [single-service](#authenticate-with-a-single-service-resource-key) or [multi-service](#authenticate-with-a-multi-service-resource-key) resource key
20
20
* Authenticate with a [token](#authenticate-with-an-access-token)
21
-
* Authenticate with [Azure Active Directory (AAD)](#authenticate-with-an-access-token)
21
+
* Authenticate with [Azure Active Directory (AAD)](#authenticate-with-azure-active-directory)
22
22
23
23
## Prerequisites
24
24
@@ -160,7 +160,126 @@ curl -X POST 'https://api.cognitive.microsofttranslator.com/translate?api-versio
160
160
--data-raw '[{ "text": "How much for the cup of coffee?" }]' | json_pp
> Azure AD authentication always needs to be used together with custom subdomain name of your Azure resource. [Regional endpoints](../articles/cognitive-services/cognitive-services-custom-subdomains.md#is-there-a-list-of-regional-endpoints) do not support Azure AD authentication.
167
+
168
+
In the previous sections, we showed you how to authenticate against Azure AI services using a single-service or multi-service subscription key. While these keys provide a quick and easy path to start development, they fall short in more complex scenarios that require Azure [role-based access control (Azure RBAC)](../articles/role-based-access-control/overview.md). Let's take a look at what's required to authenticate using Azure Active Directory (Azure AD).
169
+
170
+
In the following sections, you'll use either the Azure Cloud Shell environment or the Azure CLI to create a subdomain, assign roles, and obtain a bearer token to call the Azure AI services. If you get stuck, links are provided in each section with all available options for each command in Azure Cloud Shell/Azure CLI.
171
+
172
+
### Create a resource with a custom subdomain
173
+
174
+
The first step is to create a custom subdomain. If you want to use an existing Azure AI services resource which does not have custom subdomain name, follow the instructions in [Azure AI services custom subdomains](../articles/cognitive-services/cognitive-services-custom-subdomains.md#how-does-this-impact-existing-resources) to enable custom subdomain for your resource.
175
+
176
+
1. Start by opening the Azure Cloud Shell. Then [select a subscription](/powershell/module/az.accounts/set-azcontext):
2. Next, [create an Azure AI services resource](/powershell/module/az.cognitiveservices/new-azcognitiveservicesaccount) with a custom subdomain. The subdomain name needs to be globally unique and cannot include special characters, such as: ".", "!", ",".
> If you register an application in the Azure portal, this step is completed for you.
216
+
217
+
3. The last step is to [assign the "Cognitive Services User" role](/powershell/module/az.Resources/New-azRoleAssignment) to the service principal (scoped to the resource). By assigning a role, you're granting service principal access to this resource. You can grant the same service principal access to multiple resources in your subscription.
218
+
>[!NOTE]
219
+
> The ObjectId of the service principal is used, not the ObjectId for the application.
220
+
> The ACCOUNT_ID will be the Azure resource Id of the Azure AI services account you created. You can find Azure resource Id from "properties" of the resource in Azure portal.
$result = Invoke-RestMethod -Uri $url -Method Get -Headers @{"Authorization"=$token.CreateAuthorizationHeader()} -Verbose
263
+
$result | ConvertTo-Json
264
+
```
265
+
266
+
Alternatively, the service principal can be authenticated with a certificate. Besides service principal, user principal is also supported by having permissions delegated through another Azure AD application. In this case, instead of passwords or certificates, users would be prompted for two-factor authentication when acquiring token.
267
+
268
+
## Authorize access to managed identities
269
+
270
+
Azure AI services support Azure Active Directory (Azure AD) authentication with [managed identities for Azure resources](../articles/active-directory/managed-identities-azure-resources/overview.md). Managed identities for Azure resources can authorize access to Azure AI services resources using Azure AD credentials from applications running in Azure virtual machines (VMs), function apps, virtual machine scale sets, and other services. By using managed identities for Azure resources together with Azure AD authentication, you can avoid storing credentials with your applications that run in the cloud.
271
+
272
+
### Enable managed identities on a VM
273
+
274
+
Before you can use managed identities for Azure resources to authorize access to Azure AI services resources from your VM, you must enable managed identities for Azure resources on the VM. To learn how to enable managed identities for Azure Resources, see:
For more information about managed identities, see [Managed identities for Azure resources](../articles/active-directory/managed-identities-azure-resources/overview.md).
164
283
165
284
## Use Azure key vault to securely access credentials
0 commit comments