c# - Microsoft Bot Framework,如何对用户进行身份验证以登录 Web 应用程序

标签 c# authentication botframework

我如何要求用户从机器人登录到我的网站,然后当用户要求机器人首先检查用户是否在我的网站中通过身份验证时,如果没有则重定向到网站进行登录。我在 bot 中使用登录卡进行了登录,并传递了 activity.user.id,但如果用户已登录,我也不知道如何检索信息。

ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
Activity reply = activity.CreateReply($"Well hello there. What can I do for you today?");
await connector.Conversations.ReplyToActivityAsync(reply);

var id = activity.From.Id;
reply.Attachments = new List<Attachment>();
List<CardAction> cardButtons = new List<CardAction>();
CardAction plButton = new CardAction()
{
    Value = $"http://myapp.azurewebsites.net/Account/Login?userid='{id}'",
    Type = "signin",
    Title = "Connect"
};

cardButtons.Add(plButton);
SigninCard plCard = new SigninCard("You need to authorize me", new List<CardAction>() 
        { plButton });

Attachment plAttachment = plCard.ToAttachment();
reply.Attachments.Add(plAttachment);
var replyt = await connector.Conversations.SendToConversationAsync(reply);

最佳答案

可以翻阅这篇文章https://tsmatz.wordpress.com/2016/09/06/microsoft-bot-framework-bot-with-authentication-and-signin-login/
和示例 github 代码 https://github.com/tsmatsuz/AuthDemoBot

when your web application (web site) is opened in the browser, the page is redirected to the login url. After the user log-in (login succeeded), your web application might get some authenticated security token. Using Bot Framework api, your web application stores the given token as user state into the bot state service. (At this time, the user id is used for identifier.) The user can close your web application (web browser).
Finally, when the user inputs some chat in your bot, your bot (in server side) can retrieve the previous token from bot state service. (From now, this bot can call some api using this retrieved token.)

enter image description here

来源: Tsuyoshi Matsuzaki

关于c# - Microsoft Bot Framework,如何对用户进行身份验证以登录 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674297/

相关文章:

c# - 是否可以设置页面特定的 cookie?

botframework - 为 LUIS.AI 创建 API 或使用 .JSON 文件以便为非技术用户训练机器人

c# - ms botframework 中英雄卡按钮的自定义 css 样式

c# - 如何通过文本查找以编程方式创建的按钮?

c# - WPF ListBox 在用户滚动时生成项目

c# - XNA 矩形交叉口

asp.net - 通过 web.config 的身份验证不在 ASP.net 3.5 中进行身份验证

authentication - OpenID 提供程序可以使用 Kerberos 或其他 "alternate"身份验证机制吗?

c# - ASP.NET MVC 设计问题 将特定用户/"access level"代码放在哪里

node.js - 修改选择提示中的选择验证 - Bot Framework