首页 文章

使用Bot Framework SDK V4进行Azure AD身份验证

提问于
浏览
0

我正在使用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身份验证?

1 回答

  • 0

    我知道这是一个迟到的答案,但它可能有助于某人 . 您需要在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指南获取更多信息 .

    您甚至可以像Github,Facebook一样为Azure设置其他OAuth提供程序 . 要执行此操作,请转到Bot Channels Registration的设置,然后找到添加新连接选项 .

    enter image description here

相关问题