【问题标题】:Azure AD authentication with Bot Framework SDK V4使用 Bot Framework SDK V4 进行 Azure AD 身份验证
【发布时间】:2018-08-21 06:14:06
【问题描述】:

我正在使用 Bot Framework SDK V4 (.Net) 来构建我的 Bot 服务。我想使用 Azure AD 启用身份验证。

我找到了这些步骤 - https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-tutorial-authentication?view=azure-bot-service-3.0

但这适用于 SDK V3,不适用于 V4

有人可以帮助了解如何为使用 V4 框架构建的机器人启用 Azure AD 身份验证吗?

【问题讨论】:

  • 我们目前正在制作 v4 的示例。 Ignite 肯定会在不久的将来看到它。
  • 我应该补充一点,在 Azure 和 AAD 应用程序中设置机器人的所有步骤都与您链接的文档相同。只是机器人的代码会有所不同。
  • 是的@JasonSowers。你说的对。我知道步骤是一样的。但我找不到 var token = await context.GetUserTokenAsync(ConnectionName).ConfigureAwait(false);在 V4 框架中
  • 看看this repo 它不是最终的或官方的样本,但它应该可以帮助您入门。

标签: botframework


【解决方案1】:

我知道这是一个有点晚的答案,但它可能会对某人有所帮助。您需要在 Azure 中创建机器人服务并获取 Microsoft App Id 和 App Password。 然后可以提示用户登录。

private static OAuthPrompt Prompt(string connectionName)
{
    return new OAuthPrompt(
        LoginPromptName,
        new OAuthPromptSettings
        {
            ConnectionName = connectionName,
            Text = "Please Sign In",
            Title = "Sign In",
            Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 5)
        });
}

创建WaterfallStep 以登录Prompt

private static async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
    {
        return await step.BeginDialogAsync(LoginPromptName, cancellationToken: cancellationToken);
    }

接下来,您可以继续使用令牌做任何您想做的事情。

private static async Task<DialogTurnResult> LoginStepAsync(WaterfallStepContext step, CancellationToken cancellationToken)
        {
            // Get the token from the previous step. Note that we could also have gotten the
            // token directly from the prompt itself. There is an example of this in the next method.
            var tokenResponse = (TokenResponse)step.Result;
                    if (tokenResponse != null)
                    {
                        // use the token to do exciting things!
                    }
                    else
                    {
                        // If Bot Service does not have a token, send an OAuth card to sign in
                    }

            await step.Context.SendActivityAsync("Login was not successful please try again.", cancellationToken: cancellationToken);
            return Dialog.EndOfTurn;
        }

关注this 指南了解更多信息。

您甚至可以为 Azure 设置其他 OAuth 提供程序,例如 Github、Facebook。为此,请转到 Bot Channels Registration 的设置并找到添加新连接选项。

【讨论】:

    【解决方案2】:

    我正在使用 botframework 社区的 AzureAdAuthMiddleware 将 Azure AD 身份验证功能注入到我的 v4 聊天机器人中。

    您可以在这里查看:https://github.com/BotBuilderCommunity/botbuilder-community-dotnet

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-31
      • 2019-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多