我尝试了 3 种在 Teams bot 中实现 SSO 的方法,但都不起作用。还有其他办法吗?这些有什么问题吗?
(1)“OAuth提示”
“beginDialog(OAUTH_PROMPT)”后没有任何响应,最后请求超时。 OAuthPrompt 没有响应
之前没有像往常一样显示“继续”按钮
在“Azure Portal”的“Web Chat 测试”中运行良好
async promptStep(stepContext) {
try {
return await stepContext.beginDialog(OAUTH_PROMPT);
} catch (err) {
console.error(err);
}
}
this.addDialog(new OAuthPrompt(OAUTH_PROMPT, {
connectionName: process.env.connectionName,
text: 'Please Sign In',
title: 'Sign In',
timeout: 300000
}));
async loginStep(stepContext) {
// Get the token from the previous step. Note that we could also have gotten the
// token directly from the prompt itself. There is an example of this in the next method.
const tokenResponse = stepContext.result;
if (!tokenResponse || !tokenResponse.token) {
await stepContext.context.sendActivity('Login was not successful please try again.');
} else {
const client = new SimpleGraphClient(tokenResponse.token);
const me = await client.getMe();
const title = me ? me.jobTitle : 'UnKnown';
await stepContext.context.sendActivity(`You're logged in as ${me.displayName} (${me.userPrincipalName}); your job title is: ${title}; your photo is: `);
const photoBase64 = await client.GetPhotoAsync(tokenResponse.token);
const card = CardFactory.thumbnailCard("", CardFactory.images([photoBase64]));
await stepContext.context.sendActivity({attachments: [card]});
return await stepContext.prompt(CONFIRM_PROMPT, 'Would you like to view your token?');
}
return await stepContext.endDialog();
}
(2)“自适应卡”
虽然返回了token,但无法通过Microsoft Graph API验证token,错误为“invalid Audience”
没有弹出SSO登录窗口(与之前的OAuthPrompt Dialog相同)
我已确保在“应用程序注册”的“API权限”中设置了Graph User.Read
当我在环境变量中将机器人的“OAuth连接设置”中不存在的“xxxx”设置为“connectionName”时,仍然返回令牌
(3)“TeamsBotSso提示”
我遇到了同样的问题,但这对某些用户有效,但对其他人无效,在这篇post中,他们建议使用不同的团队版本,但我正在使用网络应用程序,但不起作用。