azure.communication.identity package¶
-
class
azure.communication.identity.
CommunicationIdentityClient
(endpoint: str, credential: str, **kwargs: Any)[source]¶ Azure Communication Services Identity client.
- Parameters
endpoint (str) – The endpoint url for Azure Communication Service resource.
credential – The credentials with which to authenticate. The value is an account shared access key
Example:
: 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 creating a user, issuing a token, revoking a token and deleting a user. uthenticating a client via a connection string on identity_samples.py the environment variables with your own values before running the sample: ZURE_COMMUNICATION_SERVICE_ENDPOINT - Communication Service endpoint url s mmunicationIdentityClientSamples(object): __init__(self): self.connection_string = os.getenv('AZURE_COMMUNICATION_SERVICE_CONNECTION_STRING') self.endpoint = os.getenv('AZURE_COMMUNICATION_SERVICE_ENDPOINT') self.client_id = os.getenv('AZURE_CLIENT_ID') self.client_secret = os.getenv('AZURE_CLIENT_SECRET') self.tenant_id = os.getenv('AZURE_TENANT_ID') issue_token(self): from azure.communication.identity import ( CommunicationIdentityClient, CommunicationTokenScope ) if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) else: identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string) user = identity_client.create_user() print("Issuing token for: " + user.identifier) tokenresponse = identity_client.issue_token(user, scopes=[CommunicationTokenScope.CHAT]) print("Token issued with value: " + tokenresponse.token) revoke_tokens(self): from azure.communication.identity import ( CommunicationIdentityClient, CommunicationTokenScope ) if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) else: identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string) user = identity_client.create_user() tokenresponse = identity_client.issue_token(user, scopes=[CommunicationTokenScope.CHAT]) print("Revoking token: " + tokenresponse.token) identity_client.revoke_tokens(user) print(tokenresponse.token + " revoked successfully") create_user(self): from azure.communication.identity import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) else: identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string) print("Creating new user") user = identity_client.create_user() print("User created with id:" + user.identifier) create_user_with_token(self): from azure.communication.identity import ( CommunicationIdentityClient, CommunicationTokenScope ) if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) else: identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string) print("Creating new user with token") user, tokenresponse = identity_client.create_user_with_token(scopes=[CommunicationTokenScope.CHAT]) print("User created with id:" + user.identifier) print("Token issued with value: " + tokenresponse.token) delete_user(self): from azure.communication.identity import CommunicationIdentityClient if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None: from azure.identity import DefaultAzureCredential identity_client = CommunicationIdentityClient(self.endpoint, DefaultAzureCredential()) else: identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string) user = identity_client.create_user() print("Deleting user: " + user.identifier) identity_client.delete_user(user) print(user.identifier + " deleted") e__ == '__main__': le = CommunicationIdentityClientSamples() le.create_user() le.create_user_with_token() le.issue_token() le.revoke_tokens() le.delete_user()
-
create_user
(**kwargs) → azure.communication.identity._shared.models.CommunicationUserIdentifier[source]¶ create a single Communication user
- Returns
CommunicationUserIdentifier
- Return type
-
create_user_with_token
(scopes: List[Union[str, ‘_model.CommunicationTokenScope’]], **kwargs: Any) → Tuple[CommunicationUserIdentifier, AccessToken][source]¶ create a single Communication user with an identity token. :param scopes:
List of scopes to be added to the token.
- Returns
A tuple of a CommunicationUserIdentifier and a AccessToken.
- Return type
tuple of (CommunicationUserIdentifier, AccessToken)
-
delete_user
(communication_user: CommunicationUserIdentifier, **kwargs: Any) → None[source]¶ Triggers revocation event for user and deletes all its data.
- Parameters
communication_user (CommunicationUserIdentifier) – Azure Communication User to delete
- Returns
None
- Return type
-
classmethod
from_connection_string
(conn_str: str, **kwargs: Any) → CommunicationIdentityClient[source]¶ Create CommunicationIdentityClient from a Connection String.
- Parameters
conn_str (str) – A connection string to an Azure Communication Service resource.
- Returns
Instance of CommunicationIdentityClient.
- Return type
Example:
-
issue_token
(user: CommunicationUserIdentifier, scopes, **kwargs: Any) → AccessToken[source]¶ Generates a new token for an identity.
- Parameters
user (CommunicationUserIdentifier) – Azure Communication User
scopes (list[str or CommunicationTokenScope]) – List of scopes to be added to the token.
- Returns
AccessToken
- Return type
-
class
azure.communication.identity.
CommunicationTokenScope
[source]¶ List of scopes for an access token.
-
CHAT
= 'chat'¶
-
VOIP
= 'voip'¶
-
-
class
azure.communication.identity.
CommunicationUserIdentifier
(identifier)[source]¶ Represents a user in Azure Communication Service. :ivar identifier: Communication user identifier. :vartype identifier: str :param identifier: Identifier to initialize CommunicationUserIdentifier. :type identifier: str