【问题标题】:AD authentication token is not getting same for every user in bot framework V4 web chat机器人框架 V4 网络聊天中的每个用户的 AD 身份验证令牌并不相同
【发布时间】:2019-04-03 14:33:12
【问题描述】:

我正在使用 Bot Framework V4,我们的机器人的 AD 身份验证工作正常。但是当我尝试使用新会话时,它使用的令牌与之前记录的令牌相同。所以我在所有会话中都得到了相同的数据。我正在使用 Enterprise Bot Template 提供的 AuthenticationDialog

实际:我只登录一次,并且所有会话都保持登录状态(即使在其他机器上) 预期:我希望每次会话都应将我带到登录卡(OAurth 卡)

public class AuthenticationDialog : ComponentDialog
{
    private static AuthenticationResponses _responder = new AuthenticationResponses();

    public AuthenticationDialog(string connectionName)
        : base(nameof(AuthenticationDialog))
    {
        InitialDialogId = nameof(AuthenticationDialog);
        ConnectionName = connectionName;

        var authenticate = new WaterfallStep[]
        {
            PromptToLogin,
            FinishLoginDialog,
        };

        AddDialog(new WaterfallDialog(InitialDialogId, authenticate));
        AddDialog(new OAuthPrompt(DialogIds.LoginPrompt, new OAuthPromptSettings()
        {
            ConnectionName = ConnectionName,
            Title = AuthenticationStrings.TITLE,
            Text = AuthenticationStrings.PROMPT,
        }));
    }

    private string ConnectionName { get; set; }

    private async Task<DialogTurnResult> PromptToLogin(WaterfallStepContext sc, CancellationToken cancellationToken)
    {
        return await sc.PromptAsync(AuthenticationResponses.ResponseIds.LoginPrompt, new PromptOptions());
    }

    private async Task<DialogTurnResult> FinishLoginDialog(WaterfallStepContext sc, CancellationToken cancellationToken)
    {
        var activity = sc.Context.Activity;
        if (sc.Result != null)
        {
            var tokenResponse = sc.Result as TokenResponse;

            if (tokenResponse?.Token != null)
            {
                var user = await GetProfile(sc.Context, tokenResponse);
                await _responder.ReplyWith(sc.Context, AuthenticationResponses.ResponseIds.SucceededMessage, new { name = user.DisplayName });
                return await sc.EndDialogAsync(tokenResponse);
            }
        }
        else
        {
            await _responder.ReplyWith(sc.Context, AuthenticationResponses.ResponseIds.FailedMessage);
        }

        return await sc.EndDialogAsync();
    }

    private async Task<User> GetProfile(ITurnContext context, TokenResponse tokenResponse)
    {
        var token = tokenResponse;
        var client = new GraphClient(token.Token);

        return await client.GetMe();
    }

    private class DialogIds
    {
        public const string LoginPrompt = "loginPrompt";
    }
}

【问题讨论】:

  • 你能添加你的WebChat和OAuth相关的代码吗?
  • 我点击下面的链接进行我们的机器人的广告验证 (docs.microsoft.com/en-us/azure/bot-service/…) 我没有从网络聊天生成任何令牌,因为我正在为 botchat.js 使用 CDN
  • 您的问题是与新用户的对话会参考与其他用户对话的数据吗?您是为 BotChat 中的每个用户使用唯一的用户 ID 还是通用 ID?
  • 我使用通用 ID,因为我的机器人是面向公众的,我们没有为用户获取任何唯一 ID。

标签: c# authentication active-directory botframework web-chat


【解决方案1】:

这是网络聊天中已知的issue。当您为每个对话使用相同的用户 ID 时,对话将引用相同的数据存储。要解决此问题,我建议为每个对话生成随机用户 ID。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-28
    • 2017-08-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多