AuthBot icon indicating copy to clipboard operation
AuthBot copied to clipboard

Unexpected behavior after implementing TableBotDataStore

Open waynehsmith opened this issue 8 years ago • 11 comments

Install Azure Storage Emulator and check operation

Steps to reproduce using SampleAADv2Bot:

  1. Install NuGet Package Autofac.WebApi2
  2. Install NuGet package Microsoft.BotBuilder.Azure

in Global.asax.cs

  1. Add the following after the Application Start method private void ConfigureBotTableStorage() { string tableName = "UserStateDev";

         TableBotDataStore store = new TableBotDataStore(CloudStorageAccount.DevelopmentStorageAccount, tableName);
    
    
         var builder = new ContainerBuilder();
    
         builder.Register(c => store)
             .Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
             .AsSelf()
             .SingleInstance();
    
         builder
             .Register(c =>
             {
                 return new CachingBotDataStore(store, CachingBotDataStoreConsistencyPolicy.ETagBasedConsistency);
             })
             .As<IBotDataStore<BotData>>()
             .AsSelf()
             .InstancePerLifetimeScope();
    
         // Get your HttpConfiguration.
         var config = GlobalConfiguration.Configuration;
    
         // Register your Web API controllers.
         builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
    
         // OPTIONAL: Register the Autofac filter provider.
         builder.RegisterWebApiFilterProvider(config);
    
         // Set the dependency resolver to be Autofac.
         //var container = builder.Build();
         builder.Update(Conversation.Container);
         config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container);
       @@}
    
  2. Before the line GlobalConfiguration.Configure(WebApiConfig.Register); insert the line ConfigureBotTableStorage();

  3. Save and compile

  4. Connect to the bot on http://localhost:3978/api/messages with the Bot Framework Channel Emulator

  5. Send logon to the bot inthe emulator

  6. Click the Authentication Required link in the emulator

  7. Log in using a Microsoft account in the browser window that opens

  8. Copy the magic number to send back to the bot

Expected behavior

Bot prompts for the magic number

Actual behavior

Bot displays sign-in card again.

waynehsmith avatar Jun 30 '17 02:06 waynehsmith

Same issue. Did you figure out how to get past this problem?

yellowwidget avatar Sep 01 '17 12:09 yellowwidget

If someone has the answer to this please post.

Thanks!

shrubby avatar Sep 01 '17 14:09 shrubby

Afraid not.. I'm still experiencing the problem.

waynehsmith avatar Sep 01 '17 18:09 waynehsmith

@weretygr @yellowwidget @shrubby

This is due to the fact that the current implementation of AuthBot is using the default state client in the OAuthCallbackController. Modifying the controller as follows will make it work with the TableBotDataStore implementation you are using:

  1. add a new class that implements IAddress:
public class AddressKey : IAddress
{
	public string BotId { get; set; }
	public string ChannelId { get; set; }
	public string ConversationId { get; set; }
	public string ServiceUrl { get; set; }
	public string UserId { get; set; }
}
  1. In place of IStateClient sc = scope.Resolve<IStateClient>(); retrieve the IBotDataStore<BotData>>
var botDataStore = scope.Resolve<IBotDataStore<BotData>>();`
  1. Instead of sc.BotState.GetUserData use the botDataStore to retrieve the user BotData object:
var userData = await botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);
  1. Instead of sc.BotState.SetUserData use the botDataStore to save the userData
await botDataStore.SaveAsync(key, BotStoreType.BotUserData, userData, CancellationToken.None);
await botDataStore.FlushAsync(key, CancellationToken.None);

I've created a PR for this: https://github.com/MicrosoftDX/AuthBot/pull/37

EricDahlvang avatar Sep 01 '17 23:09 EricDahlvang

@EricDahlvang - Thank you very much for your time investigating and figuring this out. I just tested and it works great.

yellowwidget avatar Sep 02 '17 00:09 yellowwidget

How do we fix this as we are using the AuthBot Nuget

vibjain avatar Dec 14 '17 08:12 vibjain

@vibjain Please switch your project to using BotAuth. AuthBot uses the default state client, and will be deprecated in the future.

https://www.nuget.org/packages/BotAuth/3.9.0-alpha https://github.com/richdizz/BotAuth

EricDahlvang avatar Dec 14 '17 17:12 EricDahlvang

Can you provide some guidance on moving to the BotAuth, currently I am stuggling with the ContextExtensions methods like Logout & GetAccessToken will we have to implements these methods ourselves now? I don't see them in the BothAuth anywhere. Thanks

vibjain avatar Dec 14 '17 22:12 vibjain

There is a little information on this page: https://github.com/richdizz/BotAuth/tree/7138ecf743423bcf13f53c09644ecdb60f0ec7da/CSharp and five sample applications. Have you reviewed those?

EricDahlvang avatar Dec 14 '17 23:12 EricDahlvang

Hi @EricDahlvang, thanks for your help. I think I made progress and changed my code form AuthBot to BotAuth. However after completing all the steps I am hitting this open issue. https://github.com/richdizz/BotAuth/issues/8 So, I cannot use the TableBotDataStore because AuthBot is not compatible & BotAuth has an open issue currently.

vibjain avatar Dec 15 '17 01:12 vibjain

@vibjain I've created a PR to address this: https://github.com/richdizz/BotAuth/pull/10 Until it is merged, you can clone the repository, modify the local CallbackController.cs and include it in your project.

I hope this helps.

EricDahlvang avatar Dec 15 '17 18:12 EricDahlvang