microsoft / botbuilder-js

Welcome to the Bot Framework SDK for JavaScript repository, which is the home for the libraries and packages that enable developers to build sophisticated bot applications using JavaScript.
https://github.com/Microsoft/botframework
MIT License
682 stars 279 forks source link

WebChat OAuth SSO doesn't continue after Login #2170

Closed Nitin2392 closed 4 years ago

Nitin2392 commented 4 years ago

Hey,

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.

compulim commented 4 years ago

This is related to SDK instead of Web Chat, because it is about the code on the bot side, not browser side.

Nitin2392 commented 4 years ago

Thanks @compulim . I've created a Stack Overflow Question to go with this - https://stackoverflow.com/questions/61548711/webchat-oauth-sso-doesnt-continue-with-dialog-flow-after-login

Keeping this issue open just in case someone has a workaround.

compulim commented 4 years ago

Thanks @Nitin2392.

I am also asking the team to transfer this issue to SDK to better surface the question and answers.

cleemullins commented 4 years ago

Transferring to JS Repo, and will traiage there.

cleemullins commented 4 years ago

@dmvtech, could you take a look at this?

Nitin2392 commented 4 years ago

Thanks @cleemullins

stevkan commented 4 years ago

@Nitin2392, can you please test using sample 18.bot-authentication? I just want to narrow down whether the flow is related specifically to login, SSO, or something else.

Presently, I can run sample #18 without issue. I'll next try testing using the blogs you reference and see what results are returned.

Nitin2392 commented 4 years ago

Sure @stevkan. I'll try that out and let you know what the results are

stevkan commented 4 years ago

If you can check / answer a few more questions, I'd appreciate it:

super(AUTH_DIALOG_ID, AUTH_WATERFALL_DIALOG, [
      step => this.promptStep(step),
      step => this.loginStep(step)
]);
stevkan commented 4 years ago

Closing due to a lack of activity. If the problem persists, please feel free to reopen.

Nitin2392 commented 4 years ago

I apologize for not responding @stevkan! We got sidetracked into another project.

So, we figured that we were missing out something and we fixed the issue.

We had to add in this piece of code for things to work

 this.onTokenResponseEvent(async (context, next) => {
      //Handle token 
    });

Thanks for your help!