Skip to content

Commit 36fbec5

Browse files
authored
updating with a simpler solution by initializing identity correctly
Initialize identity correctly with: # Issue an identity and an access token with the "voip" scope for the new identity identity_token_result = client.create_user_and_token(["voip"]) identity = identity_token_result[0]
1 parent d212e45 commit 36fbec5

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

articles/communication-services/quickstarts/includes/user-access-token-python.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: tomaschladek
66
manager: nmurav
77
ms.service: azure-communication-services
88
ms.subservice: azure-communication-services
9-
ms.date: 09/12/2021
9+
ms.date: 09/13/2021
1010
ms.topic: include
1111
ms.custom: include file
1212
ms.author: tchladek
@@ -104,10 +104,10 @@ Use the `create_user_and_token` method to create a Communication Services identi
104104
```python
105105
# Issue an identity and an access token with the "voip" scope for the new identity
106106
identity_token_result = client.create_user_and_token(["voip"])
107-
identity = identity_token_result[0].properties['id']
107+
identity = identity_token_result[0]
108108
token = identity_token_result[1].token
109109
expires_on = identity_token_result[1].expires_on.strftime("%d/%m/%y %I:%M %S %p")
110-
print("\nCreated an identity with ID: " + identity)
110+
print("\nCreated an identity with ID: " + identity.properties['id'])
111111
print("\nIssued an access token with 'voip' scope that expires at " + expires_on + ":")
112112
print(token)
113113
```
@@ -119,25 +119,25 @@ To refresh an access token, use the `CommunicationUserIdentifier` object to reis
119119
```python
120120
# Value existingIdentity represents identity of Azure Communication Services stored during identity creation
121121
identity = CommunicationUserIdentifier(existingIdentity)
122-
token_result = client.get_token( identity, ["voip"])
122+
token_result = client.get_token(identity, ["voip"])
123123
```
124124

125125
## Revoke access tokens
126126

127127
In some cases, you may explicitly revoke access tokens. For example, when an application's user changes the password they use to authenticate to your service. Method `revoke_tokens` invalidates all active access tokens, that were issued to the identity.
128128

129129
```python
130-
client.revoke_tokens(identity_token_result[0])
131-
print("\nSuccessfully revoked all access tokens for identity with ID: " + identity)
130+
client.revoke_tokens(identity)
131+
print("\nSuccessfully revoked all access tokens for identity with ID: " + identity.properties['id'])
132132
```
133133

134134
## Delete an identity
135135

136136
Deleting an identity revokes all active access tokens and prevents you from issuing access tokens for the identity. It also removes all the persisted content associated with the identity.
137137

138138
```python
139-
client.delete_user(identity_token_result[0])
140-
print("\nDeleted the identity with ID: " + identity)
139+
client.delete_user(identity)
140+
print("\nDeleted the identity with ID: " + identity.properties['id'])
141141
```
142142

143143
## Run the code

0 commit comments

Comments
 (0)