Skip to content

Commit

Permalink
Merge pull request #2 from beltr0n/bertong-identity-redesign
Browse files Browse the repository at this point in the history
Update the async client to reflect swagger api changes
  • Loading branch information
lsundaralingam authored Jan 19, 2021
2 parents 59fbe7d + 4b65fe9 commit 65e3f3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from ._phone_numbers_client import PhoneNumbersClient

from ._identity._generated.models import (
CommunicationTokenRequest,
CommunicationIdentityToken
CommunicationIdentityAccessTokenRequest,
CommunicationIdentityAccessToken
)

from ._phonenumber._generated.models import (
Expand All @@ -36,8 +36,8 @@
'PhoneNumbersClient',

# from _identity
'CommunicationTokenRequest',
'CommunicationIdentityToken',
'CommunicationIdentityAccessTokenRequest',
'CommunicationIdentityAccessToken',

# from _phonenumber
'AcquiredPhoneNumber',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

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

from .._shared.utils import parse_connection_str, get_authentication_policy
from .._shared.models import CommunicationUser
Expand Down Expand Up @@ -84,13 +84,35 @@ async def create_user(self, **kwargs):
# type: (...) -> CommunicationUser
"""create a single Communication user
return: CommunicationUser
rtype: ~azure.communication.administration.CommunicationUser
:return: CommunicationUser
:rtype: ~azure.communication.administration.CommunicationUser
"""
return await self._identity_service_client.communication_identity.create(
return await self._identity_service_client.communication_identity.create_identity(
cls=lambda pr, u, e: CommunicationUser(u.id),
**kwargs)

@distributed_trace_async
async def create_user_with_token(
self,
scopes, # type: List[Union[str, "_model.CommunicationIdentityTokenScope"]]
**kwargs
):
# type: (...) -> Tuple[CommunicationUser, CommunicationIdentityAccessToken]
"""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.administration.models.CommunicationIdentityTokenScope]
:return: A tuple of a CommunicationUser and a CommunicationIdentityAccessToken.
:rtype: tuple of (~azure.communication.administration.CommunicationUser, ~azure.communication.administration.CommunicationIdentityAccessToken)
"""
return await self._identity_service_client.communication_identity.create_identity(
create_token_with_scopes=scopes,
cls=lambda pr, u, e: CommunicationUser(u.id),
**kwargs)
pass

@distributed_trace_async
async def delete_user(
self,
Expand All @@ -106,28 +128,29 @@ async def delete_user(
:return: None
:rtype: None
"""
await self._identity_service_client.communication_identity.delete(
await self._identity_service_client.communication_identity.delete_identity(
communication_user.identifier, **kwargs)

@distributed_trace_async
async def issue_token(
self,
user, # type: CommunicationUser
scopes, # type: List[str]
scopes, # type: List[Union[str, "_model.CommunicationIdentityTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> CommunicationIdentityToken
# type: (...) -> CommunicationIdentityAccessToken
"""Generates a new token for an identity.
:param user: Azure Communication User
:type user: ~azure.communication.administration.CommunicationUser
:param scopes:
List of scopes to be added to the token.
:type scopes: list[str]
:return: CommunicationIdentityToken
:rtype: ~azure.communication.administration.CommunicationIdentityToken
:type scopes: list[str or
~azure.communication.administration.models.CommunicationIdentityTokenScope]
:return: CommunicationIdentityAccessToken
:rtype: ~azure.communication.administration.CommunicationIdentityAccessToken
"""
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 +159,18 @@ async def issue_token(
async def revoke_tokens(
self,
user, # type: CommunicationUser
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.administration.CommunicationUser
: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 Down

0 comments on commit 65e3f3a

Please sign in to comment.