Skip to content

Commit 9c65b7a

Browse files
Fixed identity samples (Azure#18046)
1 parent f241e37 commit 9c65b7a

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

sdk/communication/azure-communication-identity/samples/identity_samples.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
DESCRIPTION:
1212
These samples demonstrate creating a user, issuing a token, revoking a token and deleting a user.
1313
14-
///authenticating a client via a connection string
1514
USAGE:
1615
python identity_samples.py
1716
Set the environment variables with your own values before running the sample:
1817
1) AZURE_COMMUNICATION_SERVICE_ENDPOINT - Communication Service endpoint url
18+
2) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - the connection string in your ACS account
19+
3) AZURE_CLIENT_ID - the client ID of your active directory application
20+
4) AZURE_CLIENT_SECRET - the secret of your active directory application
21+
5) AZURE_TENANT_ID - the tenant ID of your active directory application
1922
"""
2023
import os
2124

@@ -40,7 +43,7 @@ def get_token(self):
4043
else:
4144
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
4245
user = identity_client.create_user()
43-
print("Getting token for: " + user.properties['id'])
46+
print("Getting token for: " + user.identifier)
4447
tokenresponse = identity_client.get_token(user, scopes=[CommunicationTokenScope.CHAT])
4548
print("Token issued with value: " + tokenresponse.token)
4649

@@ -71,7 +74,7 @@ def create_user(self):
7174
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
7275
print("Creating new user")
7376
user = identity_client.create_user()
74-
print("User created with id:" + user.properties['id'])
77+
print("User created with id:" + user.identifier)
7578

7679
def create_user_and_token(self):
7780
from azure.communication.identity import (
@@ -85,7 +88,7 @@ def create_user_and_token(self):
8588
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
8689
print("Creating new user with token")
8790
user, tokenresponse = identity_client.create_user_and_token(scopes=[CommunicationTokenScope.CHAT])
88-
print("User created with id:" + user.properties['id'])
91+
print("User created with id:" + user.identifier)
8992
print("Token issued with value: " + tokenresponse.token)
9093

9194
def delete_user(self):
@@ -97,9 +100,9 @@ def delete_user(self):
97100
else:
98101
identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
99102
user = identity_client.create_user()
100-
print("Deleting user: " + user.properties['id'])
103+
print("Deleting user: " + user.identifier)
101104
identity_client.delete_user(user)
102-
print(user.properties['id'] + " deleted")
105+
print(user.identifier + " deleted")
103106

104107
if __name__ == '__main__':
105108
sample = CommunicationIdentityClientSamples()

sdk/communication/azure-communication-identity/samples/identity_samples_async.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
DESCRIPTION:
1212
These async samples demonstrate creating a user, issuing a token, revoking a token and deleting a user.
1313
14-
///authenticating a client via a connection string
1514
USAGE:
1615
python identity_samples_async.py
1716
Set the environment variables with your own values before running the sample:
1817
1) AZURE_COMMUNICATION_SERVICE_ENDPOINT - Communication Service endpoint url
18+
2) AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING - the connection string in your ACS account
19+
3) AZURE_CLIENT_ID - the client ID of your active directory application
20+
4) AZURE_CLIENT_SECRET - the secret of your active directory application
21+
5) AZURE_TENANT_ID - the tenant ID of your active directory application
1922
"""
2023

2124
import asyncio
@@ -42,7 +45,7 @@ async def get_token(self):
4245

4346
async with identity_client:
4447
user = await identity_client.create_user()
45-
print("Issuing token for: " + user.properties['id'])
48+
print("Issuing token for: " + user.identifier)
4649
tokenresponse = await identity_client.get_token(user, scopes=[CommunicationTokenScope.CHAT])
4750
print("Token issued with value: " + tokenresponse.token)
4851

@@ -73,7 +76,7 @@ async def create_user(self):
7376
async with identity_client:
7477
print("Creating new user")
7578
user = await identity_client.create_user()
76-
print("User created with id:" + user.properties['id'])
79+
print("User created with id:" + user.identifier)
7780

7881
async def create_user_and_token(self):
7982
from azure.communication.identity.aio import CommunicationIdentityClient
@@ -87,7 +90,7 @@ async def create_user_and_token(self):
8790
async with identity_client:
8891
print("Creating new user with token")
8992
user, tokenresponse = await identity_client.create_user_and_token(scopes=[CommunicationTokenScope.CHAT])
90-
print("User created with id:" + user.properties['id'])
93+
print("User created with id:" + user.identifier)
9194
print("Token issued with value: " + tokenresponse.token)
9295

9396
async def delete_user(self):
@@ -100,9 +103,9 @@ async def delete_user(self):
100103

101104
async with identity_client:
102105
user = await identity_client.create_user()
103-
print("Deleting user: " + user.properties['id'])
106+
print("Deleting user: " + user.identifier)
104107
await identity_client.delete_user(user)
105-
print(user.properties['id'] + " deleted")
108+
print(user.identifier + " deleted")
106109

107110
async def main():
108111
sample = CommunicationIdentityClientSamples()

0 commit comments

Comments
 (0)