admin管理员组

文章数量:1287964

I have a back-end flask server currently running locally and made available to azure using ngrok. I want to connect this back-end the Azure bot service. The back-end receives messages from the "Test in Web Chat" but get a 401 when I send the response. As far as I can figure I need to give the API the correct permissions.

It is a single tenant bot.

Code to generate the token for the response

    url = "/oauth2/v2.0/token"
    headers = {
        "Content-Type": "application/x-www-form-urlencoded"
    }
    data = {
        "grant_type": "client_credentials",
        "client_id": client_id,
        "client_secret": client_secret,
        "scope": "/.default"
    }

The decoded token

{
  "typ": "JWT",
  "alg": "RS256",
  "x5t": "imi0Y2z0dYKxBttAqK_Tt5hYBTk",
  "kid": "imi0Y2z0dYKxBttAqK_Tt5hYBTk"
}.{
  "aud": ";,
  "iss": "/",
  "iat": 1740236233,
  "nbf": 1740236233,
  "exp": 1740322933,
  "aio": "k2RgYGC/rfLecEbpExbj5edObn+xAAA=",
  "appid": "59db3818-3845-4cd7-93ef-0ec3efff7974",
  "appidacr": "1",
  "idp": "/",
  "idtyp": "app",
  "rh": "1.AW4AIJTU1pvz902h3NWak1hx20IzLY0pz1lJlXcODq-9FrxeAQBuAA.",
  "tid": "d6d49420-f39b-4df7-a1dc-d59a935871db",
  "uti": "-m34WPWqiUSVGPdqi39PAA",
  "ver": "1.0",
  "xms_idrel": "13 32"
}.[Signature]

Code for sending the response back to Azure bot.

    url = f"/{conversation_id}/activities"
    headers = {
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json"
    }
    json_block= {
        "type": "message",
        "text": "Hello from the bot!"
    }
    try:
        response = requests.post(url, headers=headers, json=json_block)

The error I get is '{"message":"Authorization has been denied for this request."}'

Here is the list of API permissions I gave my project in Microsoft Graph.

Permission Type Description
APIConnectors.Read.All Delegated Read API connectors for authentication flows
APIConnectors.ReadWrite.All Delegated Read and write API connectors for authentication flows
ChannelMessage.Read.All Application Read all channel messages
Chat.Create Delegated Create chats
Chat.ManageDeletion.All Delegated Delete and recover deleted chats
Chat.Read Delegated Read user chat messages
Chat.ReadBasic Delegated Read names and members of user chat threads
Chat.ReadWrite Delegated Read and write user chat messages
Chat.ReadWrite.All Delegated Read and write all chat messages
Chat.ReadWrite.All Application Read and write all chat messages
ChatMessage.Read Delegated Read user chat messages
ChatMessage.Send Delegated Send user chat messages
User.Read.All Application Read all users' full profiles

本文标签: chatbotWhat are Azure permissions for Azure Bot Service when using a RestAPIStack Overflow