Skip to content

Commit

Permalink
Merge pull request #3 from lsundaralingam/communication-identity-rede…
Browse files Browse the repository at this point in the history
…sign-clone-personal

Use Azure.Core.AccessToken instead of CommunicationUserToken
  • Loading branch information
beltr0n authored Jan 29, 2021
2 parents 6e619e3 + b4e62f7 commit 745848a
Show file tree
Hide file tree
Showing 30 changed files with 274 additions and 274 deletions.
5 changes: 5 additions & 0 deletions sdk/communication/azure-communication-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

### Added
- Added CommunicationIdentityClient (originally was part of the azure.communication.administration package).
- Added ability to create a user and issue token for it at the same time.

### Breaking
- CommunicationIdentityClient.revoke_tokens now revoke all the currently issued tokens instead of revoking tokens issued prior to a given time.
- CommunicationIdentityClient.issue_tokens returns an instance of `azure.core.credentials.AccessToken` instead of `CommunicationUserToken`.

<!-- LINKS -->
[read_me]: https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/communication/azure-communication-identity/README.md
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from ._communication_identity_client import CommunicationIdentityClient

from ._generated.models import (
CommunicationUserToken,
CommunicationTokenScope
)

Expand All @@ -17,7 +16,6 @@
'CommunicationIdentityClient',

# from _identity
'CommunicationUserToken',
'CommunicationTokenScope',

# from _shared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
# ------------------------------------

from azure.core.tracing.decorator import distributed_trace
from azure.core.credentials import AccessToken

