0

When prompting the user for permissions as in screen 1, nothing appears when the user clicks on "Continue".

oauth permission prompt

The code seems to be getting lost somewhere in the OAUTH_PROMPT dialog from Microsoft botbuilder-dialogs.

We already check with someone from validation team and it seems like everything is in order in the Azure portal.

The code is as in the Github sample (bot-conversation-sso-quickstart), as you can see below.

index.js

const {
    CloudAdapter,
    ConversationState,
    MemoryStorage,
    UserState,
    ConfigurationBotFrameworkAuthentication,
    TeamsSSOTokenExchangeMiddleware,
} = require('botbuilder');

const { DialogBot } = require('./bots/dialogBot');
const { MainDialog } = require('./dialogs/mainDialog');

const LANGUAGE_PREFERENCE = 'language_preference';

const botFrameworkAuthentication = new ConfigurationBotFrameworkAuthentication(process.env);
const adapter = new CloudAdapter(botFrameworkAuthentication);

const memoryStorage = new MemoryStorage();
const tokenExchangeMiddleware = new TeamsSSOTokenExchangeMiddleware(memoryStorage, process.env.connectionName);
adapter.use(tokenExchangeMiddleware);

// Create conversation and user state with in-memory storage provider.
const conversationState = new ConversationState(memoryStorage);
const userState = new UserState(memoryStorage);

const languagePreferenceProperty = userState.createProperty(LANGUAGE_PREFERENCE);

const translator = new MicrosoftTranslator(process.env.translatorKey);
adapter.use(new TranslatorMiddleware(translator, languagePreferenceProperty));

const dialog = new MainDialog(userState);
const bot = new DialogBot(process.env.ExpireAfterSeconds, conversationState, userState, dialog, languagePreferenceProperty);

ssoDialog.js

const { ConfirmPrompt, OAuthPrompt, ComponentDialog, DialogSet, DialogTurnStatus, WaterfallDialog } = require('botbuilder-dialogs');
const { SignInDialog, SIGN_IN_DIALOG } = require('./signInDialog');
const { MoniaDialog } = require('./../moniaDialog');
const { polyfills } = require('isomorphic-fetch');
const { CardFactory } = require('botbuilder-core');

const SSO_DIALOG = 'SsoDialog';
const SSO_WATERFALL_DIALOG = 'SsoWaterfallDialog';
const OAUTH_PROMPT = 'OAuthPrompt';
const CONFIRM_PROMPT = 'ConfirmPrompt';

class SsoDialog extends MoniaDialog {
    constructor() {
        super(SSO_DIALOG, process.env.connectionName);

        this.addDialog(new SignInDialog())
        this.addDialog(new OAuthPrompt(OAUTH_PROMPT, {
            connectionName: process.env.connectionName,
            text: 'Please Sign In',
            title: 'Sign In',
            timeout: 300000
        }));
        this.addDialog(new ConfirmPrompt(CONFIRM_PROMPT));
        this.addDialog(new WaterfallDialog(SSO_WATERFALL_DIALOG, [
            this.promptStep.bind(this),
            this.oauth.bind(this)
        ]));

        this.initialDialogId = SSO_WATERFALL_DIALOG;
    }

    async run(context, accessor) {
        const dialogSet = new DialogSet(accessor);
        dialogSet.add(this);
        const dialogContext = await dialogSet.createContext(context);
        const results = await dialogContext.continueDialog();
        if (results.status === DialogTurnStatus.empty) {
            await dialogContext.beginDialog(this.id);
        }
    }

    async promptStep(step) {
        try {
            return await step.beginDialog(OAUTH_PROMPT);
        } catch (err) {
            console.error(err);
            return await step.endDialog();
        }
    }

    async oauth(step) {
        await this.typing(step)
        const id = step.context.activity.from.id
        const tokenResponse = step.result;
        return step.beginDialog(SIGN_IN_DIALOG, tokenResponse)
    }
}

module.exports.SsoDialog = SsoDialog;
module.exports.SSO_DIALOG = SSO_DIALOG;

Although, once the user accepts the permissions, for example via teams admin center, they can get a valid token and everything works well.

Do you have any idea for what might be malfunctioning here ?

nfroidef
  • 1
  • 3
  • Could you please let us know which sample you are referring to here? – Prasad-MSFT Jul 13 '23 at 06:25
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Jul 13 '23 at 09:24
  • I am referring to this sample : https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/bot-conversation-sso-quickstart/js – nfroidef Jul 14 '23 at 11:00
  • We tried with above sample and its working correctly at our end. On installing the app it sent me Sign In card and on clicking on sign in button and entering credentials i am able to sign in and it sends me token after that. https://i.stack.imgur.com/wBh4N.png – Prasad-MSFT Jul 17 '23 at 05:01
  • And yet everything from this sample is correctly incorporated to my code, and is working well on my side. For an unknown reason, prompt doesn't shows up when validation team tries to log in to a new test account to do the SSO. They also told me that the prompt was supposed to show up right after the installation, and yet in your screenshot, you typed login before getting the prompt. – nfroidef Jul 28 '23 at 14:26

0 Answers0