MS Bot框架不记得身份验证 [英] MS Bot framework doesn't remember authentication

查看:101
本文介绍了MS Bot框架不记得身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用v4框架开发MS Bot,并且正在尝试设置身份验证.问题是我可以进行身份​​验证,但是如果我想通过重新提示对话框来重新捕获用户身份验证令牌(找到

I'm developing a MS Bot with the v4 framework and I'm trying to set up authentication. The problem is that I can authenticate but if I want to recapture the user authentication token by reprompting the dialog (found here) then I do get a new loginprompt instead of just retrieving the token.

这是尝试的方法:

  • 使用Azure AD v1和v2
  • 搜索文档(但始终不推荐使用,或者与链接中的内容相同)

我的代码(如果您有其他需要的话):

My code (if you need something else feel free to ask):

// Register the Promt
AddDialog(Prompt(ConnectionName));

// Prompts the user to log in using the OAuth provider specified by the connection name.
// Prompt definition
public static OAuthPrompt Prompt(string connectionName) => new OAuthPrompt(
       LoginPromptName,
       new OAuthPromptSettings
       {
           ConnectionName = connectionName,
           Text = "Please login",
           Title = "Login",
           Timeout = 300000, // User has 5 minutes to login
       });

private async Task<DialogTurnResult> PromptStepAsync(WaterfallStepContext context, CancellationToken cancellationToken)
{
    var state = await UserProfileAccessor.GetAsync(context.Context);
    return await context.BeginDialogAsync(LoginPromptName, cancellationToken: cancellationToken);
}

private async Task<DialogTurnResult> LoginStepAsync(WaterfallStepContext context, CancellationToken cancellationToken)
{
    var loginState = await UserProfileAccessor.GetAsync(context.Context);
    // 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)context.Result;
    if (tokenResponse != null)
    {
       * DOES SOMETHING WHEN LOGGED IN*
    }
    else
    {
       * DOES SOMETHING WHEN LOGIN FAILED *
    }


    /* !! 
       HERE IS THE PROBLEM IN STEAD OF CHECKING IF THE USER 
       IS ALREADY LOGGED IN AND JUST RETRIEVING THE TOKEN I
       GET A NEW LOGIN SCREEN.
       !!
    */
    var token2Response = await context.BeginDialogAsync(LoginPromptName, null, cancellationToken)


}

因此,基本上,我想检索用户令牌,以便在用户登录时可以检查不同的方法和对话框.

So basically I want to retrieve the user token so I can check in different methods and dialogs if the user is logged in.

推荐答案

这是由于以下错误引起的:拉动请求进行修复.

This is due to this bug: OAuthPrompt requires user credentials when message contains guid or 6-digit number, which currently has a Pull Request to fix.

目前的解决方法是在结束对话框之前确保漫游器获得任何其他类型的用户响应.示例在这里使用:

The workaround for now would be to make sure that the bot gets any kind of other user response before ending the dialog. The sample does it here with:

return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Would you like to view your token?") }, cancellationToken);

我测试过将此代码添加到* DOES SOMETHING WHEN LOGGED IN*中的代码中,并且有效:

I tested adding this to your code in * DOES SOMETHING WHEN LOGGED IN* and it worked:

这篇关于MS Bot框架不记得身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