def setUp(self):
        super(ChatThreadClientTestAsync, self).setUp()

        self.recording_processors.extend([
            BodyReplacerProcessor(keys=["id", "token", "senderId", "chatMessageId", "nextLink", "members", "multipleStatus", "value"]),
            URIIdentityReplacer(),
            ResponseReplacerProcessor(keys=[self._resource_name]),
            ChatURIReplacer()])

        endpoint, _ = parse_connection_str(self.connection_str)
        self.endpoint = endpoint

        self.identity_client = CommunicationIdentityClient.from_connection_string(self.connection_str)

        # create user
        self.user = self.identity_client.create_user()
        token_response = self.identity_client.issue_token(self.user, scopes=["chat"])
        self.token = token_response.token

        # create another user
        self.new_user = self.identity_client.create_user()

        # create ChatClient
        refresh_option = CommunicationTokenRefreshOptions(self.token)
        self.chat_client = ChatClient(self.endpoint, CommunicationTokenCredential(refresh_option))
コード例 #2
0
    async def get_token_for_teams_user(self):
        if (os.getenv("SKIP_INT_IDENTITY_EXCHANGE_TOKEN_TEST") == "true"):
            print("Skipping the Get Access Token for Teams User sample")
            return
        from azure.communication.identity.aio import CommunicationIdentityClient
        if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
            from azure.identity.aio import DefaultAzureCredential
            endpoint, _ = parse_connection_str(self.connection_string)
            identity_client = CommunicationIdentityClient(
                endpoint, DefaultAzureCredential())
        else:
            identity_client = CommunicationIdentityClient.from_connection_string(
                self.connection_string)

        async with identity_client:
            msal_app = PublicClientApplication(client_id=self.m365_app_id,
                                               authority="{}/{}".format(
                                                   self.m365_aad_authority,
                                                   self.m365_aad_tenant))
            result = msal_app.acquire_token_by_username_password(
                username=self.msal_username,
                password=self.msal_password,
                scopes=[self.m365_scope])
            add_token = result["access_token"]
            print("AAD access token of a Teams User: "******"AAD access token of a Teams User: "******"Token issued with value: " + tokenresponse.token)
