Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AzureBot.Services.Common/ContextConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
public class ContextConstants
{
public const string AuthResultKey = "authResult";
public const string SubscriptionIdKey = "subscriptionId";
}
}
13 changes: 13 additions & 0 deletions AzureBot/Controllers/MessagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ public virtual async Task<HttpResponseMessage> Post([FromBody] Activity activity
{
switch (activity.GetActivityType())
{
case ActivityTypes.Event:
var eventToken = activity.Value.ToString();

AuthBot.Models.AuthResult authResult = new AuthBot.Models.AuthResult();
object tokenCache = new Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache();
var token = await AuthBot.Helpers.AzureActiveDirectoryHelper.GetTokenByAuthCodeAsync(eventToken,
(Microsoft.IdentityModel.Clients.ActiveDirectory.TokenCache)tokenCache);

StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
userData.SetProperty(ContextConstants.AuthResultKey, token);
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
break;
case ActivityTypes.Message:
case ActivityTypes.ConversationUpdate:

Expand Down