How to use the botbuilder-dialogs.OAuthPrompt function in botbuilder-dialogs

To help you get started, we’ve selected a few botbuilder-dialogs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / BotBuilder-Samples / javascript_nodejs / 19.bot-authentication / bot.js View on Github external
constructor(conversationState) {
        // Create a new state accessor property. See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
        this.conversationState = conversationState;
        this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
        this.dialogs = new DialogSet(this.dialogState);

        // Add prompts that will be used by the bot.
        this.dialogs.add(new ChoicePrompt(CONFIRM_PROMPT));
        this.dialogs.add(new OAuthPrompt(OAUTH_PROMPT, OAUTH_SETTINGS));

        // The WaterfallDialog that controls the flow of the conversation.
        this.dialogs.add(new WaterfallDialog(AUTH_DIALOG, [
            this.oauthPrompt,
            this.loginResults,
            this.displayToken
        ]));
    }
github microsoft / botframework-solutions / templates / Enterprise-Template / src / typescript / enterprise-bot / src / dialogs / authentication / authenticationDialog.ts View on Github external
constructor(connectionName: string) {
        super(AuthenticationDialog.name);
        this.initialDialogId = AuthenticationDialog.name;
        this.connectionName = connectionName;

        // tslint:disable-next-line:no-any
        const authenticate: ((sc: WaterfallStepContext<{}>) => Promise>)[] = [
            this.prompToLogin.bind(this),
            this.finishLoginhDialog.bind(this)
        ];

        this.addDialog(new WaterfallDialog(this.initialDialogId, authenticate));
        this.addDialog(new OAuthPrompt(DialogIds.LoginPrompt, {
            connectionName: this.connectionName,
            text: i18n.__('authentication.prompt'),
            title: i18n.__('authentication.title')
        }));
    }
github microsoft / botbuilder-js / samples / dialogs / oauthbot-ts / lib / app.js View on Github external
if (!context.responded) {
                    yield dc.beginDialog('displayToken');
                }
            }
        }
        else if (context.activity.type === 'event' || context.activity.type === 'invoke') {
            // Create dialog context and continue executing the "current" dialog, if any.
            // This is important for OAuthCards because tokens can be received via TokenResponse events
            const state = conversationState.get(context);
            const dc = dialogs.createContext(context, state);
            yield dc.continueDialog();
        }
    }));
});
// Add a dialog to get a token for the connectrion
dialogs.add('loginPrompt', new botbuilder_dialogs_1.OAuthPrompt({
    connectionName: connectionName,
    text: "Please Sign In",
    title: "Sign In",
    timeout: 300000 // User has 5 minutes to login
}));
// Add a dialog to display the token once the user has logged in
dialogs.add('displayToken', [
    function (dc) {
        return __awaiter(this, void 0, void 0, function* () {
            yield dc.beginDialog('loginPrompt');
        });
    },
    function (dc, token) {
        return __awaiter(this, void 0, void 0, function* () {
            if (token) {
                // Continue with task needing access token
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 18.bot-authentication / bot.js View on Github external
constructor(conversationState) {
        this.conversationState = conversationState;

        // Create a new state accessor property.
        // See https://aka.ms/about-bot-state-accessors to learn more about bot state and state accessors.
        this.dialogState = this.conversationState.createProperty(DIALOG_STATE_PROPERTY);
        this.dialogs = new DialogSet(this.dialogState);

        // Add prompts that will be used by the bot.
        this.dialogs.add(new ChoicePrompt(CONFIRM_PROMPT));
        this.dialogs.add(new OAuthPrompt(OAUTH_PROMPT, OAUTH_SETTINGS));

        // The WaterfallDialog that controls the flow of the conversation.
        this.dialogs.add(new WaterfallDialog(AUTH_DIALOG, [
            this.oauthPrompt,
            this.loginResults,
            this.displayToken
        ]));
    }
github microsoft / botbuilder-js / samples / dialogs / oauthbot-ts / src / app.ts View on Github external
if (!context.responded) {
                    await dc.beginDialog('displayToken');
                }
            }
        } else if (context.activity.type === 'event' || context.activity.type === 'invoke') {
            // Create dialog context and continue executing the "current" dialog, if any.
            // This is important for OAuthCards because tokens can be received via TokenResponse events
            const state = conversationState.get(context);
            const dc = dialogs.createContext(context, state);
            await dc.continueDialog();
        }
    });
});

