Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Unexpected behavior after implementing TableBotDataStore #28

Open
waynehsmith opened this issue Jun 30, 2017 · 11 comments
Open

Unexpected behavior after implementing TableBotDataStore #28

waynehsmith opened this issue Jun 30, 2017 · 11 comments

Comments

@waynehsmith
Copy link

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.

@yellowwidget
Copy link

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

@shrubby
Copy link

shrubby commented Sep 1, 2017

If someone has the answer to this please post.

Thanks!

@waynehsmith
Copy link
Author

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

@EricDahlvang
Copy link

@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(); retrieve the IBotDataStore>
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: #37

@yellowwidget
Copy link

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

@vibjain
Copy link

vibjain commented Dec 14, 2017

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

@EricDahlvang
Copy link

@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

@vibjain
Copy link

vibjain commented Dec 14, 2017

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

@EricDahlvang
Copy link

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

@vibjain
Copy link

vibjain commented Dec 15, 2017

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.

@EricDahlvang
Copy link

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants