团队频道上的 botframework 1:1 身份验证 AAD 集成

botframework on teams channel 1:1 Authentication AAD integrated

我想在团队频道上连接我的机器人,但我不知道如何确保它仅在我们的域(组织)中使用。

我已经测试了 Azure Web 应用程序的外观(身份验证 AAD),但它在团队或网络聊天中不起作用,因为端点地址未重定向。

我已经测试过实现 AUTH 卡,但它不适用于团队。

注意:我使用的是 botframework C# api BotBuilder 3.15.2.2

我看起来像其他"ask": AAD authentication in Microsoft teams for Bot Framework

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/authentication/auth-flow-bot

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/authentication/auth-bot-AAD

https://docs.microsoft.com/en-us/microsoftteams/platform/concepts/authentication/authentication

https://tsmatz.wordpress.com/2016/09/06/microsoft-bot-framework-bot-with-authentication-and-signin-login/

真诚的, 帕斯卡

编辑: 我已经实施了 Adrian 提出的解决方案,下面是一段在 MessasController.cs(Post 函数)上实施的 C# 代码: 注意 ==> 添加本地主机使用的访问权限

 //
 string tenantIdAAD = "";
 try
 {
     tenantIdAAD = activity.GetChannelData<TeamsChannelData>().Tenant.Id;
 }
 catch (Exception exception)
 {
     tenantIdAAD = "";
 }

 ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

 if ([AAD_TenantID].TenantIdAAD.Equals(tenantIdAAD) || activity.ServiceUrl.StartsWith("http://localhost") )
 {
     await Conversation.SendAsync(activity, () => new Dialogs.RootDialog().LogIfException());
 }
 else
 {
     await connector.Conversations.ReplyToActivityAsync(activity.CreateReply("Access Denied"));
 }

传入消息包含可用于识别用户的信息。消息如下所示:

{ ... "from": { "id": "29:1XJKJMvc5GBtc2JwZq0oj8tHZmzrQgFmB39ATiQWA85gQtHieVkKilBZ9XHoq9j7Zaqt7CZ-NJWi7me2kHTL3Bw", "name": "Richard Moe", "aadObjectId": "ae361bee-9946-4082-99dc-6994b00ceebb" }, "channelData": { "tenant": { "id": "72f988bf-86f1-41af-91ab-2d7cd011db47" } } }

channelData.tenant.id 标识用户所属的组织(O365 租户),因此您可以查看它并拒绝不是来自您期望的组织的邮件。

该邮件还在 from.aadObjectId 中包含发件人的 AAD 对象 ID。如果您需要向其他服务提供令牌以便您可以代表用户行事,则上面链接中的身份验证流程很有用,但如果您只需要用户的租户和身份,则该消息已满足您的所有需求。

(请记住先 authenticate the incoming request,然后再信任消息中的任何信息。)