from ._generated._communication_identity_client\
import CommunicationIdentityClient as CommunicationIdentityClientGen
from ._generated.models import CommunicationUserToken
from ._shared.utils import parse_connection_str, get_authentication_policy
from ._shared.models import CommunicationUserIdentifier
from ._version import SDK_MONIKER
Expand Down Expand Up @@ -95,17 +95,18 @@ def create_user_with_token(
scopes, # type: List[Union[str, "_model.CommunicationTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> Tuple[CommunicationUserIdentifier, CommunicationUserToken]
# type: (...) -> Tuple[CommunicationUserIdentifier, AccessToken]
"""create a single Communication user 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 CommunicationUser and a CommunicationIdentityToken tuple.
:rtype: tuple of (~azure.communication.identity.CommunicationUser, \
~azure.communication.identity.CommunicationIdentityToken)
~azure.core.credentials.AccessToken)
"""
return self._identity_service_client.communication_identity.create(
cls=lambda pr, u, e: (CommunicationUserIdentifier(u.identity.id), u.access_token),
cls=lambda pr, u, e: (CommunicationUserIdentifier(u.identity.id),
AccessToken(u.access_token.token, u.access_token.expires_on)),
create_token_with_scopes=scopes,
**kwargs)

Expand Down Expand Up @@ -134,20 +135,21 @@ def issue_token(
scopes, # List[Union[str, "_model.CommunicationTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> CommunicationUserToken
# type: (...) -> AccessToken
"""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 or ~azure.communication.identity.models.CommunicationTokenScope]
:return: CommunicationUserToken
:rtype: ~azure.communication.identity.CommunicationUserToken
:return: AccessToken
:rtype: ~azure.core.credentials.AccessToken
"""
return self._identity_service_client.communication_identity.issue_access_token(
user.identifier,
scopes,
cls=lambda pr, u, e: AccessToken(u.token, u.expires_on),
**kwargs)

@distributed_trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def __init__(

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)

self.communication_identity = CommunicationIdentityOperations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._serialize.client_side_validation = False
self._deserialize = Deserializer(client_models)

self.communication_identity = CommunicationIdentityOperations(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ async def issue_access_token(
id: str,
scopes: List[Union[str, "_models.CommunicationTokenScope"]],
**kwargs
) -> "_models.CommunicationUserToken":
) -> "_models.CommunicationIdentityAccessToken":
"""Issue a new token for an identity.
Issue a new token for an identity.
Expand All @@ -228,11 +228,11 @@ async def issue_access_token(
:param scopes: List of scopes attached to the token.
:type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope]
:keyword callable cls: A custom type or function that will be passed the direct response
:return: CommunicationUserToken, or the result of cls(response)
:rtype: ~azure.communication.identity.models.CommunicationUserToken
:return: CommunicationIdentityAccessToken, or the result of cls(response)
:rtype: ~azure.communication.identity.models.CommunicationIdentityAccessToken
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationUserToken"]
cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationIdentityAccessToken"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down Expand Up @@ -272,7 +272,7 @@ async def issue_access_token(
error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, response)
raise HttpResponseError(response=response, model=error)

deserialized = self._deserialize('CommunicationUserToken', pipeline_response)
deserialized = self._deserialize('CommunicationIdentityAccessToken', pipeline_response)

if cls:
return cls(pipeline_response, deserialized, {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
from ._models_py3 import CommunicationError
from ._models_py3 import CommunicationErrorResponse
from ._models_py3 import CommunicationIdentity
from ._models_py3 import CommunicationIdentityAccessToken
from ._models_py3 import CommunicationIdentityAccessTokenRequest
from ._models_py3 import CommunicationIdentityAccessTokenResult
from ._models_py3 import CommunicationIdentityCreateRequest
from ._models_py3 import CommunicationUserToken
except (SyntaxError, ImportError):
from ._models import CommunicationError # type: ignore
from ._models import CommunicationErrorResponse # type: ignore
from ._models import CommunicationIdentity # type: ignore
from ._models import CommunicationIdentityAccessToken # type: ignore
from ._models import CommunicationIdentityAccessTokenRequest # type: ignore
from ._models import CommunicationIdentityAccessTokenResult # type: ignore
from ._models import CommunicationIdentityCreateRequest # type: ignore
from ._models import CommunicationUserToken # type: ignore

from ._communication_identity_client_enums import (
CommunicationTokenScope,
Expand All @@ -31,9 +31,9 @@
'CommunicationError',
'CommunicationErrorResponse',
'CommunicationIdentity',
'CommunicationIdentityAccessToken',
'CommunicationIdentityAccessTokenRequest',
'CommunicationIdentityAccessTokenResult',
'CommunicationIdentityCreateRequest',
'CommunicationUserToken',
'CommunicationTokenScope',
]
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,36 @@ def __init__(
self.id = kwargs['id']


class CommunicationIdentityAccessToken(msrest.serialization.Model):
"""An access token.
All required parameters must be populated in order to send to Azure.
:param token: Required. The access token issued for the identity.
:type token: str
:param expires_on: Required. The expiry time of the token.
:type expires_on: ~datetime.datetime
"""

_validation = {
'token': {'required': True},
'expires_on': {'required': True},
}

_attribute_map = {
'token': {'key': 'token', 'type': 'str'},
'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'},
}

def __init__(
self,
**kwargs
):
super(CommunicationIdentityAccessToken, self).__init__(**kwargs)
self.token = kwargs['token']
self.expires_on = kwargs['expires_on']


class CommunicationIdentityAccessTokenRequest(msrest.serialization.Model):
"""CommunicationIdentityAccessTokenRequest.
Expand Down Expand Up @@ -139,7 +169,7 @@ class CommunicationIdentityAccessTokenResult(msrest.serialization.Model):
:param identity: Required. A communication identity.
:type identity: ~azure.communication.identity.models.CommunicationIdentity
:param access_token: An access token.
:type access_token: ~azure.communication.identity.models.CommunicationUserToken
:type access_token: ~azure.communication.identity.models.CommunicationIdentityAccessToken
"""

_validation = {
Expand All @@ -148,7 +178,7 @@ class CommunicationIdentityAccessTokenResult(msrest.serialization.Model):

_attribute_map = {
'identity': {'key': 'identity', 'type': 'CommunicationIdentity'},
'access_token': {'key': 'accessToken', 'type': 'CommunicationUserToken'},
'access_token': {'key': 'accessToken', 'type': 'CommunicationIdentityAccessToken'},
}

def __init__(
Expand Down Expand Up @@ -178,33 +208,3 @@ def __init__(
):
super(CommunicationIdentityCreateRequest, self).__init__(**kwargs)
self.create_token_with_scopes = kwargs.get('create_token_with_scopes', None)


class CommunicationUserToken(msrest.serialization.Model):
"""An access token.
All required parameters must be populated in order to send to Azure.
:param token: Required. The access token issued for the identity.
:type token: str
:param expires_on: Required. The expiry time of the token.
:type expires_on: ~datetime.datetime
"""

_validation = {
'token': {'required': True},
'expires_on': {'required': True},
}

_attribute_map = {
'token': {'key': 'token', 'type': 'str'},
'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'},
}

def __init__(
self,
**kwargs
):
super(CommunicationUserToken, self).__init__(**kwargs)
self.token = kwargs['token']
self.expires_on = kwargs['expires_on']
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,39 @@ def __init__(
self.id = id


class CommunicationIdentityAccessToken(msrest.serialization.Model):
"""An access token.
All required parameters must be populated in order to send to Azure.
:param token: Required. The access token issued for the identity.
:type token: str
:param expires_on: Required. The expiry time of the token.
:type expires_on: ~datetime.datetime
"""

_validation = {
'token': {'required': True},
'expires_on': {'required': True},
}

_attribute_map = {
'token': {'key': 'token', 'type': 'str'},
'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'},
}

def __init__(
self,
*,
token: str,
expires_on: datetime.datetime,
**kwargs
):
super(CommunicationIdentityAccessToken, self).__init__(**kwargs)
self.token = token
self.expires_on = expires_on


class CommunicationIdentityAccessTokenRequest(msrest.serialization.Model):
"""CommunicationIdentityAccessTokenRequest.
Expand Down Expand Up @@ -152,7 +185,7 @@ class CommunicationIdentityAccessTokenResult(msrest.serialization.Model):
:param identity: Required. A communication identity.
:type identity: ~azure.communication.identity.models.CommunicationIdentity
:param access_token: An access token.
:type access_token: ~azure.communication.identity.models.CommunicationUserToken
:type access_token: ~azure.communication.identity.models.CommunicationIdentityAccessToken
"""

_validation = {
Expand All @@ -161,14 +194,14 @@ class CommunicationIdentityAccessTokenResult(msrest.serialization.Model):

_attribute_map = {
'identity': {'key': 'identity', 'type': 'CommunicationIdentity'},
'access_token': {'key': 'accessToken', 'type': 'CommunicationUserToken'},
'access_token': {'key': 'accessToken', 'type': 'CommunicationIdentityAccessToken'},
}

def __init__(
self,
*,
identity: "CommunicationIdentity",
access_token: Optional["CommunicationUserToken"] = None,
access_token: Optional["CommunicationIdentityAccessToken"] = None,
**kwargs
):
super(CommunicationIdentityAccessTokenResult, self).__init__(**kwargs)
Expand Down Expand Up @@ -196,36 +229,3 @@ def __init__(
):
super(CommunicationIdentityCreateRequest, self).__init__(**kwargs)
self.create_token_with_scopes = create_token_with_scopes


class CommunicationUserToken(msrest.serialization.Model):
"""An access token.
All required parameters must be populated in order to send to Azure.
:param token: Required. The access token issued for the identity.
:type token: str
:param expires_on: Required. The expiry time of the token.
:type expires_on: ~datetime.datetime
"""

_validation = {
'token': {'required': True},
'expires_on': {'required': True},
}

_attribute_map = {
'token': {'key': 'token', 'type': 'str'},
'expires_on': {'key': 'expiresOn', 'type': 'iso-8601'},
}

def __init__(
self,
*,
token: str,
expires_on: datetime.datetime,
**kwargs
):
super(CommunicationUserToken, self).__init__(**kwargs)
self.token = token
self.expires_on = expires_on
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def issue_access_token(
scopes, # type: List[Union[str, "_models.CommunicationTokenScope"]]
**kwargs # type: Any
):
# type: (...) -> "_models.CommunicationUserToken"
# type: (...) -> "_models.CommunicationIdentityAccessToken"
"""Issue a new token for an identity.
Issue a new token for an identity.
Expand All @@ -236,11 +236,11 @@ def issue_access_token(
:param scopes: List of scopes attached to the token.
:type scopes: list[str or ~azure.communication.identity.models.CommunicationTokenScope]
:keyword callable cls: A custom type or function that will be passed the direct response
:return: CommunicationUserToken, or the result of cls(response)
:rtype: ~azure.communication.identity.models.CommunicationUserToken
:return: CommunicationIdentityAccessToken, or the result of cls(response)
:rtype: ~azure.communication.identity.models.CommunicationIdentityAccessToken
:raises: ~azure.core.exceptions.HttpResponseError
"""
cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationUserToken"]
cls = kwargs.pop('cls', None) # type: ClsType["_models.CommunicationIdentityAccessToken"]
error_map = {
401: ClientAuthenticationError, 404: ResourceNotFoundError, 409: ResourceExistsError
}
Expand Down Expand Up @@ -280,7 +280,7 @@ def issue_access_token(
error = self._deserialize.failsafe_deserialize(_models.CommunicationErrorResponse, response)
raise HttpResponseError(response=response, model=error)

deserialized = self._deserialize('CommunicationUserToken', pipeline_response)
deserialized = self._deserialize('CommunicationIdentityAccessToken', pipeline_response)

if cls:
return cls(pipeline_response, deserialized, {})
Expand Down
Loading

0 comments on commit 745848a

Please sign in to comment.