我如何要求用户从机器人登录到我的网站,然后当用户要求机器人首先检查用户是否在我的网站中通过身份验证时,如果没有则重定向到网站进行登录。我在 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.)
来源: Tsuyoshi Matsuzaki
关于c# - Microsoft Bot Framework,如何对用户进行身份验证以登录 Web 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41674297/