在Microsoft Teams Bot中进行身份验证后如何获取用户访问令牌?

杰西姆·阿巴斯(Jaseem Abbas)

我正在Microsoft Teams开发我的第一个机器人

我希望用户在机器人中输入命令,该机器人应将请求发送到我的外部Web服务器,并将结果显示为自适应卡。我可以使用外部服务器对机器人进行身份验证。机器人在身份验证后显示用户访问令牌。完善!

如何在我的机器人代码或网络服务器中获取用户的访问令牌,以处理来自机器人的传入请求。这是我的机器人代码的样子。

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();
});

我在这里想念什么?

史蒂文·坎伯格

您可以在登录过程中捕获令牌。假设您已按照以下方式构建了登录过程,则用户登录的结果将从传递promptStep()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();
}

希望有帮助!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Microsoft Teams Bot身份验证黑屏

从 Microsoft Teams 获取 SSO 身份验证令牌的问题

Microsoft Teams身份验证:无法在Teams Bot(V4 SDK)中检索令牌

如何使用 Microsoft Share To Teams 按钮对用户进行身份验证?

如何永久卸载 Microsoft Teams?

Microsoft Bot Framework 和 Microsoft Teams

使用 AAD 身份验证的 Microsoft Teams 传出 Webhook

Microsoft Teams SSO 身份验证方法 getAuthToken() 返回“resourceDisabled”

如何加载可变的Microsoft Teams Bot图标?

如何从Microsoft Teams恢复已删除的团队?

如何关闭Microsoft Teams中的通知声音?

如何为 Microsoft Teams 选择背景

如何获取Microsoft Teams用户的当前状态

Microsoft Teams Bot-调试刷新令牌流

我如何在应用安装时从 Microsoft Teams 上的 Microsoft Bot Framework 中的团队中拉取用户

Microsoft Teams Bot-链接展开验证流程

在Python Flask中从Microsoft Teams bot验证HMAC

Microsoft Teams Bot-用户无法发起对话

使用REST API for Microsoft Teams访问用户状态

如何从Bot手动向Microsoft Teams发送“ conversationUpdate”?

如何在Azure中向Microsoft Teams Bot添加授权

Microsoft Teams订阅

Microsoft Teams订阅电话

Microsoft Teams 对话存储

Microsoft Bot-Node SDK:如何在Microsoft Teams中提及用户

如何通过EWS获取Microsoft Teams聊天消息?

如何获取 Microsoft Teams 上下文属性 hostClientType

Microsoft Bot Framework Composer Teams 包发送任务模块

Microsoft Teams App-通过Bot发布通知