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

port: [#3943] Add ShowSignInLink to OAuthPromptSettings (#5906) #4157

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 @@ -590,6 +590,7 @@ export interface OAuthPromptSettings {
connectionName: string;
endOnInvalidMessage?: boolean;
oAuthAppCredentials?: CoreAppCredentials;
showSignInLink?: boolean;
text?: string;
timeout?: number;
title: string;
Expand Down
11 changes: 10 additions & 1 deletion libraries/botbuilder-dialogs/src/prompts/oauthPrompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ export interface OAuthPromptSettings {
* by default for backwards compatibility.
*/
endOnInvalidMessage?: boolean;

/**
* (Optional) value to force the display of a Sign In link overriding the default behavior.
* True to display the SignInLink.
*/
showSignInLink?: boolean;
}

/**
Expand Down Expand Up @@ -352,7 +358,10 @@ export class OAuthPrompt extends Dialog {
if (turnContext.activity.channelId === Channels.Emulator) {
cardActionType = ActionTypes.OpenUrl;
}
} else if (!this.channelRequiresSignInLink(turnContext.activity.channelId)) {
} else if (
settings.showSignInLink === false ||
(!settings.showSignInLink && !this.channelRequiresSignInLink(turnContext.activity.channelId))
) {
link = undefined;
}

Expand Down
55 changes: 55 additions & 0 deletions libraries/botbuilder-dialogs/tests/oauthPrompt.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,61 @@ describe('OAuthPrompt', function () {
.startTest();
});
});

describe('OAuthPrompt signin link settings', function () {
let adapter;
const testCases = [
{ showSignInLinkValue: null, channelId: Channels.Test, shouldHaveSignInLink: false },
{ showSignInLinkValue: null, channelId: Channels.Msteams, shouldHaveSignInLink: true },
{ showSignInLinkValue: false, channelId: Channels.Test, shouldHaveSignInLink: false },
{ showSignInLinkValue: true, channelId: Channels.Test, shouldHaveSignInLink: true },
{ showSignInLinkValue: false, channelId: Channels.Msteams, shouldHaveSignInLink: false },
{ showSignInLinkValue: true, channelId: Channels.Msteams, shouldHaveSignInLink: true },
];

testCases.forEach((testCase) => {
const test = testCase.shouldHaveSignInLink ? 'show sign in link' : 'not show sign in link';
it(`Should ${test} for '${testCase.channelId}' channel and showSignInLink set to ${testCase.showSignInLinkValue}`, async function () {
const oAuthPromptSettings = {
showSignInLink: testCase.showSignInLinkValue,
};

adapter = new TestAdapter(async (turnContext) => {
const dc = await dialogs.createContext(turnContext);
const results = await dc.continueDialog();
if (results.status === DialogTurnStatus.empty) {
await dc.prompt('OAuthPrompt', {});
}
await convoState.saveChanges(turnContext);
});

//Create new ConversationState with MemoryStorage
const convoState = new ConversationState(new MemoryStorage());

//Create a DialogState property, DialogSet and OAuthPrompt
const dialogState = convoState.createProperty('dialogState');
const dialogs = new DialogSet(dialogState);

dialogs.add(new OAuthPrompt('OAuthPrompt', oAuthPromptSettings));

const initialActivity = {
channelId: testCase.channelId,
text: 'hello',
};

await adapter
.send(initialActivity)
.assertReply((activity) => {
assert.strictEqual(activity.attachments.length, 1);
assert.strictEqual(activity.attachments[0].contentType, CardFactory.contentTypes.oauthCard);
const oAuthCard = activity.attachments[0].content;
const cardAction = oAuthCard.buttons[0];
assert.strictEqual(testCase.shouldHaveSignInLink, cardAction.value != null);
})
.startTest();
});
});
});
});

function createReply(activity) {
Expand Down