コード例 #3
0
 def setUp(self):
     super(CommunicationIdentityTestCase, self).setUp()
     if self.is_playback():
         self.connection_str = "endpoint=https://sanitized/;accesskey=fake==="
         self.m365_app_id = "sanitized"
         self.m365_aad_authority = "sanitized"
         self.m365_aad_tenant = "sanitized"
         self.m365_scope = "sanitized"
         self.msal_username = "******"
         self.msal_password = "******"
         self.expired_teams_token = "sanitized"
         self.skip_get_token_for_teams_user_tests = "false"
     else:
         self.connection_str = os.getenv(
             'COMMUNICATION_LIVETEST_DYNAMIC_CONNECTION_STRING')
         self.m365_app_id = os.getenv('COMMUNICATION_M365_APP_ID')
         self.m365_aad_authority = os.getenv(
             'COMMUNICATION_M365_AAD_AUTHORITY')
         self.m365_aad_tenant = os.getenv('COMMUNICATION_M365_AAD_TENANT')
         self.m365_scope = os.getenv('COMMUNICATION_M365_SCOPE')
         self.msal_username = os.getenv('COMMUNICATION_MSAL_USERNAME')
         self.msal_password = os.getenv('COMMUNICATION_MSAL_PASSWORD')
         self.expired_teams_token = os.getenv(
             'COMMUNICATION_EXPIRED_TEAMS_TOKEN')
         endpoint, _ = parse_connection_str(self.connection_str)
         self._resource_name = endpoint.split(".")[0]
         self.scrubber.register_name_pair(self._resource_name, "sanitized")
         self.skip_get_token_for_teams_user_tests = os.getenv(
             'SKIP_INT_IDENTITY_EXCHANGE_TOKEN_TEST')
    def setUp(self):
        super(ChatClientTestAsync, self).setUp()

        self.recording_processors.extend([
            BodyReplacerProcessor(keys=[
                "id", "token", "createdBy", "participants", "multipleStatus",
                "value"
            ]),
            URIIdentityReplacer(),
            ResponseReplacerProcessor(keys=[self._resource_name]),
            ChatURIReplacer()
        ])

        endpoint, _ = parse_connection_str(self.connection_str)
        self.endpoint = endpoint

        self.identity_client = CommunicationIdentityClient.from_connection_string(
            self.connection_str)

        # create user
        self.user = self.identity_client.create_user()
        token_response = self.identity_client.get_token(self.user,
                                                        scopes=["chat"])
        self.token = token_response.token

        # create ChatClient
        self.chat_client = ChatClient(self.endpoint,
                                      CommunicationTokenCredential(self.token))
    def test_create_user_from_managed_identity(self, connection_string):
        endpoint, access_key = parse_connection_str(connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(endpoint, credential)
        user = identity_client.create_user()

        assert user.identifier is not None
    async def test_delete_user_from_managed_identity(self, communication_connection_string):
        endpoint, access_key = parse_connection_str(communication_connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(endpoint, credential) 
        async with identity_client:
            user = await identity_client.create_user()
            await identity_client.delete_user(user)

        assert user.properties.get('id') is not None
コード例 #7
0
    async def create_user(self):
        from azure.communication.identity.aio import CommunicationIdentityClient
        if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
            from azure.identity.aio import DefaultAzureCredential
            endpoint, _ = parse_connection_str(self.connection_string)
            identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
        else:
            identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)

        async with identity_client:
            print("Creating new user")
            user = await identity_client.create_user()
            print("User created with id:" + user.properties.get('id'))
    def test_issue_token_from_managed_identity(self, connection_string):
        endpoint, access_key = parse_connection_str(connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(endpoint, credential)
        user = identity_client.create_user()

        token_response = identity_client.issue_token(user, scopes=["chat"])

        assert user.identifier is not None
        assert token_response.token is not None
    async def test_get_token_from_managed_identity(self, communication_connection_string):
        endpoint, access_key = parse_connection_str(communication_connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(endpoint, credential) 
        async with identity_client:
            user = await identity_client.create_user()
            token_response = await identity_client.get_token(user, scopes=[CommunicationTokenScope.CHAT])

        assert user.properties.get('id') is not None
        assert token_response.token is not None
コード例 #10
0
    async def create_user_and_token(self):
        from azure.communication.identity.aio import CommunicationIdentityClient
        from azure.communication.identity import CommunicationTokenScope
        if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
            from azure.identity.aio import DefaultAzureCredential
            endpoint, _ = parse_connection_str(self.connection_string)
            identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
        else:
            identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)

        async with identity_client:
            print("Creating new user with token")
            user, tokenresponse = await identity_client.create_user_and_token(scopes=[CommunicationTokenScope.CHAT])
            print("User created with id:" + user.properties.get('id'))
            print("Token issued with value: " + tokenresponse.token)
コード例 #11
0
    def delete_user(self):
        from azure.communication.identity import CommunicationIdentityClient

        if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
            from azure.identity import DefaultAzureCredential
            endpoint, _ = parse_connection_str(self.connection_string)
            identity_client = CommunicationIdentityClient(
                endpoint, DefaultAzureCredential())
        else:
            identity_client = CommunicationIdentityClient.from_connection_string(
                self.connection_string)
        user = identity_client.create_user()
        print("Deleting user: "******" deleted")
コード例 #12
0
    def test_create_user_from_managed_identity(self, communication_livetest_dynamic_connection_string):
        endpoint, access_key = parse_connection_str(communication_livetest_dynamic_connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(
            endpoint, 
            credential,
            http_logging_policy=get_http_logging_policy()
        )
        user = identity_client.create_user()

        assert user.properties.get('id') is not None
コード例 #13
0
    async def revoke_tokens(self):
        from azure.communication.identity.aio import CommunicationIdentityClient
        from azure.communication.identity import CommunicationTokenScope
        if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
            from azure.identity.aio import DefaultAzureCredential
            endpoint, _ = parse_connection_str(self.connection_string)
            identity_client = CommunicationIdentityClient(endpoint, DefaultAzureCredential())
        else:
            identity_client = CommunicationIdentityClient.from_connection_string(self.connection_string)

        async with identity_client:
            user = await identity_client.create_user()
            tokenresponse = await identity_client.get_token(user, scopes=[CommunicationTokenScope.CHAT])
            print("Revoking token: " + tokenresponse.token)
            await identity_client.revoke_tokens(user)
            print(tokenresponse.token + " revoked successfully")
コード例 #14
0
    def get_token(self):
        from azure.communication.identity import (CommunicationIdentityClient,
                                                  CommunicationTokenScope)

        if self.client_id is not None and self.client_secret is not None and self.tenant_id is not None:
            from azure.identity import DefaultAzureCredential
            endpoint, _ = parse_connection_str(self.connection_string)
            identity_client = CommunicationIdentityClient(
                endpoint, DefaultAzureCredential())
        else:
            identity_client = CommunicationIdentityClient.from_connection_string(
                self.connection_string)
        user = identity_client.create_user()
        print("Getting token for: " + user.properties.get('id'))
        tokenresponse = identity_client.get_token(
            user, scopes=[CommunicationTokenScope.CHAT])
        print("Token issued with value: " + tokenresponse.token)
 def test_get_token_for_teams_user_from_managed_identity(
         self, communication_livetest_dynamic_connection_string):
     if (self.skip_get_token_for_teams_user_test()):
         return
     endpoint, access_key = parse_connection_str(
         communication_livetest_dynamic_connection_string)
     from devtools_testutils import is_live
     if not is_live():
         credential = FakeTokenCredential()
     else:
         credential = DefaultAzureCredential()
     identity_client = CommunicationIdentityClient(
         endpoint,
         credential,
         http_logging_policy=get_http_logging_policy())
     add_token = self.generate_teams_user_aad_token()
     token_response = identity_client.get_token_for_teams_user(add_token)
     assert token_response.token is not None
コード例 #16
0
    def setUp(self):
        super(ChatThreadClientTestAsync, self).setUp()

        self.recording_processors.extend([
            BodyReplacerProcessor(keys=[
                "id", "token", "senderId", "chatMessageId", "nextLink",
                "participants", "multipleStatus", "value"
            ]),
            URIIdentityReplacer(),
            ResponseReplacerProcessor(keys=[self._resource_name]),
            ChatURIReplacer()
        ])

        endpoint, _ = parse_connection_str(self.connection_str)
        self.endpoint = endpoint

        self.identity_client = CommunicationIdentityClient.from_connection_string(
            self.connection_str)

        self.users = []
        self.user_tokens = []
        self.chat_clients = []

        # create user 1
        self.user = self.identity_client.create_user()
        token_response = self.identity_client.get_token(self.user,
                                                        scopes=["chat"])
        self.token = token_response.token

        # create user 2
        self.new_user = self.identity_client.create_user()
        token_response = self.identity_client.get_token(self.new_user,
                                                        scopes=["chat"])
        self.token_new_user = token_response.token

        # create ChatClient
        self.chat_client = ChatClient(
            self.endpoint,
            CommunicationTokenCredential(self.token),
            http_logging_policy=get_http_logging_policy())
        self.chat_client_new_user = ChatClient(
            self.endpoint,
            CommunicationTokenCredential(self.token_new_user),
            http_logging_policy=get_http_logging_policy())
コード例 #17
0
    def test_revoke_tokens_from_managed_identity(self, communication_livetest_dynamic_connection_string):
        endpoint, access_key = parse_connection_str(communication_livetest_dynamic_connection_string)
        from devtools_testutils import is_live
        if not is_live():
            credential = FakeTokenCredential()
        else:
            credential = DefaultAzureCredential()
        identity_client = CommunicationIdentityClient(
            endpoint, 
            credential, 
            http_logging_policy=get_http_logging_policy()
        )
        user = identity_client.create_user()

        token_response = identity_client.get_token(user, scopes=[CommunicationTokenScope.CHAT])
        identity_client.revoke_tokens(user)

        assert user.properties.get('id') is not None
        assert token_response.token is not None