Skip to content

Commit

Permalink
Merge pull request #1003 from OfficeDev/v-mfurquan/fixes-for-app-sso
Browse files Browse the repository at this point in the history
App SSO Fixes
  • Loading branch information
Pawank-MSFT authored Oct 23, 2023
2 parents 9ed3f61 + 171f9c6 commit 288b6da
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -13,9 +14,11 @@ namespace Microsoft.BotBuilderSamples
{
public class AdapterWithErrorHandler : CloudAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<IBotFrameworkHttpAdapter> logger, ConversationState conversationState = null)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration configuration, IStorage storage, BotFrameworkAuthentication auth, ILogger<IBotFrameworkHttpAdapter> logger, ConversationState conversationState = null)

Check warning on line 17 in samples/app-sso/csharp/App SSO Sample/AdapterWithErrorHandler.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.

Check warning on line 17 in samples/app-sso/csharp/App SSO Sample/AdapterWithErrorHandler.cs

View workflow job for this annotation

GitHub Actions / Build All "app-sso" csharp

Cannot convert null literal to non-nullable reference type.
: base(auth,logger)
{
base.Use(new TeamsSSOTokenExchangeMiddleware(storage, configuration["ConnectionName"]));

OnTurnError = async (turnContext, exception) =>
{
// Log any leaked exception from the application.
Expand Down
2 changes: 1 addition & 1 deletion samples/app-sso/csharp/App SSO Sample/Bots/DialogBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private async Task<TokenResponse> GetTokenResponse(ITurnContext<IInvokeActivity>
}

var userTokenClient = turnContext.TurnState.Get<UserTokenClient>();
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;
}
Expand Down
23 changes: 14 additions & 9 deletions samples/app-sso/csharp/App SSO Sample/Dialogs/LogoutDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserTokenClient>();
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<UserTokenClient>();
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);
}
}
}

Expand Down

0 comments on commit 288b6da

Please sign in to comment.