Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Use IBotDataStore instead of IStateClient
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Dahlvang committed Dec 18, 2017
1 parent f651b02 commit b6e9751
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions CSharp/BotAuth/Controllers/CallbackController.cs
Expand Up @@ -56,9 +56,10 @@ public async Task<HttpResponseMessage> Callback([FromUri] string code, [FromUri]
using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
{
// Get the UserData from the original conversation
IStateClient sc = scope.Resolve<IStateClient>();
BotData userData = await sc.BotState.GetUserDataAsync(message.ChannelId, message.From.Id);

IBotDataStore<BotData> stateStore = scope.Resolve<IBotDataStore<BotData>>();
var key = Address.FromActivity(message);
var userData = await stateStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);

// Get Access Token using authorization code
var authOptions = userData.GetProperty<AuthenticationOptions>($"{authProvider.Name}{ContextConstants.AuthOptions}");
var token = await authProvider.GetTokenByAuthCodeAsync(authOptions, code);
Expand All @@ -77,10 +78,11 @@ public async Task<HttpResponseMessage> Callback([FromUri] string code, [FromUri]
userData.SetProperty($"{authProvider.Name}{ContextConstants.MagicNumberKey}", magicNumber);
userData.SetProperty($"{authProvider.Name}{ContextConstants.MagicNumberValidated}", "false");
}
sc.BotState.SetUserData(message.ChannelId, message.From.Id, userData);
await stateStore.SaveAsync(key, BotStoreType.BotUserData, userData, CancellationToken.None);
await stateStore.FlushAsync(key, CancellationToken.None);
writeSuccessful = true;
}
catch (HttpOperationException)
catch (Exception)
{
writeSuccessful = false;
}
Expand Down

0 comments on commit b6e9751

Please sign in to comment.