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

Use IBotDataStore instead of IStateClient in OAuthCallbackController #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions AuthBot/Controllers/OAuthCallbackController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ public async Task<HttpResponseMessage> OAuthCallback()
}

}

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; }
}

[HttpGet]
[Route("api/OAuthCallback")]
public async Task<HttpResponseMessage> OAuthCallback(
Expand Down Expand Up @@ -89,7 +99,7 @@ public async Task<HttpResponseMessage> OAuthCallback(
{
}

IStateClient sc = scope.Resolve<IStateClient>();


//IMPORTANT: DO NOT REMOVE THE MAGIC NUMBER CHECK THAT WE DO HERE. THIS IS AN ABSOLUTE SECURITY REQUIREMENT
//REMOVING THIS WILL REMOVE YOUR BOT AND YOUR USERS TO SECURITY VULNERABILITIES.
Expand All @@ -101,11 +111,25 @@ public async Task<HttpResponseMessage> OAuthCallback(
{
try
{
BotData userData = sc.BotState.GetUserData(message.ChannelId, message.From.Id);
var botDataStore = scope.Resolve<IBotDataStore<BotData>>();
var key = new AddressKey()
{
BotId = message.Recipient.Id,
ChannelId = message.ChannelId,
UserId = message.From.Id,
ConversationId = message.Conversation.Id,
ServiceUrl = message.ServiceUrl
};

var userData = await botDataStore.LoadAsync(key, BotStoreType.BotUserData, CancellationToken.None);

userData.SetProperty(ContextConstants.AuthResultKey, authResult);
userData.SetProperty(ContextConstants.MagicNumberKey, magicNumber);
userData.SetProperty(ContextConstants.MagicNumberValidated, "false");
sc.BotState.SetUserData(message.ChannelId, message.From.Id, userData);

await botDataStore.SaveAsync(key, BotStoreType.BotUserData, userData, CancellationToken.None);
await botDataStore.FlushAsync(key, CancellationToken.None);

writeSuccessful = true;
}
catch (HttpOperationException)
Expand Down