0
votes

The issue we're having right now is that once we click on the Login button in the OAuthPrompt from the webchat, the SSO takes over and the Sign in Happens but when the flow returns to the webchat, nothing happens and the bot just hangs.

In the Microsoft Bot Framework (v4) bot that we're building, we have implemented the new SSO OAuth features that were recommended in this blog here and here.

1) We initially had an <iframe> setup which prompted for the Magic code.

2) We then changed the <iframe> setup and migrated to a DirectLine channel by changing the webchat's source code to exchange the bot secret for a token (we also pass a unique userId in the format - dl_guid())

3) We pass that token down to window.WebChat.createDirectLine method sourced from the CDN - https://cdn.botframework.com/botframework-webchat/latest/webchat.js

4) We have AADV2 Setup with the right scopes and we also have the bot configured for this AAD.

5) We also have Enhanced Authentication options enabled for the DirectLine channel and have the localhost dev environment & the hosted server environment added to the Trusted Origin list

6) We've also enabled 3rd party cookies in the browser

Screenshots

image

Bot Source Code

Here's a snippet from the AuthDialog that we are using (TypeScript)

export class AuthDialog extends BaseDialog {
  constructor(
    private dialogContextUtils: DialogContextUtils,
    private userManager: UserManager,
    appConfig: AppConfig
  ) {
    super(AUTH_DIALOG_ID, AUTH_WATERFALL_DIALOG, [
      step => this.promptStep(step),
      step => this.loginStep(step)
    ]);

    this.addDialog(
      new OAuthPrompt(OAUTH_PROMPT, {
        connectionName: appConfig.connectionName,
        text: 'Please login',
        title: 'Login',
        timeout: 300000
      })
    );
  }

  private async promptStep(step: WaterfallStepContext) {
    return await step.beginDialog(OAUTH_PROMPT);
  }

  private async loginStep(step: WaterfallStepContext) {
    const tokenResponse = step.result;

    if (tokenResponse) {
            await step.context.sendActivity(`Hi`);   
    }

    return await step.endDialog(tokenResponse);
  }

If we take a look at the code, the bot should essentially enter into loginStep but it doesn't (Tried it by setting breakpoints)

Would really appreciate some help with this issue.

1

1 Answers

0
votes

I figured the issue out. We had to add this line of code in our middleware and things worked

this.onTokenResponseEvent(async (context, next) => {

//Handle token

});