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/openai/how-to/managed-identity.md
+51-32Lines changed: 51 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,8 +5,8 @@ description: Provides guidance on how to set managed identity with Microsoft Ent
5
5
ms.service: azure-ai-openai
6
6
ms.topic: how-to
7
7
ms.date: 02/29/2024
8
-
author: ChrisHMSFT
9
-
ms.author: chrhoder
8
+
author: mrbullwinkle
9
+
ms.author: mbullwin
10
10
recommendations: false
11
11
ms.custom: devx-track-azurecli
12
12
---
@@ -15,7 +15,7 @@ ms.custom: devx-track-azurecli
15
15
16
16
More complex security scenarios require Azure role-based access control (Azure RBAC). This document covers how to authenticate to your OpenAI resource using Microsoft Entra ID.
17
17
18
-
In the following sections, you'll use the Azure CLI to assign roles, and obtain a bearer token to call the OpenAI resource. If you get stuck, links are provided in each section with all available options for each command in Azure Cloud Shell/Azure CLI.
18
+
In the following sections, you'll use the Azure CLI to sign in, and obtain a bearer token to call the OpenAI resource. If you get stuck, links are provided in each section with all available options for each command in Azure Cloud Shell/Azure CLI.
19
19
20
20
## Prerequisites
21
21
@@ -27,52 +27,71 @@ In the following sections, you'll use the Azure CLI to assign roles, and obtain
- The following Python libraries: os, requests, json
30
+
- The following Python libraries: os, requests, json, openai, azure-identity
31
+
32
+
## Assign yourself to the Cognitive Services User role
33
+
34
+
Assign yourself the [Cognitive Services User](role-based-access-control.md#cognitive-services-contributor) role to allow you to use your account to make Azure OpenAI API calls rather than having to use key-based auth. After you make this change it can take up to 5 minutes before the change takes effect.
31
35
32
36
## Sign into the Azure CLI
33
37
34
-
To sign-in to the Azure CLI, run the following command and complete the sign-in. You may need to do it again if your session has been idle for too long.
38
+
To sign-in to the Azure CLI, run the following command and complete the sign-in. You might need to do it again if your session has been idle for too long.
35
39
36
40
```azurecli
37
41
az login
38
42
```
39
43
40
-
## Assign yourself to the Cognitive Services User role
41
-
42
-
Assigning yourself to the "Cognitive Services User" role will allow you to use your account for access to the specific Azure AI services resource.
43
-
44
-
1. Get your user information
45
-
46
-
```azurecli
47
-
export user=$(az account show --query "user.name" -o tsv)
48
-
```
44
+
## Chat Completions
45
+
46
+
```python
47
+
from azure.identity import DefaultAzureCredential, get_bearer_token_provider
0 commit comments