Teams Azure Bot - Getting authentication error.

Robert Jesuraj 10 Reputation points
2024-03-27T11:56:40.4866667+00:00

Hi helpers,

The task I m trying to achieve is to create a teams chat bot that connect azure bot and give relevant chat message after calling OpenAI service calls.

I am trying to create an echo bot using flask using the code https://github.com/frankqianms/echo-bot/blob/main/app.py  &

https://github.com/microsoft/BotBuilder-Samples/blob/main/samples/python/02.echo-bot/app.py

But when sending a (chat) request using "Test in Web Chat" functionality in Azure bot, I don't get echo bot working. The same code worked fine when i tried with Microsoft emulator. I just added the app registration client_id and clinet_secret_value in the azure bot server version (that is the only change I did).

python code line where I made the changes in azure webapp

botadaptersettings = BotFrameworkAdapterSettings("uuid-client-id", "client_secret_value")

Error message is appended below, Error is thrown from the botframework package. Any suggestions to correct this error?

2024-03-20T19:53:26.6379565Z     response = await self.next.send(request, **kwargs)  # type: ignore
2024-03-20T19:53:26.6466259Z   File "/home/site/wwwroot/antenv/lib/python3.10/site-packages/msrest/pipeline/async_requests.py", line 99, in send
2024-03-20T19:53:26.6550986Z     self._creds.signed_session(session)
2024-03-20T19:53:26.6558362Z   File "/home/site/wwwroot/antenv/lib/python3.10/site-packages/botframework/connector/auth/app_credentials.py", line 98, in signed_session
2024-03-20T19:53:26.6564263Z     auth_token = self.get_access_token()
2024-03-20T19:53:26.6569844Z   File "/home/site/wwwroot/antenv/lib/python3.10/site-packages/botframework/connector/auth/microsoft_app_credentials.py", line 65, in get_access_token
2024-03-20T19:53:26.6576731Z     return auth_token["access_token"]
2024-03-20T19:53:26.6582585Z KeyError: 'access_token'
Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
746 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,074 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,846 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
6,878 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. YutongTie-MSFT 46,566 Reputation points
    2024-03-28T00:01:17.6433333+00:00

    @Robert Jesuraj

    Thanks for reaching out to us, based on the error message, it seems there is something wrong with your credentials. Please check on below items to see if there is anything wrong with it.

    1. Verify your credentials: Make sure that the "uuid-client-id" and "client_secret_value" are correct and have the right permissions. The Client ID and Client Secret should come from your Azure Bot Registration.
    2. Emulator and Azure differences: The bot emulator might not require the same authentication process as deploying to Azure. If the bot works with the emulator but not when deployed, it's likely due to differences in the authentication process.
    3. Check your OAuth Connection: If you're using an OAuth connection, make sure it's set up correctly in Azure. You can test the connection in the Azure portal (Bot services -> Settings -> OAuth Connection Settings -> Test Connection).
    4. Consider using Managed Identity: If you're running your bot on Azure, you could consider using Managed Identity to handle your bot's authentication to Azure services. This can simplify your code and make your bot more secure.
    5. Debug the Authentication process: You may need to debug your bot's authentication process. This could involve printing out the auth_token dictionary to see what it contains, or printing out other information about the authentication process. Be careful not to print out any sensitive information like secrets or access tokens.
    6. Upgrade your libraries: Ensure that you're using the latest versions of the botframework-connector and other related libraries. Sometimes issues can be caused by bugs in older versions of libraries.

    Once you check on everything but you believe there is nothing wrong with it, please let us know, we can discuss further on this issue.

    Regards,

    Yutong

    -Please kindly accept the answer if you feel helpful to support the community, thanks a lot.