【问题标题】:Error on BotAuth with Azure Table StorageAzure 表存储的 BotAuth 错误
【发布时间】:2018-06-08 09:15:37
【问题描述】:

我正在使用BotAuth nuget 包在我的机器人上登录用户。最近我按照https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-state-azure-table-storage 中提到的步骤实现了 Azure Table storage 来存储和管理 bot 的状态数据。

我的 Global.asax.cs 文件如下所示:

public class WebApiApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {

        var store = new TableBotDataStore(CloudStorageAccount.DevelopmentStorageAccount);
        Conversation.UpdateContainer(builder =>
        {

            builder.Register(c => store)
                .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
                .AsSelf()
                .SingleInstance();

            builder.Register(c => new CachingBotDataStore(store,
                      CachingBotDataStoreConsistencyPolicy
                      .ETagBasedConsistency))
                      .As<IBotDataStore<BotData>>()
                      .AsSelf()
                      .InstancePerLifetimeScope();
        });
        GlobalConfiguration.Configure(WebApiConfig.Register);
    }
}

MessagesController 和 bot 模板中的一样:

[BotAuthentication]
public class MessagesController : ApiController
{
    /// <summary>
    /// POST: api/Messages
    /// Receive a message from a user and reply to it
    /// </summary>
    public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
    {
        if (activity.Type == ActivityTypes.Message)
        {
            await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
        }
        else
        {
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

    private Activity HandleSystemMessage(Activity message)
    { ...... }
}

现在,在测试时,我按预期获得了登录卡,单击并完成授权过程后,我在浏览器中收到以下错误:

{
"message": "An error has occurred.",
"exceptionMessage": "Object reference not set to an instance of an object.",
"exceptionType": "System.NullReferenceException",
"stackTrace": "   at BotAuth.AADv1.ADALAuthProvider.<GetTokenByAuthCodeAsync>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n   at BotAuth.Controllers.CallbackController.<Callback>d__3.MoveNext()"
}

我到底错过了什么?是不是一些autofac模块注册。有没有人有这方面的工作样本。

【问题讨论】:

  • 能否请您也发布您的消息控制器?
  • 添加了它@JasonSowers。消息控制器与机器人初始模板中的相同。我没有对此进行任何更改。
  • 我在github上找到this issue:"Enabling custom state service causes authentication failure",你可以参考weshackett的评论,尝试修改CallBack controller使用你配置的数据存储。
  • 非常感谢@FeiHan,修复成功了!!
  • @FeiHan 你指出的是对的,这个问题已经在MicrosoftDX/botauth修复了

标签: c# azure-storage botframework


【解决方案1】:

正如@FeiHan 在 cmets 中指出的,这是richdizz/BotAuth 中的一个未解决问题。 -"Enabling custom state service causes authentication failure"

此问题已在MicrosoftDX/botauth 中修复,因此首选使用此问题

【讨论】:

    猜你喜欢
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 2017-04-17
    • 1970-01-01
    • 1970-01-01
    • 2020-04-07
    • 2013-04-24
    相关资源
    最近更新 更多