Skip to main content

Microsoft Azure Communication Identity Service Client Library for Python

Project description

Azure Communication Identity Package client library for Python

Azure Communication Identity client package is intended to be used to setup the basics for opening a way to use Azure Communication Service offerings. This package helps to create identity user tokens to be used by other client packages such as chat, calling, sms.

Source code | Package (Pypi) | API reference documentation | Product documentation

Getting started

Prerequisites

Install the package

Install the Azure Communication Identity client library for Python with pip:

pip install azure-communication-identity

Key concepts

CommunicationIdentityClient

CommunicationIdentityClient provides operations for:

  • Create/delete identities to be used in Azure Communication Services. Those identities can be used to make use of Azure Communication offerings and can be scoped to have limited abilities through token scopes.

  • Create/revoke scoped user access tokens to access services such as chat, calling, sms. Tokens are issued for a valid Azure Communication identity and can be revoked at any time.

Initializing Identity Client

# You can find your endpoint and access token from your resource in the Azure Portal
import os
from azure.communication.identity import CommunicationIdentityClient
from azure.identity import DefaultAzureCredential

connection_str = "endpoint=ENDPOINT;accessKey=KEY"
endpoint = "https://<RESOURCE_NAME>.communication.azure.com"

# To use Azure Active Directory Authentication (DefaultAzureCredential) make sure to have
# AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET as env variables.
identity_client_managed_identity = CommunicationIdentityClient(endpoint, DefaultAzureCredential())

#You can also authenticate using your connection string
identity_client = CommunicationIdentityClient.from_connection_string(connection_str)

Examples

The following section provides several code snippets covering some of the most common Azure Communication Services tasks, including:

Creating a new user

Use the create_user method to create a new user.

user = identity_client.create_user()
print("User created with id:" + user.properties['id'])

Issuing or Refreshing an access token for a user

Use the get_token method to issue or refresh a scoped access token for the user.
Pass in the user object as a parameter, and a list of CommunicationTokenScope. Scope options are:

  • CHAT (Chat)
  • VOIP (VoIP)
tokenresponse = identity_client.get_token(user, scopes=[CommunicationTokenScope.CHAT])
print("Token issued with value: " + tokenresponse.token)

Creating a user and a token in a single request

For convenience, use create_user_and_token to create a new user and issue a token with one function call. This translates into a single web request as opposed to creating a user first and then issuing a token.

user, tokenresponse = identity_client.create_user_and_token(scopes=[CommunicationTokenScope.CHAT])
print("User id:" + user.properties['id'])
print("Token issued with value: " + tokenresponse.token)

Revoking a user's access tokens

Use revoke_tokens to revoke all access tokens for a user. Pass in the user object as a parameter

identity_client.revoke_tokens(user)

Deleting a user

Use the delete_user method to delete a user. Pass in the user object as a parameter

identity_client.delete_user(user)

Troubleshooting

The Azure Communication Service Identity client will raise exceptions defined in Azure Core.

Next steps

More sample code

Please take a look at the samples directory for detailed examples of how to use this library to manage identities and tokens.

Provide Feedback

If you encounter any bugs or have suggestions, please file an issue in the Issues section of the project

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

azure-communication-identity-1.0.1.zip (57.5 kB view details)

Uploaded Source

Built Distribution

azure_communication_identity-1.0.1-py2.py3-none-any.whl (34.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file azure-communication-identity-1.0.1.zip.

File metadata

  • Download URL: azure-communication-identity-1.0.1.zip
  • Upload date:
  • Size: 57.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for azure-communication-identity-1.0.1.zip
Algorithm Hash digest
SHA256 e94c0aa2f4dab1d661254f81ce42f08212d932f03c380f8011bd7be4acb8aac6
MD5 d4649b990f9be2de2accf2a6bce9e490
BLAKE2b-256 0ecb4a44a876dd596ba0de9fa6cb96b0003fd8b9ada5588372e46a6f47576bc9

See more details on using hashes here.

File details

Details for the file azure_communication_identity-1.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: azure_communication_identity-1.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 34.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.0 CPython/3.9.5

File hashes

Hashes for azure_communication_identity-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 40743bdbe30c5f58817bf54b4f2e05f3ede4f98e99bf5bfe91984b32e2590a73
MD5 c94a58501fa38a8cbe658e1017e114ea
BLAKE2b-256 4a59cd2a6f04ed019fc524ed3b386e4d5deb8f6e222f84705d0ff7a063b698e9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page