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/includes/managed-identity/managed-identity-js.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@
5
5
Open your terminal or command window create a new directory for your app, and navigate to it.
6
6
7
7
```console
8
-
mkdir managed-identity-quickstart && cd managed-identity--quickstart
8
+
mkdir managed-identity-quickstart && cd managed-identity-quickstart
9
9
```
10
10
11
11
Run `npm init -y` to create a **package.json** file with default settings.
@@ -44,7 +44,7 @@ We'll be using the [DefaultAzureCredential](/javascript/api/@azure/identity/defa
44
44
constcredential=newDefaultAzureCredential();
45
45
```
46
46
47
-
## Create an identity and issue a token with Managed Identity
47
+
## Create an identity and issue a token with managed identities
48
48
49
49
Next, we'll write a function which creates a new identity and issues a token for this identity, we'll use this later to test our managed identity setup.
50
50
@@ -81,7 +81,7 @@ With our functions created we can now write a main function to call them and dem
81
81
asyncfunctionmain() {
82
82
// You can find your endpoint and access key from your resource in the Azure portal
83
83
// e.g. "https://<RESOURCE_NAME>.communication.azure.com";
Open and save a new file within your created folder called `managed-identity.py`, we'll be placing our code inside this file.
21
+
11
22
### Use the SDK packages
12
23
13
-
Add the following `import` to your code to use the Azure Identity.
24
+
Add the following `import`statements to the top of your file to use the SDKs that we installed.
14
25
15
26
```python
16
27
from azure.identity import DefaultAzureCredential
28
+
from azure.communication.identity import CommunicationIdentityClient
29
+
from azure.communication.sms import SmsClient
17
30
```
18
31
19
-
The examples below are using the [DefaultAzureCredential](/python/api/azure-identity/azure.identity.defaultazurecredential). This credential is suitable for production and development environments.
32
+
### Create a DefaultAzureCredential
20
33
21
-
To register application in the development environment and set up environment variables, see [Authorize access with managed identity](../managed-identity-from-cli.md)
34
+
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.
22
35
23
-
### Create an identity and issue a token
36
+
```python
37
+
credential = DefaultAzureCredential()
38
+
```
24
39
25
-
The following code example shows how to create a service client object with managed identity, then use the client to issue a token for a new user:
40
+
## Create an identity and issue a token with managed identities.
26
41
27
-
```python
28
-
from azure.communication.identity import CommunicationIdentityClient
42
+
Now we'll add code which uses the created credential, to issue a VoIP Access Token. We'll call this code later on:
print("Retrieving new Access Token, using Managed Identities");
123
+
result = create_identity_and_get_token(endpoint);
124
+
print(f'Retrieved Access Token: {result.token}');
125
+
126
+
print("Sending SMS using Managed Identities");
127
+
128
+
# You will need a phone number from your resource to send an SMS.
129
+
sms_result = send_sms(endpoint, "<FROM_NUMBER>", "<TO_NUMBER>", "Hello from Managed Identities");
130
+
print(f'SMS ID: {sms_result[0].message_id}');
131
+
print(f'Send Result Successful: {sms_result[0].successful}');
132
+
```
133
+
## Run the Program
134
+
135
+
With everything complete, you can run the file by entering `python managed-identity.py` from your project's directory. If everything went well you should see something similar to the following.
136
+
137
+
```Bash
138
+
$ python managed-identity.py
139
+
Retrieving new Access Token, using Managed Identities
Copy file name to clipboardExpand all lines: articles/communication-services/quickstarts/managed-identity.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,9 +20,9 @@ This quickstart shows you how to authorize access to the Identity and SMS SDKs f
20
20
## Prerequisites
21
21
22
22
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free)
23
-
- An active Azure Communication Services resource, see [create a Communication Services resource](../create-communication-resource.md) if you do not have one.
23
+
- An active Azure Communication Services resource, see [create a Communication Services resource](./create-communication-resource.md) if you do not have one.
24
24
- To send an SMS you will need a [Phone Number](./telephony-sms/get-phone-number.md).
25
-
- A setup managed identity for a development environment, see [Authorize access with managed identity](../managed-identity-from-cli.md)
25
+
- A setup managed identity for a development environment, see [Authorize access with managed identity](./managed-identity-from-cli.md)
0 commit comments