首页 > 解决方案 > 团队机器人中的身份验证问题:如何强制打开选项卡?

问题描述

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

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

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

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

标签: authenticationbotframeworkmicrosoft-teams

解决方案


这可能与此问题有关,特别是您的操作类型是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 清单编辑器中创建您的 Teams 机器人
  3. 在域和权限下,确保token.botframework.com已将其添加为有效域。
    • (可选)使用您的 appId 启用 Web 应用单点登录,并且https://token.botframework.com/.auth/web/redirect
  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);
    }
}

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


根据@SylvainBarbot,您可能还需要更新您的软件包,如本期所述


推荐阅读