Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ShowSignInLink to OAuthPromptSettings #5906

Merged
merged 2 commits into from
Oct 7, 2021
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
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]
gabog marked this conversation as resolved.
Show resolved Hide resolved
[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