34
34
35
35
class CommunicationIdentityClientSamples (object ):
36
36
def __init__ (self ):
37
- self .connection_string = os .getenv ("COMMUNICATION_SAMPLES_CONNECTION_STRING" )
37
+ self .connection_string = os .getenv ("COMMUNICATION_SAMPLES_CONNECTION_STRING" , "" )
38
38
self .endpoint = os .getenv ("AZURE_COMMUNICATION_SERVICE_ENDPOINT" )
39
39
self .client_id = os .getenv ("AZURE_CLIENT_ID" )
40
40
self .client_secret = os .getenv ("AZURE_CLIENT_SECRET" )
41
41
self .tenant_id = os .getenv ("AZURE_TENANT_ID" )
42
- self .m365_client_id = os .getenv ("COMMUNICATION_M365_APP_ID" )
42
+ self .m365_client_id = os .getenv ("COMMUNICATION_M365_APP_ID" , "" )
43
43
self .m365_aad_authority = os .getenv ("COMMUNICATION_M365_AAD_AUTHORITY" )
44
44
self .m365_aad_tenant = os .getenv ("COMMUNICATION_M365_AAD_TENANT" )
45
45
self .msal_username = os .getenv ("COMMUNICATION_MSAL_USERNAME" )
@@ -67,11 +67,11 @@ async def get_token(self):
67
67
68
68
async with identity_client :
69
69
user = await identity_client .create_user ()
70
- print ("Issuing token for: " + user .properties .get ("id" ) )
70
+ print (f "Issuing token for: { user .properties .get ('id' ) } " )
71
71
tokenresponse = await identity_client .get_token (
72
72
user , scopes = [CommunicationTokenScope .CHAT ]
73
73
)
74
- print ("Token issued with value: " + tokenresponse .token )
74
+ print (f "Token issued with value: { tokenresponse .token } " )
75
75
76
76
async def get_token_with_custom_expiration (self ):
77
77
from azure .communication .identity .aio import CommunicationIdentityClient
@@ -95,14 +95,14 @@ async def get_token_with_custom_expiration(self):
95
95
96
96
async with identity_client :
97
97
user = await identity_client .create_user ()
98
- print ("Issuing token for: " + user .properties .get ("id" ) )
98
+ print (f "Issuing token for: { user .properties .get ('id' ) } " )
99
99
token_expires_in = timedelta (hours = 1 )
100
100
tokenresponse = await identity_client .get_token (
101
101
user ,
102
102
scopes = [CommunicationTokenScope .CHAT ],
103
103
token_expires_in = token_expires_in ,
104
104
)
105
- print ("Issued token with custom expiration: " + tokenresponse .token )
105
+ print (f "Issued token with custom expiration: { tokenresponse .token } " )
106
106
107
107
async def revoke_tokens (self ):
108
108
from azure .communication .identity .aio import CommunicationIdentityClient
@@ -129,9 +129,9 @@ async def revoke_tokens(self):
129
129
tokenresponse = await identity_client .get_token (
130
130
user , scopes = [CommunicationTokenScope .CHAT ]
131
131
)
132
- print ("Revoking token: " + tokenresponse .token )
132
+ print (f "Revoking token: { tokenresponse .token } " )
133
133
await identity_client .revoke_tokens (user )
134
- print (tokenresponse .token + " revoked successfully" )
134
+ print (f" { tokenresponse .token } revoked successfully" )
135
135
136
136
async def create_user (self ):
137
137
from azure .communication .identity .aio import CommunicationIdentityClient
@@ -155,7 +155,7 @@ async def create_user(self):
155
155
async with identity_client :
156
156
print ("Creating new user" )
157
157
user = await identity_client .create_user ()
158
- print ("User created with id:" + user .properties .get ("id" ) )
158
+ print (f "User created with id: { user .properties .get ('id' ) } " )
159
159
160
160
async def create_user_and_token (self ):
161
161
from azure .communication .identity .aio import CommunicationIdentityClient
@@ -182,8 +182,8 @@ async def create_user_and_token(self):
182
182
user , tokenresponse = await identity_client .create_user_and_token (
183
183
scopes = [CommunicationTokenScope .CHAT ]
184
184
)
185
- print ("User created with id:" + user .properties .get ("id" ) )
186
- print ("Token issued with value: " + tokenresponse .token )
185
+ print (f "User created with id: { user .properties .get ('id' ) } " )
186
+ print (f "Token issued with value: { tokenresponse .token } " )
187
187
188
188
async def create_user_and_token_with_custom_expiration (self ):
189
189
from azure .communication .identity .aio import CommunicationIdentityClient
@@ -211,8 +211,8 @@ async def create_user_and_token_with_custom_expiration(self):
211
211
user , tokenresponse = await identity_client .create_user_and_token (
212
212
scopes = [CommunicationTokenScope .CHAT ], token_expires_in = token_expires_in
213
213
)
214
- print ("User created with id:" + user .properties .get ("id" ) )
215
- print ("Issued token with custom expiration: " + tokenresponse .token )
214
+ print (f "User created with id: { user .properties .get ('id' ) } " )
215
+ print (f "Issued token with custom expiration: { tokenresponse .token } " )
216
216
217
217
async def delete_user (self ):
218
218
from azure .communication .identity .aio import CommunicationIdentityClient
@@ -235,9 +235,9 @@ async def delete_user(self):
235
235
236
236
async with identity_client :
237
237
user = await identity_client .create_user ()
238
- print ("Deleting user: " + user .properties .get ("id" ) )
238
+ print (f "Deleting user: { user .properties .get ('id' ) } " )
239
239
await identity_client .delete_user (user )
240
- print (user .properties .get ("id" ) + " deleted" )
240
+ print (f" { user .properties .get ('id' ) } deleted" )
241
241
242
242
async def get_token_for_teams_user (self ):
243
243
if os .getenv ("SKIP_INT_IDENTITY_EXCHANGE_TOKEN_TEST" ) == "true" :
@@ -275,12 +275,12 @@ async def get_token_for_teams_user(self):
275
275
)
276
276
aad_token = result ["access_token" ]
277
277
teams_user_oid = result ["id_token_claims" ]["oid" ]
278
- print ("AAD access token of a Teams User: " + aad_token )
278
+ print (f "AAD access token of a Teams User: { aad_token } " )
279
279
280
280
tokenresponse = await identity_client .get_token_for_teams_user (
281
281
aad_token , self .m365_client_id , teams_user_oid
282
282
)
283
- print ("Token issued with value: " + tokenresponse .token )
283
+ print (f "Token issued with value: { tokenresponse .token } " )
284
284
285
285
286
286
async def main ():
0 commit comments