Skip to content

Commit

Permalink
Add ShowSignInLink to OAuthPromptSettings (#5906)
Browse files Browse the repository at this point in the history
* Add ShowSignInLink to OAuthPromptSettings

* Refactor tests
  • Loading branch information
mrivera-ms authored Oct 7, 2021
1 parent c20cc39 commit 80c4720
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public static async Task SendOAuthCardAsync(OAuthPromptSettings settings, ITurnC
cardActionType = ActionTypes.OpenUrl;
}
}
else if (!ChannelRequiresSignInLink(turnContext.Activity.ChannelId))
else if ((settings.ShowSignInLink != null && settings.ShowSignInLink == false) ||
(settings.ShowSignInLink == null && !ChannelRequiresSignInLink(turnContext.Activity.ChannelId)))
{
value = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public class OAuthPromptSettings
/// <value>True if the <see cref="OAuthPrompt"/> should automatically end upon receiving
/// an invalid message.</value>
public bool EndOnInvalidMessage { get; set; }

/// <summary>
/// Gets or sets an optional boolean value to force the display of a Sign In link overriding
/// the default behavior.
/// </summary>
/// <value>True to display the SignInLink.</value>
public bool? ShowSignInLink { get; set; }
}
}
51 changes: 51 additions & 0 deletions tests/Microsoft.Bot.Builder.Dialogs.Tests/OAuthPromptTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,57 @@ public async Task OAuthPromptInNotSupportedChannelShouldAddSignInCard()
.StartTestAsync();
}

[Theory]
[InlineData(null, Channels.Test, false)] //Do not override; ChannelRequiresSingInLink() returns false; Result: no link
[InlineData(null, Channels.Msteams, true)] //Do not override; ChannelRequiresSingInLink() returns true; Result: show link
[InlineData(false, Channels.Test, false)] //Override: no link; ChannelRequiresSingInLink() returns false; Result: no link
[InlineData(true, Channels.Test, true)] //Override: show link; ChannelRequiresSingInLink() returns false; Result: show link
[InlineData(false, Channels.Msteams, false)] //Override: no link; ChannelRequiresSingInLink() returns true; Result: no link
[InlineData(true, Channels.Msteams, true)] //Override: show link; ChannelRequiresSingInLink() returns true; Result: show link
public async Task OAuthPromptSignInLinkSettingsCases(bool? showSignInLinkValue, string channelId, bool shouldHaveSignInLink)
{
var oAuthPromptSettings = new OAuthPromptSettings();
oAuthPromptSettings.ShowSignInLink = showSignInLinkValue;

var convoState = new ConversationState(new MemoryStorage());
var dialogState = convoState.CreateProperty<DialogState>("dialogState");

var adapter = new TestAdapter()
.Use(new AutoSaveStateMiddleware(convoState));

// Create new DialogSet
var dialogs = new DialogSet(dialogState);
dialogs.Add(new OAuthPrompt("OAuthPrompt", oAuthPromptSettings));

BotCallbackHandler botCallbackHandler = async (turnContext, cancellationToken) =>
{
var dc = await dialogs.CreateContextAsync(turnContext, cancellationToken);

var results = await dc.ContinueDialogAsync(cancellationToken);
if (results.Status == DialogTurnStatus.Empty)
{
await dc.PromptAsync("OAuthPrompt", new PromptOptions(), cancellationToken: cancellationToken);
}
};

var initialActivity = new Activity()
{
ChannelId = channelId,
Text = "hello"
};
await new TestFlow(adapter, botCallbackHandler)
.Send(initialActivity)
.AssertReply(activity =>
{
Assert.Single(((Activity)activity).Attachments);
Assert.Equal(OAuthCard.ContentType, ((Activity)activity).Attachments[0].ContentType);
var oAuthCard = (OAuthCard)((Activity)activity).Attachments[0].Content;
var cardAction = oAuthCard.Buttons[0];
Assert.Equal(shouldHaveSignInLink, cardAction.Value != null);
})
.StartTestAsync();
}

[Fact]
public async Task TestAdapterTokenExchange()
{
Expand Down

0 comments on commit 80c4720

Please sign in to comment.