Skip to content

Commit 05e29a8

Browse files
Merge pull request #223695 from ddematheu2/patch-43
Create service-principal-cli.md
2 parents 7f8fd60 + ddc602e commit 05e29a8

File tree

7 files changed

+72
-99
lines changed

7 files changed

+72
-99
lines changed

articles/communication-services/.openpublishing.redirection.communication-services.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@
133133
"source_path_from_root": "/articles/communication-services/concepts/voice-video-calling/call-automation.md",
134134
"redirect_url": "/azure/communication-services/concepts/call-automation/call-automation",
135135
"redirect_document_id": false
136+
},
137+
{
138+
"source_path_from_root": "/articles/communication-services/quickstarts/identity/service-principal-from-cli.md",
139+
"redirect_url": "/azure/communication-services/quickstarts/identity/service-principal",
140+
"redirect_document_id": false
136141
}
137142
]
138-
}
143+
}

articles/communication-services/concepts/authentication.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ If you wish to call Azure Communication Services' APIs manually using an access
4747

4848
The Azure platform provides role-based access (Azure RBAC) to control access to the resources. Azure RBAC security principal represents a user, group, service principal, or managed identity that is requesting access to Azure resources. Azure AD authentication provides superior security and ease of use over other authorization options. For example, by using managed identity, you avoid having to store your account access key within your code, as you do with Access Key authorization. While you can continue to use Access Key authorization with communication services applications, Microsoft recommends moving to Azure AD where possible.
4949

50-
To set up a service principal, [create a registered application from the Azure CLI](../quickstarts/identity/service-principal-from-cli.md). Then, the endpoint and credentials can be used to authenticate the SDKs. See examples of how [service principal](../quickstarts/identity/service-principal.md) is used.
50+
To set up a service principal, [create a registered application from the Azure CLI](../quickstarts/identity/service-principal.md?pivots=platform-azcli). Then, the endpoint and credentials can be used to authenticate the SDKs. See examples of how [service principal](../quickstarts/identity/service-principal.md) is used.
5151

5252
Communication services support Azure AD authentication but do not support managed identity for Communication services resources. You can find more details, about the managed identity support in the [Azure Active Directory documentation](../../active-directory/managed-identities-azure-resources/services-support-managed-identities.md).
5353

@@ -67,7 +67,7 @@ The user identity is intended to act as a primary key for logs and metrics colle
6767
> [Create and manage Communication Services resources](../quickstarts/create-communication-resource.md)
6868
6969
> [!div class="nextstepaction"]
70-
> [Create an Azure Active Directory service principal application from the Azure CLI](../quickstarts/identity/service-principal-from-cli.md)
70+
> [Create an Azure Active Directory service principal application from the Azure CLI](../quickstarts/identity/service-principal.md?pivots=platform-azcli)
7171
7272
> [!div class="nextstepaction"]
7373
> [Create user access tokens](../quickstarts/access-tokens.md)

articles/communication-services/quickstarts/email/includes/send-email-net.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ To authenticate using Azure Active Directory, install the Azure.Identity library
114114
dotnet add package Azure.Identity
115115
```
116116

117-
Open **Program.cs** in a text editor and replace the body of the `Main` method with code to initialize an `EmailClient` using `DefaultAzureCredential`. The Azure Identity SDK reads values from three environment variables at runtime to authenticate the application. Learn how to [create an Azure Active Directory Registered Application and set the environment variables](../../identity/service-principal-from-cli.md).
117+
Open **Program.cs** in a text editor and replace the body of the `Main` method with code to initialize an `EmailClient` using `DefaultAzureCredential`. The Azure Identity SDK reads values from three environment variables at runtime to authenticate the application. Learn how to [create an Azure Active Directory Registered Application and set the environment variables](../../identity/service-principal.md?pivots=platform-azcli).
118118

119119
```csharp
120120
// This code demonstrates how to authenticate to your Communication Service resource using
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
## Additional Prerequisites
2+
3+
- Azure CLI. [Installation guide](/cli/azure/install-azure-cli)
4+
5+
## Setting Up
6+
7+
When using Active Directory for other Azure Resources, you should be using Managed identities. To learn how to enable managed identities for Azure Resources, see one of these articles:
8+
9+
- [Azure portal](../../../../../active-directory/managed-identities-azure-resources/qs-configure-portal-windows-vm.md)
10+
- [Azure PowerShell](../../../../../active-directory/managed-identities-azure-resources/qs-configure-powershell-windows-vm.md)
11+
- [Azure CLI](../../../../../active-directory/managed-identities-azure-resources/qs-configure-cli-windows-vm.md)
12+
- [Azure Resource Manager template](../../../../../active-directory/managed-identities-azure-resources/qs-configure-template-windows-vm.md)
13+
- [Azure Resource Manager SDKs](../../../../../active-directory/managed-identities-azure-resources/qs-configure-sdk-windows-vm.md)
14+
- [App services](../../../../../app-service/overview-managed-identity.md)
15+
16+
## Authenticate a registered application in the development environment
17+
18+
If your development environment doesn't support single sign-on or login via a web browser, then you can use a registered application to authenticate from the development environment.
19+
20+
### Creating an Azure Active Directory Registered Application
21+
22+
To create a registered application from the Azure CLI, you need to be logged in to the Azure account where you want the operations to take place. To do this, you can use the `az login` command and enter your credentials in the browser. Once you're logged in to your Azure account from the CLI, we can call the `az ad sp create-for-rbac` command to create the registered application and service principal.
23+
24+
The following example uses the Azure CLI to create a new registered application:
25+
26+
```azurecli
27+
az ad sp create-for-rbac --name <application-name> --role Contributor --scopes /subscriptions/<subscription-id>
28+
```
29+
30+
The `az ad sp create-for-rbac` command will return a list of service principal properties in JSON format. Copy these values so that you can use them to create the necessary environment variables in the next step.
31+
32+
```json
33+
{
34+
"appId": "generated-app-ID",
35+
"displayName": "service-principal-name",
36+
"name": "http://service-principal-uri",
37+
"password": "generated-password",
38+
"tenant": "tenant-ID"
39+
}
40+
```
41+
> [!IMPORTANT]
42+
> Azure role assignments may take a few minutes to propagate.
43+
44+
#### Set environment variables
45+
46+
The Azure Identity SDK reads values from three environment variables at runtime to authenticate the application. The following table describes the value to set for each environment variable.
47+
48+
| Environment variable | Value |
49+
| --------------------- | ---------------------------------------- |
50+
| `AZURE_CLIENT_ID` | `appId` value from the generated JSON |
51+
| `AZURE_TENANT_ID` | `tenant` value from the generated JSON |
52+
| `AZURE_CLIENT_SECRET` | `password` value from the generated JSON |
53+
54+
> [!IMPORTANT]
55+
> After you set the environment variables, close and re-open your console window. If you're using Visual Studio or another development environment, you may need to restart it in order for it to register the new environment variables.
56+
57+
Once these variables have been set, you should be able to use the DefaultAzureCredential object in your code to authenticate to the service client of your choice.

articles/communication-services/quickstarts/identity/service-principal-from-cli.md

Lines changed: 0 additions & 91 deletions
This file was deleted.

articles/communication-services/quickstarts/identity/service-principal.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ ms.topic: quickstart
1010
ms.date: 06/30/2021
1111
ms.author: peiliu
1212
ms.reviewer: mikben
13-
zone_pivot_groups: acs-js-csharp-java-python
13+
zone_pivot_groups: acs-azcli-js-csharp-java-python
1414
ms.custom: mode-other
1515
---
1616

@@ -25,7 +25,11 @@ This quickstart shows you how to authorize access to the Identity and SMS SDKs f
2525
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free)
2626
- An active Azure Communication Services resource, see [create a Communication Services resource](../create-communication-resource.md) if you do not have one.
2727
- To send an SMS you will need a [Phone Number](../telephony/get-phone-number.md).
28-
- A setup Service Principal for a development environment, see [Authorize access with service principal](./service-principal-from-cli.md)
28+
- A setup Service Principal for a development environment, see [Authorize access with service principal](./service-principal.md?pivots=platform-azcli)
29+
30+
::: zone pivot="platform-azcli"
31+
[!INCLUDE [AzCLI](./includes/active-directory/service-principal-cli.md)]
32+
::: zone-end
2933

3034
::: zone pivot="programming-language-csharp"
3135
[!INCLUDE [.NET](./includes/active-directory/service-principal-net.md)]

articles/communication-services/toc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ items:
1919
href: quickstarts/access-tokens.md
2020
- name: Authenticate with Azure AD
2121
href: quickstarts/identity/service-principal.md
22-
- name: Authenticate with Azure AD (Azure CLI)
23-
href: quickstarts/identity/service-principal-from-cli.md
2422
- name: Quick-create identities for testing
2523
href: quickstarts/identity/quick-create-identity.md
2624
- name: Create identities and tokens in Azure Logic Apps

0 commit comments

Comments
 (0)