You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Microsoft Teams对话机器人SSO流程中OAUTH_PROMPT崩溃问题

Microsoft Teams对话机器人SSO流程中OAuthPrompt崩溃问题排查求助

问题现象

当用户发送“sign-in”命令时,机器人崩溃,抛出以下错误:

DialogContextError: OAuthPrompt.recognizeToken(): not supported by the current adapter
    at /Users/celine/dev/monia/node_modules/botbuilder-dialogs/lib/dialogContext.js:39:19
    at Generator.throw (<anonymous>)
    at rejected (/Users/celine/dev/monia/node_modules/botbuilder-dialogs/lib/dialogContext.js:6:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  error: Error: OAuthPrompt.recognizeToken(): not supported by the current adapter
      at OAuthPrompt.<anonymous> (/Users/celine/dev/monia/node_modules/botbuilder-dialogs/lib/prompts/oauthPrompt.js:355:27)
      at Generator.next (<anonymous>)
      at fulfilled (/Users/celine/dev/monia/node_modules/botbuilder-dialogs/lib/prompts/oauthPrompt.js:5:58)
      at processTicksAndRejections (node:internal/process/task_queues:96:5),
  dialogContext: {
    activeDialog: 'OAuthPrompt',
    parent: 'SsoDialog',
    stack: [ [Object], [Object] ]
  }
}

 [onTurnError] unhandled error: DialogContextError: OAuthPrompt.recognizeToken(): not supported by the current adapter

代码背景

代码基于微软官方对话机器人SSO快速启动JS示例,本地侧加载应用时运行正常。

配置验证

Azure Portal中OAuth连接测试正常,App Registration和Azure Bot的配置已按官方文档验证无误。

相关代码与配置

SsoDialog代码

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 {
            console.log("1")
            return await step.beginDialog(OAUTH_PROMPT);
        } catch (err) {
            console.error(err);
            return await step.endDialog();
        }
    }

    async oauth(step) {
        console.log("2")
        const id = step.context.activity.from.id
        const tokenResponse = step.result;
        console.log(tokenResponse)
        return step.beginDialog(SIGN_IN_DIALOG, tokenResponse)
    }
}

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

清单文件(manifest)摘要

{"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.11/MicrosoftTeams.schema.json",
    "version": "2.0.1",
    "manifestVersion": "1.11",
    "id": "392077da-6e68-43cd-897e-b45746da6a58",
    "packageName": "monia.app",
    "name": {
        "short": "Monia",
        "full": "Monia CRM"
    },
    "icons": {
        "outline": "outline.png",
        "color": "color.png"
    },
    "accentColor": "#FFFFFF",
    "showLoadingIndicator": true,
     "bots": [
        {
            "botId": "7e48fa83-a08b-44b1-bf7d-59a3a042965c",
            "scopes": [
                "personal"
            ]
        }
    ],
    "validDomains": [
        "token.botframework.com",
        "app.monia.ai"
    ],
    "webApplicationInfo": {
        "id": "7e48fa83-a08b-44b1-bf7d-59a3a042965c",
        "resource": "api://botid-7e48fa83-a08b-44b1-bf7d-59a3a042965c"
    },
    "subscriptionOffer": {
        "offerId": "neodeal.monia"
    }
}

.env.prod配置

MicrosoftAppType="Multi-tenant"
MicrosoftAppId="7e48fa83-a08b-44b1-bf7d-59a3a042965c"
MicrosoftAppPassword="bkc************"
MicrosoftAppTenantId="2152c805-66a7-4c7d-aad6-4ab6172cd85d"
AppCatalogTeamAppId="75c8f873-42f5-4f11-b5c2-60d05205eee8"
connectionName="Monia"

index.js摘要

const {
    BotFrameworkAdapter,
    createBotFrameworkAuthenticationFromConfiguration,
    ConfigurationServiceClientCredentialFactory,
    CloudAdapter,
    ConversationState,
    MemoryStorage,
    UserState
} = require('botbuilder');

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

const credentialsFactory = new ConfigurationServiceClientCredentialFactory({
    MicrosoftAppId: process.env.MicrosoftAppId,
    MicrosoftAppPassword: process.env.MicrosoftAppPassword,
    MicrosoftAppType: process.env.MicrosoftAppType,
    MicrosoftAppTenantId: process.env.MicrosoftAppTenantId
});

const botFrameworkAuthentication = createBotFrameworkAuthenticationFromConfiguration(null, credentialsFactory);

const adapter = new CloudAdapter(botFrameworkAuthentication);

app.post('/api/messages', async (req, res) => {
    await adapter.process(req, res, (context) => bot.run(context));
})

版本信息

botbuilder-dialogs版本为"botbuilder-dialogs": "~4.15.0"

其他说明

清单中包含subscriptionOffer配置,不确定是否与此问题相关。


可能的原因及排查方向

  • 版本兼容性问题:检查botbuilder核心包版本是否与botbuilder-dialogs版本(~4.15.0)完全一致。版本不匹配会导致CloudAdapter缺少OAuthPrompt所需的recognizeToken支持方法。
  • OAuth连接配置不一致:确认.env.prod中的connectionName与Azure Bot中配置的OAuth连接名称完全一致(注意大小写)。
  • 适配器初始化问题:验证CloudAdapter的初始化参数是否完整,确保botFrameworkAuthentication包含了OAuth流程所需的所有凭证配置。
  • 清单文件SSO配置错误:检查webApplicationInfo中的resource值是否与Azure App Registration里的应用ID URI完全匹配,SSO流程依赖该配置完成令牌获取。
  • subscriptionOffer干扰:临时移除清单中的subscriptionOffer配置,重新部署测试,排除该配置对SSO流程的潜在影响。

内容的提问来源于stack exchange,提问作者nfroidef

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 07:37:35