Beispiel #1
0
    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 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)

        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: "******"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