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/communication-services/quickstarts/identity/includes/active-directory/service-principal-python.md
+24-14Lines changed: 24 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,26 +5,28 @@
5
5
6
6
### Create a new Python application
7
7
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:
9
9
10
10
```console
11
11
mkdir active-directory-authentication-quickstart && cd active-directory-authentication-quickstart
12
12
```
13
13
14
14
### Install the SDK packages
15
15
16
+
Next we need to install the required Azure SDK packages. Run these commands:
17
+
16
18
```console
17
19
pip install azure-identity
18
20
pip install azure-communication-identity
19
21
pip install azure-communication-sms
20
22
```
21
23
22
24
### 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.
24
26
25
27
### Use the SDK packages
26
28
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:
28
30
29
31
```python
30
32
from azure.identity import DefaultAzureCredential
@@ -34,15 +36,17 @@ from azure.communication.sms import SmsClient
34
36
35
37
### Create a DefaultAzureCredential
36
38
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:
38
42
39
43
```python
40
44
credential = DefaultAzureCredential()
41
45
```
42
46
43
47
## Create an identity and issue a token with service principals
44
48
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:
#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.
86
93
sms_result = send_sms(endpoint, "<FROM_NUMBER>", "<TO_NUMBER>", "Hello from Service Principals");
87
94
print(f'SMS ID: {sms_result[0].message_id}');
88
95
print(f'Send Result Successful: {sms_result[0].successful}');
89
96
```
90
97
91
-
The final `authentication.py`file should look something like this:
98
+
This is how the `authentication.py`looks after all changes you made:
92
99
93
100
```python
94
101
from azure.identity import DefaultAzureCredential
@@ -131,12 +138,15 @@ print(f'Send Result Successful: {sms_result[0].successful}');
131
138
```
132
139
## Run the program
133
140
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:
136
146
```Bash
137
147
$ python authentication.py
138
148
Retrieving new Access Token, using Service Principals
0 commit comments