Botframework 使用BotAuth对话框启用Webchat上的语音

Botframework 使用BotAuth对话框启用Webchat上的语音,botframework,Botframework,在我们的webchat中,我们启用了BotAuth,因此用户应该能够使用Azure AD凭据登录(如下所示): await context.Forward(新建AuthDialog(新的MSALAuthProvider(),选项),async(IDialogContext authContext,IAwaitable) 这是第一次,机器人显示登录按钮,用户可以登录,并可以看到电子邮件发送到他/她的id 第二次,如果另一个用户登录,它不会显示登录按钮,而是显示电子邮件已发送给第一个用户,不知何故,

在我们的webchat中,我们启用了BotAuth,因此用户应该能够使用Azure AD凭据登录(如下所示):

await context.Forward(新建AuthDialog(新的MSALAuthProvider(),选项),async(IDialogContext authContext,IAwaitable)

这是第一次,机器人显示登录按钮,用户可以登录,并可以看到电子邮件发送到他/她的id

第二次,如果另一个用户登录,它不会显示登录按钮,而是显示电子邮件已发送给第一个用户,不知何故,第一个用户的令牌会保留给第二个用户,依此类推

如果我们删除Webchat.html的引用(其中包含对Bot的directline引用,该功能可以正常工作)。directline似乎保留了令牌,这导致了上述问题

为了清除directline消息,我们已经尝试过,但没有得到确切的解决方案

有没有关于如何解决这个问题的想法?也在这里发布了这个问题
DirectLine没有保留令牌,您的bot是或更具体地说是BotAuth代码。 BotAuth在BotUserData store中存储三个值。AuthResultKey、MagicNumberKey和MagicNumberValidated。它使用这些值来获取和刷新身份验证令牌。请看一下BotAuth项目,了解我所说的内容

BothAuth将令牌存储在内存缓存中,然后检索或刷新它,只要它认为同一用户仍在“登录”。你需要做的是在你的bot中想出一种机制来注销当前用户

无论您决定采用何种机制,执行注销只需清除存储在BotUserData存储中的三条数据。您可以在BotAuth项目的登录过程中看到BotAuth在哪里设置这些值

在我参与的几个bot项目中,我实现了直接注销,在那里我会提示用户,询问他们是否完成并想注销。我还跟踪用户最后收到的消息的时间戳。我有一个超时值(通常大约5分钟),如果下一条消息在这五分钟之后出现,我会默默地执行注销(通过清除我提到的那些值),从而强制进行新的登录。 下面是一个简单的例子,这是我的MessagesController.cs

var userPrivateData = await _botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);

if (!DateTime.TryParse(userPrivateData.GetProperty<string>(Utility.Constants.UserActivityKey), out DateTime userLastActivity))
userLastActivity = DateTime.Now;
Trace.TraceInformation($"MessagesController::User Last Activity : {userLastActivity.ToString()}");

TimeSpan sincelast = TimeSpan.FromTicks(DateTime.Now.Ticks - userLastActivity.Ticks);
if (sincelast > Constants.MaxIdleTimeTicks)
{
    Trace.TraceInformation($"MessagesController::User Last Activity : Idle Timeout. Reset User Auth State");        

    userPrivateData.RemoveProperty($"{Constants.AzureADAuthType}{ContextConstants.AuthResultKey}");
    userPrivateData.RemoveProperty($"{Constants.AzureADAuthType}{ContextConstants.MagicNumberKey}");
    userPrivateData.RemoveProperty($"{Constants.AzureADAuthType}{ContextConstants.MagicNumberValidated}");
}
userPrivateData.SetProperty(Utility.Constants.UserActivityKey, DateTime.Now.ToString());

await _botDataStore.SaveAsync(key, BotStoreType.BotUserData, userPrivateData, CancellationToken.None);
await _botDataStore.FlushAsync(key, CancellationToken.None);
var userPrivateData=await\u botDataStore.LoadAsync(key,BotStoreType.BotUserData,CancellationToken.None);
如果(!DateTime.TryParse(userPrivateData.GetProperty(Utility.Constants.UserActivityKey),out DateTime userLastActivity))
userLastActivity=DateTime.Now;
Trace.TraceInformation($“MessagesController::User Last Activity:{userLastActivity.ToString()}”);
TimeSpan sincelast=TimeSpan.FromTicks(DateTime.Now.Ticks-userLastActivity.Ticks);
if(sincelast>Constants.MaxIdleTimeTicks)
{
Trace.TraceInformation($“MessagesController::用户上次活动:空闲超时。重置用户身份验证状态”);
userPrivateData.RemoveProperty($“{Constants.AzureADAuthType}{ContextConstants.AuthResultKey}”);
userPrivateData.RemoveProperty($“{Constants.AzureADAuthType}{ContextConstants.MagicNumberKey}”);
userPrivateData.RemoveProperty($“{Constants.AzureADAuthType}{ContextConstants.MagicNumberValidated}”);
}
userPrivateData.SetProperty(Utility.Constants.UserActivityKey,DateTime.Now.ToString());
wait_botDataStore.SaveAsync(key,BotStoreType.BotUserData,userPrivateData,CancellationToken.None);
wait_botDataStore.FlushAsync(key,CancellationToken.None);

感谢您的回复&它为我指明了正确的方向

StartAsync方法中的context.userdata.clear()。这条语句解决了这个问题

基本上,我很惊讶在这个url中如何处理它 “秘密”


但是,尽管它与Directlinewebchat.html集成在html页面中,但它并没有自动运行,需要像上面那样编写代码行

请阅读-总结是,这不是向志愿者致辞的理想方式,可能会对获得答案产生反作用。请不要将此添加到您的问题中。他说lpful反馈:这个问题增加了新的乞讨材料,所以这次我投了否决票。
var userPrivateData = await _botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);

if (!DateTime.TryParse(userPrivateData.GetProperty<string>(Utility.Constants.UserActivityKey), out DateTime userLastActivity))
userLastActivity = DateTime.Now;
Trace.TraceInformation($"MessagesController::User Last Activity : {userLastActivity.ToString()}");

TimeSpan sincelast = TimeSpan.FromTicks(DateTime.Now.Ticks - userLastActivity.Ticks);
if (sincelast > Constants.MaxIdleTimeTicks)
{
    Trace.TraceInformation($"MessagesController::User Last Activity : Idle Timeout. Reset User Auth State");        

    userPrivateData.RemoveProperty($"{Constants.AzureADAuthType}{ContextConstants.AuthResultKey}");
    userPrivateData.RemoveProperty($"{Constants.AzureADAuthType}{ContextConstants.MagicNumberKey}");
    userPrivateData.RemoveProperty($"{Constants.AzureADAuthType}{ContextConstants.MagicNumberValidated}");
}
userPrivateData.SetProperty(Utility.Constants.UserActivityKey, DateTime.Now.ToString());

await _botDataStore.SaveAsync(key, BotStoreType.BotUserData, userPrivateData, CancellationToken.None);
await _botDataStore.FlushAsync(key, CancellationToken.None);