CommunicationIdentityClient Class

Azure Communication Services Identity client.

Inheritance
builtins.object
CommunicationIdentityClient

Constructor

CommunicationIdentityClient(endpoint: str, credential: str, **kwargs: Any)

Parameters

endpoint
str
Required

The endpoint url for Azure Communication Service resource.

credential
Required

The credentials with which to authenticate. The value is an account shared access key

Examples


   : utf-8

   -------------------------------------------------------------------
   ght (c) Microsoft Corporation. All rights reserved.
   ed under the MIT License. See License.txt in the project root for
   e information.
   --------------------------------------------------------------------


   entity_sample.py
   ION:
   e samples demonstrate identity client samples.

   uthenticating a client via a connection string

   on identity_samples.py

   s

   mmunicationIdentityClientSamples(object):

   __init__(self):
   self.connection_string = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING')

   issue_token(self):
   from azure.communication.administration import CommunicationIdentityClient

   identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
   user = identity_client.create_user()
   tokenresponse = identity_client.issue_token(user, scopes=["chat"])
   print(tokenresponse)

   revoke_tokens(self):
   from azure.communication.administration import CommunicationIdentityClient

   identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
   user = identity_client.create_user()
   tokenresponse = identity_client.issue_token(user, scopes=["chat"])
   identity_client.revoke_tokens(user)
   print(tokenresponse)

   create_user(self):
   from azure.communication.administration import CommunicationIdentityClient
   identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
   user = identity_client.create_user()

   print(user.identifier)

   delete_user(self):
   from azure.communication.administration import CommunicationIdentityClient
   identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)
   user = identity_client.create_user()
   identity_client.delete_user(user)

   e__ == '__main__':
   le = CommunicationIdentityClientSamples()
   le.create_user()
   le.delete_user()
   le.issue_token()
   le.revoke_tokens()

Methods

create_user

create a single Communication user

return: CommunicationUser rtype: ~azure.communication.administration.CommunicationUser

delete_user

Triggers revocation event for user and deletes all its data.

from_connection_string

Create CommunicationIdentityClient from a Connection String.

issue_token

Generates a new token for an identity.

revoke_tokens

Schedule revocation of all tokens of an identity.

create_user

create a single Communication user

return: CommunicationUser rtype: ~azure.communication.administration.CommunicationUser

create_user(**kwargs) -> azure.communication.administration._shared.models.CommunicationUser

delete_user

Triggers revocation event for user and deletes all its data.

delete_user(communication_user: CommunicationUser, **kwargs: Any) -> None

Parameters

communication_user
CommunicationUser
Required

Azure Communication User to delete

Returns

None

Return type

from_connection_string

Create CommunicationIdentityClient from a Connection String.

from_connection_string(conn_str: str, **kwargs: Any) -> CommunicationIdentityClient

Parameters

conn_str
str
Required

A connection string to an Azure Communication Service resource.

conn_str
Required

Returns

Instance of CommunicationIdentityClient.

Return type

<xref:azure.communication.CommunicationIdentityClient>

issue_token

Generates a new token for an identity.

issue_token(user: CommunicationUser, scopes: List[str], **kwargs: Any) -> CommunicationIdentityToken

Parameters

user
CommunicationUser
Required

Azure Communication User

scopes
list[str]
Required

List of scopes to be added to the token.

Returns

CommunicationIdentityToken

Return type

revoke_tokens

Schedule revocation of all tokens of an identity.

revoke_tokens(user: CommunicationUser, issued_before: Optional[datetime.datetime] = None, **kwargs: Any) -> None

Parameters

user
<xref:azure.communication.administration.CommunicationUser.>
Required

Azure Communication User.

issued_before
<xref:datetime.datetime.>
Required

All tokens that are issued prior to this time should get revoked.

Returns

None

Return type