本文介绍了Microsoft Teams身份验证:无法在Teams Bot(V4 SDK)中检索令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Microsoft Teams机器人,并且我正在尝试使用 AAD(v2端点)对用户进行身份验证.该机器人使用 V4 SDK和OauthPrompt .我可以登录,但无法获取令牌.

I have a Microsoft Teams bot and I am trying to authenticate the user using AAD (v2 endpoint). The bot uses V4 SDK and OauthPrompt.I am able to log in but unable to get the token.

我正在使用OAuth卡.该卡正在Teams中呈现.单击登录按钮后,它将转到Microsoft登录页面.用户登录后,该漫游器停止响应,因此我无法获取令牌.

I am using OAuth Card. The card is being rendered inside Teams. When the sign in button is clicked it goes to the Microsoft login page. After the user logins, the bot stops responding and hence I have no way to get the token.

我正在尝试的样本是: https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/18.bot-authentication https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/24.bot-authentication-msgraph .

The samples I am trying out are :https://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/18.bot-authenticationandhttps://github.com/microsoft/BotBuilder-Samples/tree/master/samples/csharp_dotnetcore/24.bot-authentication-msgraph.

这两个示例都在模拟器内部进行.

Both the samples are working inside the emulator.

下面是代码片段:

               AddDialog(new OAuthPrompt(
            nameof(OAuthPrompt),
            new OAuthPromptSettings
            {
                ConnectionName = ConnectionName,
                Text = "Please Sign In",
                Title = "Sign In",
                Timeout = 300000, // User has 5 minutes to login (1000 * 60 * 5)
            }));


         AddDialog(new ConfirmPrompt(nameof(ConfirmPrompt)));

        AddDialog(new WaterfallDialog(nameof(WaterfallDialog), new WaterfallStep[]
        {
            PromptStepAsync,
            LoginStepAsync,
            DisplayTokenPhase1Async,
            DisplayTokenPhase2Async,
        }));

 private async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
           return await stepContext.BeginDialogAsync(nameof(OAuthPrompt), null, cancellationToken);
        }


它永远不会到达代码:

        private async Task<DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, 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)stepContext.Result;
        if (tokenResponse != null)
        {
            await stepContext.Context.SendActivityAsync(MessageFactory.Text("You are now logged in."), cancellationToken);
            return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Would you like to view your token?") }, cancellationToken);
        }

        await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken);
        return await stepContext.EndDialogAsync(cancellationToken: cancellationToken);
    }

我希望一旦用户登录,令牌就会在代码中收到,但是漫游器只是停止响应.

I expected that the token would be received in the code once the user signs in, but the bot just stops responding.

推荐答案

这似乎是Bot框架中的错误,但是已经有一个拉取请求来解决此问题.您可以在此处找到拉取请求.

It seems like this is a bug in the Bot framework, but there is already a pull request to fix this issue. You can find the pull request here.

您现在可以看到这里.

这篇关于Microsoft Teams身份验证:无法在Teams Bot(V4 SDK)中检索令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:19