Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在Microsoft Team Bot中获取身份验证后的用户访问令牌?_Node.js_Botframework_Microsoft Teams - Fatal编程技术网

Node.js 如何在Microsoft Team Bot中获取身份验证后的用户访问令牌?

Node.js 如何在Microsoft Team Bot中获取身份验证后的用户访问令牌?,node.js,botframework,microsoft-teams,Node.js,Botframework,Microsoft Teams,我正在开发我的第一个 我希望用户在bot中输入命令,bot应该向我的外部web服务器发送请求,并将结果显示为自适应卡。我能够通过我的外部服务器对bot进行身份验证。bot在身份验证后显示用户访问令牌。太好了 如何在我的bot代码或web服务器中获取用户的访问令牌,以处理来自bot的传入请求。下面是我的机器人程序代码 this.onMessage(async (context, next) => { //I need a way to get the user's access

我正在开发我的第一个

我希望用户在bot中输入命令,bot应该向我的外部web服务器发送请求,并将结果显示为自适应卡。我能够通过我的外部服务器对bot进行身份验证。bot在身份验证后显示用户访问令牌。太好了

如何在我的bot代码或web服务器中获取用户的访问令牌,以处理来自bot的传入请求。下面是我的机器人程序代码

this.onMessage(async (context, next) => {

     //I need a way to get the user's access token here 
     //or a way to fetch the access token from my web server 
     //based on some id in the context.
     const response = await myWebService.getData(context);

     // Run the Dialog with the new message Activity.
     await this.dialog.run(context, this.dialogState);
     await next();
});

我在这里遗漏了什么?

您可以在登录过程中捕获令牌。假设您已经构建了如下所示的登录过程,用户登录的结果将从
prompstep()
传递到
loginStep()
。它在
stepContext.result
中可用,我已将其分配给
tokenResponse
,并将其作为活动中的文本返回给用户

在这里,您可以执行所需的附加逻辑

async promptStep(stepContext) {
    return await stepContext.beginDialog(OAUTH_AAD_PROMPT);
}

async loginStep(stepContext) {
    // 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.
    const tokenResponse = stepContext.result;
    if (tokenResponse) {
        return await stepContext.context.sendActivity(`Your token is: ${ tokenResponse.token }`);
    }
    await stepContext.context.sendActivity('Login was not successful, please try again.');
    return await stepContext.next();
}

希望有帮助

BotFrameworkAdapter的GetUserTokenAsync可用于在任何瀑布式步骤中获取令牌,如下所示

var botAdapter = (BotFrameworkAdapter)stepContext.Context.Adapter;
TokenResponse result = await botAdapter.GetUserTokenAsync(stepContext.Context, connectionName, null, cancellationToken);

接受/向上投票答案服务于更大的堆栈溢出社区和任何有类似问题的人。如果你觉得我的回答足够,请“接受”并投票表决。如果没有,让我知道我还能提供什么帮助!有没有办法在后续命令调用的turn上下文中使用此标记?