Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from .._generated.aio._communication_identity_client\
import CommunicationIdentityClient as CommunicationIdentityClientGen
from .._generated.models import CommunicationIdentityToken
from .._generated.models import CommunicationUserToken

from .._shared.utils import parse_connection_str, get_authentication_policy
from .._shared.models import CommunicationUserIdentifier
Expand Down Expand Up @@ -64,7 +64,7 @@ def from_connection_string(
:param str conn_str:
A connection string to an Azure Communication Service resource.
:returns: Instance of CommunicationIdentityClient.
:rtype: ~azure.communication.aio.CommunicationIdentityClient
:rtype: ~azure.communication.identity.aio.CommunicationIdentityClient

.. admonition:: Example:

Expand All @@ -84,13 +84,34 @@ async def create_user(self, **kwargs):
# type: (...) -> CommunicationUserIdentifier
"""create a single Communication user

return: CommunicationUserIdentifier
rtype: ~azure.communication.identity.CommunicationUserIdentifier
:return: CommunicationUserIdentifier
:rtype: ~azure.communication.identity.CommunicationUserIdentifier
"""
return await self._identity_service_client.communication_identity.create(
cls=lambda pr, u, e: CommunicationUserIdentifier(u.id),
**kwargs)

@distributed_trace_async
async def create_user_with_token(
self,
scopes, # type: List[Union[str, "_model.CommunicationTokenScope"]]
**kwargs
):
# type: (...) -> Tuple[CommunicationUserIdentifier, CommunicationUserToken]
"""create a single Communication user along with an Identity Token

:param scopes:
List of scopes to be added to the token.
:type scopes: list[str or
~azure.communication.identity.models.CommunicationTokenScope]
:return: A tuple of a CommunicationUserIdentifier and a CommunicationUserToken.
:rtype: tuple of (~azure.communication.identity.CommunicationUserIdentifier, ~azure.communication.identity.CommunicationUserToken)
"""
return await self._identity_service_client.communication_identity.create(
create_token_with_scopes=scopes,
cls=lambda pr, u, e: CommunicationUserIdentifier(u.id),
**kwargs)

@distributed_trace_async
async def delete_user(
self,
Expand All @@ -113,21 +134,22 @@ async def delete_user(
async def issue_token(
self,
user, # type: CommunicationUserIdentifier
scopes, # type: List[str]
scopes, # type: List[Union[str, "_model.CommunicationTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> CommunicationIdentityToken
# type: (...) -> CommunicationUserToken
"""Generates a new token for an identity.

:param user: Azure Communication User
:type user: ~azure.communication.identity.CommunicationUserIdentifier
:param scopes:
List of scopes to be added to the token.
:type scopes: list[str]
:return: CommunicationIdentityToken
:rtype: ~azure.communication.identity.CommunicationIdentityToken
:type scopes: list[str or
~azure.communication.identity.models.CommunicationTokenScope]
:return: CommunicationUserToken
:rtype: ~azure.communication.identity.CommunicationUserToken
"""
return await self._identity_service_client.communication_identity.issue_token(
return await self._identity_service_client.communication_identity.issue_access_token(
user.identifier,
scopes,
**kwargs)
Expand All @@ -136,22 +158,18 @@ async def issue_token(
async def revoke_tokens(
self,
user, # type: CommunicationUserIdentifier
issued_before=None, # type: Optional[datetime.datetime]
**kwargs # type: Any
):
# type: (...) -> None
"""Schedule revocation of all tokens of an identity.

:param user: Azure Communication User.
:type user: ~azure.communication.identity.CommunicationUserIdentifier
:param issued_before: All tokens that are issued prior to this time should get revoked.
:type issued_before: ~datetime.datetime
:return: None
:rtype: None
"""
return await self._identity_service_client.communication_identity.update(
return await self._identity_service_client.communication_identity.revoke_access_tokens(
user.identifier if user else None,
tokens_valid_from=issued_before,
**kwargs)

async def __aenter__(self) -> "CommunicationIdentityClient":
Expand All @@ -163,6 +181,6 @@ async def __aexit__(self, *args: "Any") -> None:

async def close(self) -> None:
"""Close the :class:
`~azure.communication.administration.aio.CommunicationIdentityClient` session.
`~azure.communication.identity.aio.CommunicationIdentityClient` session.
"""
await self._identity_service_client.__aexit__()