如何更改 OAuthCard 的 "Sign In" 按钮的行为以仅打开 URL 而不重定向

How to change the behavior of the "Sign In" button of the OAuthCard to just open the URL without redirect

我将网络聊天(来自 Microsoft Bot Framework)运行 嵌入到另一个使用浏览器的应用程序中。

尝试向机器人添加身份验证时,我意识到 OAuthCard 的登录按钮不起作用,因为我正在尝试打开一个空白的 window (about:blank) 用于将用户重定向到身份提供者的登录页面。在嵌入式上下文中,OS 不知道如何处理 about:blank 调用。见下图。

我正在关注这个例子,它实际上是在浏览器上运行的:
Add authentication to a bot
Bot authentication example

我想知道是否有办法将 OAuthCard 的“登录”按钮的行为更改为直接打开登录 URI,而不使用 about:blank 和重定向技术。

我发现可以在 Webchat 进行呈现之前将 OAuthCard 的按钮类型从“signin”更改为“openUrl”后,我才能够让它工作。

Microsoft Teams 似乎也存在类似问题。我在这里找到了线索:
https://github.com/microsoft/botframework-sdk/issues/4768

根据Webchat参考,可以交叉和改变活动:
https://github.com/microsoft/BotFramework-WebChat/blob/master/docs/API.md#web-chat-api-reference

这是解决方案,更像是一个 hack。我希望这在将来是可配置的:

      // Change the button type in the OAuthCard to the type of OpenUrl
      const store = window.WebChat.createStore( {}, ( { dispatch } ) => next => action => {
        if (action.type == "DIRECT_LINE/QUEUE_INCOMING_ACTIVITY" && 
            action.payload.activity.hasOwnProperty("attachments") && 
            action.payload.activity.attachments[0].contentType === "application/vnd.microsoft.card.oauth") {
          action.payload.activity.attachments[0].content.buttons[0].type = "openUrl";
        }
        return next( action );
      });
      
      // Pass the store to the webchat
      window.WebChat.renderWebChat({
         ...,
         store
      });