【发布时间】:2018-07-13 06:32:53
【问题描述】:
我正在尝试在https://github.com/Microsoft/BotBuilder/blob/master/Node/examples/basics-oauth/app.js 的 botbuilder nodejs 文档中运行 OAuth 示例
我已经在 Azure 上设置了 Azure Active Directory v1 应用程序,并使用图形 api 访问,并将 OAuth 连接添加到我的机器人。下面代码中使用的connectionName 已经准备好了。
但是当我运行从文档(上面提供的 github 链接)中获取的代码时,我得到:
TypeError: connector.getUserToken 不是函数
我在模拟器和网络聊天频道上都运行过这个,得到了同样的错误。
// Create your bot with a function to receive messages from the user
var bot = new builder.UniversalBot(connector, function (session) {
if (session.message.text == 'signout') {
// It is important to have a SignOut intent
connector.signOutUser(session.message.address, connectionName, (err, result) => {
if (!err) {
session.send('You are signed out.');
} else {
session.send('There was a problem signing you out.');
}
});
} else {
// First check whether the Azure Bot Service already has a token for this user
connector.getUserToken(session.message.address, connectionName, undefined, (err, result) => {
if (result) {
// If there is already a token, the bot can use it directly
session.send('You are already signed in with token: ' + result.token);
} else {
// If there not is already a token, the bot can send an OAuthCard to have the user log in
if (!session.userData.activeSignIn) {
session.send("Hello! Let's get you signed in!");
builder.OAuthCard.create(connector, session, connectionName, "Please sign in", "Sign in", (createSignInErr, signInMessage) =>
{
if (signInMessage) {
session.send(signInMessage);
session.userData.activeSignIn = true;
} else {
session.send("Something went wrong trying to sign you in.");
}
});
} else {
// Some clients require a 6 digit code validation so we can check that here
session.send("Let's see if that code works...");
connector.getUserToken(session.message.address, connectionName, session.message.text, (err2, tokenResponse) => {
if (tokenResponse) {
session.send('It worked! You are now signed in with token: ' + tokenResponse.token);
session.userData.activeSignIn = false;
} else {
session.send("Hmm, that code wasn't right");
}
});
}
}
});
}
})
【问题讨论】:
标签: node.js botframework