Mandy
Mandy

Reputation: 11

OAuthPrompt and TeamsBotSsoPrompt and AdaptiveCard are not work for SSO in Teams Bot

I have tried 3 ways to implement SSO in Teams bot but none of them works. Is there any other way? What's wrong with these?

  1. Use of "OAuthPrompt" (botbuilder-dialogs) with source code from https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation-sso-quickstart/js
  2. Use of (oAuthCard) AdaptiveCard from CardFactory with source code from https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-sso-adaptivecard
  3. Use of TeamsBotSsoPrompt from "@microsoft/teamsfx" with source code from https://github.com/OfficeDev/teams-toolkit-samples/tree/v2.5.0/bot-sso

(1) "OAuthPrompt"

        async promptStep(stepContext) {
            try {
                return await stepContext.beginDialog(OAUTH_PROMPT);
            } catch (err) {
                console.error(err);
            }
        }
this.addDialog(new OAuthPrompt(OAUTH_PROMPT, {
connectionName: process.env.connectionName,
text: 'Please Sign In',
title: 'Sign In',
timeout: 300000
}));
    async loginStep(stepContext) {
        // Get the token from the previous step. Note that we could also have gotten the
        // token directly from the prompt itself. There is an example of this in the next method.
        const tokenResponse = stepContext.result;
        if (!tokenResponse || !tokenResponse.token) {
            await stepContext.context.sendActivity('Login was not successful please try again.');
        } else {
            const client = new SimpleGraphClient(tokenResponse.token);
            const me = await client.getMe();
            const title = me ? me.jobTitle : 'UnKnown';
            await stepContext.context.sendActivity(`You're logged in as ${me.displayName} (${me.userPrincipalName}); your job title is: ${title}; your photo is: `);
            const photoBase64 = await client.GetPhotoAsync(tokenResponse.token);
            const card = CardFactory.thumbnailCard("", CardFactory.images([photoBase64]));
            await stepContext.context.sendActivity({attachments: [card]});
            return await stepContext.prompt(CONFIRM_PROMPT, 'Would you like to view your token?');
        }
        return await stepContext.endDialog();
    }

(2) "AdaptiveCard"

(3) "TeamsBotSsoPrompt"

Upvotes: 1

Views: 85

Answers (1)

CurlyPaul
CurlyPaul

Reputation: 1148

I have been experiencing the same issue. I found that most of the examples state that the app reg's allowed redirect urls should include this value:

https://{BOT_DOMAIN}/auth-end

But from deconstructing the code scaffolded by TeamsToolkit I could see the url used there was actually:

https://{BOT_DOMAIN}/bot-auth-end

This seems to have solved my issue

Upvotes: 0

Related Questions