团队机器人中的身份验证问题:如何强制打开选项卡?

issue with authentication in teams bot: how to keep a tab forcibly open?

我们开发了一个基于 Virtual Assistant Solution Accelerator beta 0.3 的机器人。 该机器人通过 Teams 使用,并且一切都处于 azure 状态。 我们正在通过机器人使用其他服务:office365 和 Yammer。用户根据虚拟助手代码通过 OAuthPrompt 进行身份验证。 直到最近,一切都很好。但是我们在星期二早上发现我们对尚未登录的用户存在问题。

在认证过程中,当点击oauthprompt卡片中的登录按钮时,会打开一个新的标签页,连接用户并显示魔术代码。但是现在,此选项卡在显示代码后立即关闭,从而阻止用户将其复制到团队中。

如果我们之后立即重新打开选项卡,代码就在这里并且可以正常工作。 我们使用 chrome、Firefox 和 edge 进行了测试,结果相同。但在移动设备上,该选项卡保持打开状态。我们通过团队应用程序和团队网络应用程序进行了测试。

我现在的问题是:当我在团队中通过卡片打开选项卡时(操作类型是 openUrl),有没有办法让我保持打开状态。

这可能与 this issue 有关,特别是你的操作类型是 openUrl 而现在应该是 Signin

您使用中间件是为了让它最初工作吗?中间件看起来像:

// hook up onSend pipeline
turnContext.OnSendActivities(async (ctx, activities, nextSend) =>
{
    foreach (var activity in activities)
    {
        if (activity.ChannelId != "msteams") continue;
        if (activity.Attachments == null) continue;
        if (!activity.Attachments.Any()) continue;
        if (activity.Attachments[0].ContentType != "application/vnd.microsoft.card.signin") continue;
        if (!(activity.Attachments[0].Content is SigninCard card)) continue;
        if (!(card.Buttons is CardAction[] buttons)) continue;
        if (!buttons.Any()) continue;

        // Modify button type to openUrl as signIn is not working in teams
        buttons[0].Type = ActionTypes.OpenUrl;
    }

    // run full pipeline
    return await nextSend().ConfigureAwait(false);
});

最近有一个更新使您不再需要中间件。相反,请按照以下步骤操作:

  1. 下载最新样本
  2. 在 App Studio Manifest Editor 中创建您的 Teams Bot
  3. 在域和权限下,确保 token.botframework.com 已添加为有效域。
    • 可以选择使用您的 appId 和 https://token.botframework.com/.auth/web/redirect
    • 启用 Web 应用 Single Sign-On
  4. 单击“安装”并开始与您的机器人对话

如果您已经对您的机器人做了大量工作并且不想使用新示例,请将您的所有包更新到 4.4.4,我相信您可以将它添加到您的 OnTurnAsync():

if (turnContext?.Activity?.Type == ActivityTypes.Invoke && turnContext.Activity.ChannelId == "msteams")
    await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
else
    await base.OnTurnAsync(turnContext, cancellationToken);

如果还是不行,你可以试试这个:

protected override async Task OnUnrecognizedActivityTypeAsync(ITurnContext turnContext, CancellationToken cancellationToken)
{
    if (turnContext?.Activity.Type == ActivityTypes.Invoke)
    {
        await turnContext.SendActivityAsync(
        new Activity()
        {
            Type = ActivityTypesEx.InvokeResponse,
            Value = null
        });
        await Dialog.Run(turnContext, ConversationState.CreateProperty<DialogState>(nameof(DialogState)), cancellationToken);
    }
}

中间件使 Teams 中的卡片使用 Action.OpenUrl(不再有效)而不是 Action.Signin(这是所有其他渠道使用的)。


根据@SylvainBarbot,您可能还需要更新您的软件包,如 this issue

中所述