diff --git a/samples/app-sso/csharp/App SSO Sample/AdapterWithErrorHandler.cs b/samples/app-sso/csharp/App SSO Sample/AdapterWithErrorHandler.cs index 10a304c527..bf8800a0a6 100644 --- a/samples/app-sso/csharp/App SSO Sample/AdapterWithErrorHandler.cs +++ b/samples/app-sso/csharp/App SSO Sample/AdapterWithErrorHandler.cs @@ -4,6 +4,7 @@ using System; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Integration.AspNet.Core; +using Microsoft.Bot.Builder.Teams; using Microsoft.Bot.Builder.TraceExtensions; using Microsoft.Bot.Connector.Authentication; using Microsoft.Extensions.Configuration; @@ -13,9 +14,11 @@ namespace Microsoft.BotBuilderSamples { public class AdapterWithErrorHandler : CloudAdapter { - public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger logger, ConversationState conversationState = null) - : base(auth, logger) + public AdapterWithErrorHandler(IConfiguration configuration, IStorage storage, BotFrameworkAuthentication auth, ILogger logger, ConversationState conversationState = null) + : base(auth,logger) { + base.Use(new TeamsSSOTokenExchangeMiddleware(storage, configuration["ConnectionName"])); + OnTurnError = async (turnContext, exception) => { // Log any leaked exception from the application. diff --git a/samples/app-sso/csharp/App SSO Sample/Bots/DialogBot.cs b/samples/app-sso/csharp/App SSO Sample/Bots/DialogBot.cs index f903a81f1d..5cdb731f3f 100644 --- a/samples/app-sso/csharp/App SSO Sample/Bots/DialogBot.cs +++ b/samples/app-sso/csharp/App SSO Sample/Bots/DialogBot.cs @@ -308,7 +308,7 @@ private async Task GetTokenResponse(ITurnContext } var userTokenClient = turnContext.TurnState.Get(); - var tokenResponse = await userTokenClient.GetUserTokenAsync(turnContext.Activity.From.Id, _connectionName, turnContext.Activity.ChannelId, magicCode, cancellationToken); + var tokenResponse = await userTokenClient.GetUserTokenAsync(turnContext.Activity.From.Id, _connectionName, turnContext.Activity.ChannelId, magicCode, cancellationToken).ConfigureAwait(false); return tokenResponse; } diff --git a/samples/app-sso/csharp/App SSO Sample/Dialogs/LogoutDialog.cs b/samples/app-sso/csharp/App SSO Sample/Dialogs/LogoutDialog.cs index 488cd7c6d5..1ed305ef39 100644 --- a/samples/app-sso/csharp/App SSO Sample/Dialogs/LogoutDialog.cs +++ b/samples/app-sso/csharp/App SSO Sample/Dialogs/LogoutDialog.cs @@ -46,17 +46,22 @@ public LogoutDialog(string id, string connectionName) { if (innerDc.Context.Activity.Type == ActivityTypes.Message) { - var text = innerDc.Context.Activity.Text.ToLowerInvariant(); - // Allow logout anywhere in the command - if (text.IndexOf("logout") >= 0) + var text = innerDc.Context.Activity.Text; + if (text != null) { - // The bot adapter encapsulates the authentication processes. - var botAdapter = innerDc.Context.Adapter; - var userTokenClient = innerDc.Context.TurnState.Get(); - await userTokenClient.SignOutUserAsync(innerDc.Context.Activity.From.Id, ConnectionName, innerDc.Context.Activity.ChannelId, cancellationToken); - await innerDc.Context.SendActivityAsync(MessageFactory.Text("You have been signed out."), cancellationToken); - return await innerDc.CancelAllDialogsAsync(cancellationToken); + text = innerDc.Context.Activity.Text.ToLowerInvariant(); + + // Allow logout anywhere in the command + if (text.IndexOf("logout") >= 0) + { + // The bot adapter encapsulates the authentication processes. + var botAdapter = innerDc.Context.Adapter; + var userTokenClient = innerDc.Context.TurnState.Get(); + await userTokenClient.SignOutUserAsync(innerDc.Context.Activity.From.Id, ConnectionName, innerDc.Context.Activity.ChannelId, cancellationToken); + await innerDc.Context.SendActivityAsync(MessageFactory.Text("You have been signed out."), cancellationToken); + return await innerDc.CancelAllDialogsAsync(cancellationToken); + } } }