Azure 机器人 channel 错误 "There was an error sending this message to your bot: HTTP status code Unauthorized"

标签 azure asp.net-core azure-active-directory botframework pulumi

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

Implicit Grant

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

我已经使用 this link 与 pulumi 创建了 Azure 应用程序和 Bot channel

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 中,隐式授予 的设置由 Manifest 中的参数控制。 (您也可以在 UI 中设置它们,然后它们将在 list 中更改),Access tokens 对应于 oauth2AllowImplicitFlow , ID token 对应于 oauth2AllowIdTokenImplicitFlow .

如果您使用 pulumi 创建应用程序,则可以设置 Oauth2AllowImplicitFlow = false 来禁用访问 token ,但看起来没有 oauth2AllowIdTokenImplicitFlow > 在 pulumi inputs ,因此您无法通过 pulumi 禁用 ID token

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

1.从警告中,它说您应该删除这些设置或注册适当的重定向URI。因此您可以尝试使用以下代码创建带有重定向URI(即 ReplyUrls )的应用程序下面,看看它是否可以在不禁用 ID token 的情况下工作。

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

2.如果接受,您可以使用 Microsoft Graph SDKupdate the application创建后。设置enableIdTokenIssuanceimplicitGrantSettings 中的 falseweb属性,则 ID token 将被禁用。

关于Azure 机器人 channel 错误 "There was an error sending this message to your bot: HTTP status code Unauthorized",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64327115/

相关文章:

azure - AADB2C90083 : The request is missing required parameter: grant_type

azure-active-directory - 如何检查我的 AzureAD 版本是 V1 还是 V2?

azure - 网关在指定时间内没有收到 'Microsoft.Sql'的响应

Azure 数据资源管理器 : Multi-Select Parameter "Select All" return all possible options instead

azure - Azure Linux VM 上的自定义端口连接被拒绝

c# - 当表中存在记录时,Azure 表存储查询不会从有效筛选器中检索任何实体

angularjs - 在 VS2015 Update 2 中使用 npm 安装 Angular 2 包时出现问题

azure - 在 Azure B2C 中使用 OpenId Connect 面临本地帐户用户的登录问题

c# - 如何在数据库优先方法中配置全局查询过滤器?

c# - 当一个从 DBContextBase 读取而另一个从 DomainDBContext 读取时,从 2 个不同项目中的类访问 DBContext