Skip to content

Commit ac03fd5

Browse files
author
Kirill Linnik
committed
boost clarity score
1 parent b5c8fbc commit ac03fd5

File tree

1 file changed

+38
-21
lines changed

1 file changed

+38
-21
lines changed

articles/communication-services/quickstarts/identity/includes/active-directory/service-principal-net.md

Lines changed: 38 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,44 @@
11
> [!NOTE]
22
> Find the finalized code for this quickstart on [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/use-managed-Identity)
33
4-
## Setting up
4+
## Overview
55

6-
### Create a new C# application
6+
This quickstart demonstrates how to use managed identities via Azure Service Principals to authenticate with Azure Communication Services. It provides examples for issuing an access token for Voice over IP (VoIP) calls and sending SMS messages.
77

8-
In a console window (such as cmd, PowerShell, or Bash), use the `dotnet new` command to create a new console app with the name `ActiveDirectoryQuickstart`. This command creates a simple "Hello World" C# project with a single source file: `Program.cs`.
8+
## Setting Up
9+
10+
### Create a New C# Application
11+
12+
The goal is to create a new console application in C# to run the quickstart code. Open a terminal window (e.g., Command Prompt, PowerShell, or Bash) and execute the following command to create a new console app named `ActiveDirectoryAuthenticationQuickstart`:
913

1014
```console
1115
dotnet new console -o ActiveDirectoryAuthenticationQuickstart
1216
```
1317

14-
Change your directory to the newly created app folder and use the `dotnet build` command to compile your application.
18+
This command will generate a simple "Hello World" C# project, including a single source file: `Program.cs`.
19+
20+
### Build the Application
21+
22+
Navigate to the newly created app folder and compile your application using the `dotnet build` command:
1523

1624
```console
1725
cd ActiveDirectoryAuthenticationQuickstart
1826
dotnet build
1927
```
2028

21-
### Install the SDK packages
29+
### Install the Required SDK Packages
30+
31+
To interact with Azure Communication Services and Azure Identity, add the following NuGet packages to your project:
2232

2333
```console
2434
dotnet add package Azure.Communication.Identity
2535
dotnet add package Azure.Communication.Sms
2636
dotnet add package Azure.Identity
2737
```
2838

29-
### Use the SDK packages
39+
### Update the Program.cs File
3040

31-
Add the following `using` directives to `Program.cs` to use the Azure Identity and Azure Storage SDKs.
41+
To use the installed Azure SDK packages, include the following `using` directives at the top of your `Program.cs` file:
3242

3343
```csharp
3444
using Azure.Identity;
@@ -38,17 +48,17 @@ using Azure.Core;
3848
using Azure;
3949
```
4050

41-
## Create a DefaultAzureCredential
51+
## Authenticate with DefaultAzureCredential
4252

43-
We'll be using the [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential) for this quickstart. This credential is suitable for production and development environments. As it is needed for each operation let's create it within the `Program.cs` class. Add the following to the top of the file.
53+
For this quickstart, we'll use the [DefaultAzureCredential](/dotnet/api/azure.identity.defaultazurecredential), which is suitable for both development and production environments. Declare an instance of this credential at the class level in `Program.cs`:
4454

4555
```csharp
4656
private DefaultAzureCredential credential = new DefaultAzureCredential();
4757
```
4858

49-
## Issue a token with service principals
59+
## Issue a Token with Service Principals
5060

51-
Now we'll add code which uses the created credential, to issue a VoIP Access Token. We'll call this code later on.
61+
Add the following method to your `Program.cs` file. This method uses the Azure Communication Services SDK to issue a VoIP Access Token:
5262

5363
```csharp
5464
public AccessToken CreateIdentityAndGetTokenAsync(Uri resourceEndpoint)
@@ -60,9 +70,9 @@ public AccessToken CreateIdentityAndGetTokenAsync(Uri resourceEndpoint)
6070
}
6171
```
6272

63-
## Send an SMS with service principals
73+
## Send an SMS with Service Principals
6474

65-
As another example of using service principals, we'll add this code which uses the same credential to send an SMS:
75+
To demonstrate sending an SMS, add the following method to your `Program.cs` file. This method uses the Azure Communication Services SDK to send an SMS message:
6676

6777
```csharp
6878
public SmsSendResult SendSms(Uri resourceEndpoint, string from, string to, string message)
@@ -79,9 +89,9 @@ public SmsSendResult SendSms(Uri resourceEndpoint, string from, string to, strin
7989
}
8090
```
8191

82-
## Write the Main method
92+
## Write the Main Method
8393

84-
Your `Program.cs` should already have a Main method, let's add some code which will call our previously created code to demonstrate the use of service principals:
94+
In the `Main` method of your `Program.cs` file, add code to call the methods you created for issuing a token and sending an SMS. Your `Main` method should look similar to this:
8595

8696
```csharp
8797
static void Main(string[] args)
@@ -156,11 +166,18 @@ class Program
156166

157167
## Run the program
158168

159-
You should now be able to run your application, using `dotnet run` from your application folder. The output should resemble the following:
169+
It is time to run your application and verify that it retrieves an access token and sends an SMS. Open a terminal, navigate to your application directory, and run:
170+
171+
```console
172+
dotnet run
160173
```
161-
Retrieving new Access Token, using Service Principals
162-
Retrieved Access Token: ey....
163-
Sending SMS using Service Principals
164-
Sms id: ...
165-
Send Result Successful: True
174+
175+
The console output should appear as follows:
176+
177+
```Bash
178+
Retrieving new Access Token, using Service Principals
179+
Retrieved Access Token: ...
180+
Sending SMS using Service Principals
181+
Sms id: ...
182+
Send Result Successful: True
166183
```

0 commit comments

Comments
 (0)