{"id":9539,"library":"azure-communication-identity","title":"Azure Communication Identity Client","description":"The `azure-communication-identity` library provides client-side functionality for managing user identities and issuing access tokens for Azure Communication Services. It allows applications to create, delete, and manage users, and to generate tokens required for client-side authentication with various communication functionalities like chat and calling. The current version is 1.5.0, and new versions are released regularly as part of the broader Azure SDK for Python, typically every 1-2 months or as features/fixes dictate.","status":"active","version":"1.5.0","language":"en","source_language":"en","source_url":"https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/communication/azure-communication-identity","tags":["azure","communication","identity","auth","sdk","cloud"],"install":[{"cmd":"pip install azure-communication-identity","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"CommunicationIdentityClient","correct":"from azure.communication.identity import CommunicationIdentityClient"},{"note":"Starting from version 1.4.0, CommunicationTokenScope was moved to the `models` submodule.","wrong":"from azure.communication.identity import CommunicationTokenScope","symbol":"CommunicationTokenScope","correct":"from azure.communication.identity.models import CommunicationTokenScope"}],"quickstart":{"code":"import os\nfrom azure.communication.identity import CommunicationIdentityClient\nfrom azure.communication.identity.models import CommunicationTokenScope\n\n# Set the COMMUNICATION_SERVICES_CONNECTION_STRING environment variable\n# Example: 'endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>'\nconnection_string = os.environ.get(\n    \"COMMUNICATION_SERVICES_CONNECTION_STRING\",\n    \"endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>\"\n)\n\nif \"endpoint=\" not in connection_string or \"accesskey=\" not in connection_string:\n    print(\"Error: COMMUNICATION_SERVICES_CONNECTION_STRING not set or invalid.\")\n    print(\"Please ensure it contains 'endpoint=' and 'accesskey='.\")\n    exit(1)\n\ntry:\n    client = CommunicationIdentityClient.from_connection_string(connection_string)\n    print(\"CommunicationIdentityClient initialized.\")\n\n    # Create a new identity\n    user = client.create_user()\n    print(f\"Created identity with ID: {user.communication_user_id}\")\n\n    # Issue an access token for the identity\n    token_response = client.get_token(\n        user, \n        scopes=[CommunicationTokenScope.CHAT, CommunicationTokenScope.VOIP]\n    )\n    print(f\"Issued token (partial): {token_response.token[:10]}...{token_response.token[-10:]}\")\n    print(f\"Token expires on: {token_response.expires_on}\")\n\n    # Clean up: Delete the created identity (optional, but good for cost management)\n    # client.delete_user(user)\n    # print(f\"Deleted identity: {user.communication_user_id}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the `CommunicationIdentityClient`, create a new user identity, and issue an access token for that identity with specific scopes (e.g., chat and VoIP). It requires the `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable to be set, containing your Azure Communication Services resource's endpoint and access key. Identities incur costs, so consider deleting them after use if they are temporary."},"warnings":[{"fix":"Update your code to use `from azure.communication.identity import CommunicationIdentityClient` and instantiate this class.","message":"The client class name changed from `CommunicationUserTokenClient` (in preview versions) to `CommunicationIdentityClient`.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Replace calls to `client.issue_token(...)` with `client.get_token(...)`.","message":"The method for issuing tokens was renamed from `issue_token` to `get_token`.","severity":"breaking","affected_versions":">=1.3.0"},{"fix":"Update your import statement from `from azure.communication.identity import CommunicationTokenScope` to `from azure.communication.identity.models import CommunicationTokenScope`.","message":"The `CommunicationTokenScope` enum moved from the main package namespace to the `models` submodule.","severity":"breaking","affected_versions":">=1.4.0"},{"fix":"Implement proper lifecycle management, including calling `client.delete_user(user)` when an identity is no longer required.","message":"Azure Communication Service identities incur costs. Ensure you delete identities when they are no longer needed to avoid unexpected charges.","severity":"gotcha","affected_versions":"All"},{"fix":"Verify the connection string obtained from the Azure portal, ensuring both 'endpoint=' and 'accesskey=' components are present and correctly formatted.","message":"The connection string format must be exact: `endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>`. Missing parts or incorrect delimiters will lead to authentication errors.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run: `pip install azure-communication-identity`","cause":"The package `azure-communication-identity` is not installed in your Python environment.","error":"ModuleNotFoundError: No module named 'azure.communication.identity'"},{"fix":"Update your code to use `client.get_token(user, scopes=[...])` instead of `client.issue_token(...)`.","cause":"The method `issue_token` was renamed to `get_token` in version 1.3.0.","error":"AttributeError: 'CommunicationIdentityClient' object has no attribute 'issue_token'"},{"fix":"Double-check your `COMMUNICATION_SERVICES_CONNECTION_STRING` environment variable or hardcoded string against the format `endpoint=https://<your-resource>.communication.azure.com/;accesskey=<your-access-key>`.","cause":"The provided connection string is malformed or missing required components like 'endpoint' or 'accesskey'.","error":"ValueError: Connection string is not in valid format."},{"fix":"Change your import statement to `from azure.communication.identity.models import CommunicationTokenScope`.","cause":"Starting from version 1.4.0, `CommunicationTokenScope` was moved to the `models` submodule.","error":"ImportError: cannot import name 'CommunicationTokenScope' from 'azure.communication.identity'"}]}