c# - 使用 BotAuth 时如何正确注销

标签 c# botframework

在使用 BotAuth 时,注销现有登录用户的正确方法是什么?在 AuthBot ,这是使用 await context.Logout(); 完成的。

关于 BotAuth code ,我发现以下代码执行注销,但它未在任何示例中显示。

public async Task Logout(AuthenticationOptions authOptions, IDialogContext context)
    {
        context.UserData.RemoveValue($"{this.Name}{ContextConstants.AuthResultKey}");
        context.UserData.RemoveValue($"{this.Name}{ContextConstants.MagicNumberKey}");
        context.UserData.RemoveValue($"{this.Name}{ContextConstants.MagicNumberValidated}");
        string signoutURl = "https://login.microsoftonline.com/common/oauth2/logout?post_logout_redirect_uri=" + System.Net.WebUtility.UrlEncode(authOptions.RedirectUrl);
        await context.PostAsync($"In order to finish the sign out, please click at this [link]({signoutURl}).");
    }

在调用上述函数时,尽管清除了用户数据,但出现以下错误: enter image description here 这是正确的注销方式吗?

最佳答案

我发现在我执行注销操作后,返回 URL 将是 http://localhost:3979/Callback(没有任何查询字符串),在 the source code of botauth 中,我发现它直接返回了状态为 BadRequest 的异常:

[HttpGet]
[Route("Callback")]
public async Task<HttpResponseMessage> Callback()
{
    return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new Exception());
}

我做了一个测试,用下面的代码修改这个 Callback,它在我这边按预期工作。

[HttpGet]
[Route("Callback")]
public async Task<HttpResponseMessage> Callback()
{
    //return Request.CreateErrorResponse(HttpStatusCode.BadRequest, new Exception());

    var resp = new HttpResponseMessage(HttpStatusCode.OK);
    resp.Content = new StringContent("<html><body>Logout success</body></html>", System.Text.Encoding.UTF8, @"text/html");
    return resp;
}

测试结果:

enter image description here

关于c# - 使用 BotAuth 时如何正确注销,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48116847/

相关文章:

c# - 未经授权。访问 token 丢失、无效、受众不正确 (https ://cognitiveservices. azure.com) 或已过期

c# - Bot框架获取内嵌聊天控制页面的ServiceUrl

.net-core - 机器人配置不包含 ID 为 `luis` 的服务类型 `basic-bot-LUIS` 。 (.NET 核心)

c# - 如何实现通用 GetById() 其中 Id 可以是各种类型

node.js - Microsoft Bot 框架 : Sending Message on connect

c# - 机器人框架 : Loop through Prompts

c# - 在同一装配空间中动态生成模块

c# - 无法将 T 转换为间隔(我自己的自定义类型)

c# - 如何使用 global.asax 中的 Server.MapPath()?

c# - 我无法理解 GroupJoin 在数据库关系中需要它的地方