def get_token()

in ees_microsoft_teams/msal_access_token.py [0:0]


    def get_token(self, is_acquire_for_client=False):
        """Generates the access token to call Microsoft Graph APIs
            :param is_acquire_for_client: Pass True if want to acquire token by using client_id, tenant_id and
                secret_key
            Returns:
                access_token: Access token for authorization
        """
        self.logger.debug(f'Generating the access token for the tenant ID: {self.config.get_value("tenant_id")}...')
        authority = f'https://login.microsoftonline.com/{self.config.get_value("tenant_id")}'

        try:
            auth_context = ConfidentialClientApplication(
                self.config.get_value("application_id"),
                client_credential=self.config.get_value("client_secret"),
                authority=authority)
            if is_acquire_for_client:
                token = auth_context.acquire_token_for_client("https://graph.microsoft.com/.default")
            else:
                token = auth_context.acquire_token_by_username_password(
                    self.config.get_value("username"), self.config.get_value("password"), SCOPE)
            if not token.get("access_token"):
                raise AccesstokenError(
                    "Could not generate the access token, please verify the Microsoft Teams configuration settings in \
                        configuration file.")
            self.logger.info(
                f"Successfully generated the access token for the tenant ID: {self.config.get_value('tenant_id')}.")
            return token.get("access_token")
        except Exception as exception:
            raise AccesstokenError(f"Error while generating the access token. Error: {exception}")