// Add a dialog to get a token for the connectrion
dialogs.add('loginPrompt', new OAuthPrompt({
    connectionName: connectionName,
    text: "Please Sign In",
    title: "Sign In",
    timeout: 300000        // User has 5 minutes to login
}));
 
// Add a dialog to display the token once the user has logged in
 dialogs.add('displayToken', [
      async function (dc) {
          await dc.beginDialog('loginPrompt');
      },
      async function (dc, token) {
          if (token) {
              // Continue with task needing access token
              await dc.context.sendActivity(`Your token is: ` + token.token);
          } else {
github microsoft / botframework-solutions / templates / Virtual-Assistant-Template / typescript / samples / sample-assistant / src / dialogs / authenticationDialog.ts View on Github external
constructor(connectionName: string) {
        super(AuthenticationDialog.name);
        this.initialDialogId = AuthenticationDialog.name;
        this.connectionName = connectionName;
        const authenticate: ((sc: WaterfallStepContext) => Promise)[] = [
            this.prompToLogin.bind(this),
            this.finishLoginhDialog.bind(this)
        ];

        this.addDialog(new WaterfallDialog(this.initialDialogId, authenticate));
        this.addDialog(new OAuthPrompt(DialogIds.loginPrompt, {
            connectionName: this.connectionName,
            text: i18next.t('authentication.prompt'),
            title: i18next.t('authentication.title')
        }));
    }
github compulim / BotFramework-MockBot / src / commands / OAuthCard2.ts View on Github external
import { TurnContext, ActivityTypes } from 'botbuilder';
import { OAuthPrompt, DialogSet, ChoicePrompt, DialogReason, WaterfallDialog } from 'botbuilder-dialogs';
import fetch from 'node-fetch';

import conversationState from '../singletonConversationState';

const dialogState = conversationState['createProperty']('dialogState');
const dialogs = new DialogSet(dialogState);

dialogs.add(new ChoicePrompt('CONFIRM_PROMPT'));

dialogs.add(new OAuthPrompt('OAUTH_PROMPT', {
  connectionName: process.env.OAUTH_CONNECTION_NAME,
  text: 'Sign into GitHub',
  title: 'Sign in'
}));

dialogs.add(new WaterfallDialog('AUTH_DIALOG', [
  async step => await step.prompt('OAUTH_PROMPT', {}),
  async step => {
    if (step.result) {
      await step.context.sendActivity('You have now logged in.');

      return await step.next(step.result);
    } else {
      await step.context.sendActivity('Failed to login, please try again.');

      return await step.endDialog();
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 24.bot-authentication-msgraph / dialogs / mainDialog.js View on Github external
constructor() {
        super('MainDialog');
        this.addDialog(new ChoicePrompt(CHOICE_PROMPT))
            .addDialog(new OAuthPrompt(OAUTH_PROMPT, {
                connectionName: process.env.ConnectionName,
                text: 'Please login',
                title: 'Login',
                timeout: 300000
            }))
            .addDialog(new TextPrompt(TEXT_PROMPT))
            .addDialog(new WaterfallDialog(MAIN_WATERFALL_DIALOG, [
                this.promptStep.bind(this),
                this.loginStep.bind(this),
                this.commandStep.bind(this),
                this.processStep.bind(this)
            ]));

        this.initialDialogId = MAIN_WATERFALL_DIALOG;
    }
github microsoft / BotBuilder-Samples / samples / javascript_typescript / 52.enterprise-bot / src / dialogs / signin / signInDialog.ts View on Github external
constructor(connectionName: string) {
        super("SignInDialog");
        this.initialDialogId = "SignInDialog";
        this._connectionName = connectionName;
        this._responder = new SignInResponses();

        this.addDialog(new WaterfallDialog(this.initialDialogId, [
            this.askToLogin.bind(this),
            this.finishAuthDialog.bind(this),
        ]));
        this.addDialog(new OAuthPrompt(this._loginPrompt, {
            connectionName: this._connectionName,
            text: "Please sign in to access this bot.",
            title: "Sign In",
        }));
    }
github microsoft / BotBuilder-Samples / samples / javascript_nodejs / 46.teams-auth / dialogs / mainDialog.js View on Github external
constructor() {
        super(MAIN_DIALOG, process.env.connectionName);

        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(MAIN_WATERFALL_DIALOG, [
            this.promptStep.bind(this),
            this.loginStep.bind(this),
            this.displayTokenPhase1.bind(this),
            this.displayTokenPhase2.bind(this)
        ]));

        this.initialDialogId = MAIN_WATERFALL_DIALOG;
    }