I use the BotAuth nuget package to log users into my bot. I recently implemented an Azure Table repository for storing and managing bot state data by following the steps in https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-state-azure-table -storage .
My Global.asax.cs file looks like this:
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);
}
}
And MessageController is the same as in the bot template:
[BotAuthentication]
public class MessagesController : ApiController
{
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)
{ ...... }
}
Now, checking this, I get the login card as expected, and after clicking and completing the authorization process, I get the following error in the browser:
{
"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()"
}
What exactly am I missing? This is some kind of registration autofac module. Does anyone have a working sample for this.
source