繁体   English   中英

Azure Bot 通道错误“向您的机器人发送此消息时出错:HTTP 状态代码未经授权”

[英]Azure Bot channel error "There was an error sending this message to your bot: HTTP status code Unauthorized"

尝试将消息从 azure Bot 通道发送到 api 时出现未经授权的错误。 我已经使用 pulumi 部署了 azure 应用程序和 Bot 频道。 在 azure 应用程序中,我注意到身份验证部分中有一个关于Implicit Grant的警告。

隐性授予

如果我从 azure 门户禁用隐式授予设置,则 Bot 通道工作正常。 我正在根据 pulumi 文档使用默认设置创建 azure 应用程序,但没有选项可以删除此隐式授予设置

我使用 此链接使用 pulumi 创建了 Azure 应用程序和 Bot 频道

public static AzureAD.Application Create()
{
    var name = "app-name";
    var azureApp = new AzureAD.Application(name, new AzureAD.ApplicationArgs
    {
        Name = name
        // Tried combinations of the following lines, but it makes no difference
        //, Type = "native"
        //, Oauth2AllowImplicitFlow = false
    });
    
    CreatePrincipal(azureApp);
    
    return azureApp;
}
    
private static void CreatePrincipal(AzureAD.Application azureApp)
{
    var name = "app-principal";
    new AzureAD.ServicePrincipal(name, new AzureAD.ServicePrincipalArgs
    {
        ApplicationId = azureApp.ApplicationId
    });
}

public static ChannelsRegistration Create(ResourceGroup resourceGroup, AzureAD.Application teamsBotAzureApp)
{
    var channelName = "Channel";
    var channel = new ChannelsRegistration(channelName, new ChannelsRegistrationArgs
    {
        Location = "global",
        ResourceGroupName = resourceGroup.Name,
        Sku = "F0",
        MicrosoftAppId = teamsBotAzureApp.ApplicationId,
        Endpoint = "https://azurefunction.com/api/BotMessagesHandler"
    });
    
    CreateChannel(resourceGroup, channel);
    
    return channel;
}

在 azure ad 中, Implicit Grant的设置由Manifest的参数控制(您也可以在 UI 中设置它们,然后它们将在 manifest 中更改), Access tokens对应oauth2AllowImplicitFlowID tokens对应oauth2AllowIdTokenImplicitFlow

如果您使用 pulumi 创建应用程序,您可以设置Oauth2AllowImplicitFlow = false以禁用Access tokens ,但看起来pulumi 输入中没有oauth2AllowIdTokenImplicitFlow ,因此您无法通过 pulumi 禁用ID tokens

您可以尝试以下解决方法。

1.从警告中,它说You should remove these settings or register the appropriate redirect URI. 因此,您可以尝试使用如下代码创建具有重定向 URI(即 ReplyUrls )的应用程序,看看它是否可以在不禁用ID tokens

ReplyUrls = 
            {
                "https://replyurl",
            }

2.如果被接受,您可以在创建应用程序后使用Microsoft Graph SDK 更新应用程序 web属性的implicitGrantSettings中的enableIdTokenIssuance设置为false ,则ID tokens将被禁用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM