Skip to content

Commit 48fcc04

Browse files
author
Kirill Linnik
committed
adjusted wording for a better score
1 parent 97559f6 commit 48fcc04

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

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

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,28 @@
55

66
### Create a new Python application
77

8-
Open your terminal or command window create a new directory for your app, and navigate to it.
8+
Let us set up your working directory for the application. For that, open your terminal or command window, create a new directory, and navigate to it:
99

1010
```console
1111
mkdir active-directory-authentication-quickstart && cd active-directory-authentication-quickstart
1212
```
1313

1414
### Install the SDK packages
1515

16+
Next we need to install the required Azure SDK packages. Run these commands:
17+
1618
```console
1719
pip install azure-identity
1820
pip install azure-communication-identity
1921
pip install azure-communication-sms
2022
```
2123

2224
### Create a new file
23-
Open and save a new file within your created folder called `authentication.py`, we'll be placing our code inside this file.
25+
Now we need a Python file to hold your code. Open and save a new file called `authentication.py` within your directory.
2426

2527
### Use the SDK packages
2628

27-
Add the following `import` statements to the top of your file to use the SDKs that we installed.
29+
Our next goal is to import the necessary Azure SDK modules to work with identity and SMS. Add the following statements at the top of your file:
2830

2931
```python
3032
from azure.identity import DefaultAzureCredential
@@ -34,15 +36,17 @@ from azure.communication.sms import SmsClient
3436

3537
### Create a DefaultAzureCredential
3638

37-
We'll be using the [DefaultAzureCredential](/python/api/azure-identity/azure.identity.defaultazurecredential). This credential is suitable for production and development environments. As we'll be using it throughout this quickstart we'll create it at the top of the file.
39+
We need to initialize a credential for both production and development environments.
40+
41+
Place this line with [DefaultAzureCredential](/python/api/azure-identity/azure.identity.defaultazurecredential) after previously inserted lines:
3842

3943
```python
4044
credential = DefaultAzureCredential()
4145
```
4246

4347
## Create an identity and issue a token with service principals
4448

45-
Now we'll add code which uses the created credential, to issue a VoIP Access Token. We'll call this code later on:
49+
Create an identity and request a Voice over Internet Protocol (VoIP) access token:
4650

4751
```python
4852
def create_identity_and_get_token(resource_endpoint):
@@ -53,7 +57,8 @@ def create_identity_and_get_token(resource_endpoint):
5357
```
5458

5559
### Send an SMS with service principals
56-
As another example of using service principals, we'll add this code which uses the same credential to send an SMS:
60+
61+
Alternetively, you can utilize your credential to send a Short Message Service (SMS) as shown in the example below:
5762

5863
```python
5964
def send_sms(resource_endpoint, from_phone_number, to_phone_number, message_content):
@@ -69,11 +74,13 @@ def send_sms(resource_endpoint, from_phone_number, to_phone_number, message_cont
6974

7075
## Write our main code
7176

72-
With our functions created we can now write the main code which will call the functions we've previous written.
77+
Now we have all the necessary code blocks to execute the functions to create an identity, obtain an access token, and send an SMS.
78+
79+
Include the main code that calls your functions:
7380

7481
```python
75-
# You can find your endpoint and access key from your resource in the Azure portal
76-
# e.g. "https://<RESOURCE_NAME>.communication.azure.com";
82+
# Retrieve your endpoint and access key from your resource in the Azure portal
83+
# For example: "https://<RESOURCE_NAME>.communication.azure.com"
7784
endpoint = "https://<RESOURCE_NAME>.communication.azure.com/"
7885

7986
print("Retrieving new Access Token, using Service Principals");
@@ -82,13 +89,13 @@ print(f'Retrieved Access Token: {result.token}');
8289

8390
print("Sending SMS using Service Principals");
8491

85-
# You will need a phone number from your resource to send an SMS.
92+
# Provide a valid phone number from your Azure resource to send an SMS.
8693
sms_result = send_sms(endpoint, "<FROM_NUMBER>", "<TO_NUMBER>", "Hello from Service Principals");
8794
print(f'SMS ID: {sms_result[0].message_id}');
8895
print(f'Send Result Successful: {sms_result[0].successful}');
8996
```
9097

91-
The final `authentication.py` file should look something like this:
98+
This is how the `authentication.py` looks after all changes you made:
9299

93100
```python
94101
from azure.identity import DefaultAzureCredential
@@ -131,12 +138,15 @@ print(f'Send Result Successful: {sms_result[0].successful}');
131138
```
132139
## Run the program
133140

134-
With everything complete, you can run the file by entering `python authentication.py` from your project's directory. If everything went well you should see something similar to the following.
135-
141+
It is time to execute your Python script to verify functionality. Run the file from your project's directory with the command:
142+
```console
143+
python authentication.py
144+
```
145+
If successful, you see output similar to this:
136146
```Bash
137147
$ python authentication.py
138148
Retrieving new Access Token, using Service Principals
139-
Retrieved Access Token: ey...Q
149+
Retrieved Access Token: ...
140150
Sending SMS using using Service Principals
141151
SMS ID: ...
142152
Send Result Successful: true

0 commit comments

Comments
 (0)