我通过从github下载示例测试了身份验证。修改连接名称并登录并显示令牌后,我已成功发布到Azure。但是,当我开始在我的bot应用程序(使用的企业bot)中集成相同的身份验证后,点击登录按钮并将幻数复制回bot之后,我没有得到令牌响应。
我正在使用网络聊天直接电话。我已经正确配置了重定向URL。 当我检查应用程序洞察力以跟踪错误时,我收到以下错误消息
GET / api / usertoken / GetToken 结果代码:404
下面是代码:
public AuthenticationDialog(string connectionName)
: base(nameof(AuthenticationDialog))
{
InitialDialogId = nameof(AuthenticationDialog);
ConnectionName = connectionName;
var authenticate = new WaterfallStep[]
{
PromptToLogin,
FinishLoginDialog,
};
AddDialog(new OAuthPrompt(DialogIds.LoginPrompt, new OAuthPromptSettings()
{
ConnectionName = ConnectionName,
Title = AuthenticationStrings.TITLE,
Text = AuthenticationStrings.PROMPT,
Timeout = 300000,
}));
AddDialog(new WaterfallDialog(InitialDialogId, authenticate));
}
private async Task<DialogTurnResult> PromptToLogin(WaterfallStepContext sc, CancellationToken cancellationToken)
{
return await sc.PromptAsync(DialogIds.LoginPrompt, new PromptOptions(),cancellationToken);
}
private async Task<DialogTurnResult> FinishLoginDialog(WaterfallStepContext step, CancellationToken cancellationToken)
{
if (step.Result != null)
{
// We do not need to store the token in the bot. When we need the token we can
// send another prompt. If the token is valid the user will not need to log back in.
// The token will be available in the Result property of the task.
var tokenResponse = step.Result as TokenResponse;
// If we have the token use the user is authenticated so we may use it to make API calls.
if (tokenResponse?.Token != null)
{
await step.Context.SendActivityAsync($"Your token is: {tokenResponse.Token}", cancellationToken: cancellationToken);
}
else
{
await step.Context.SendActivityAsync("We couldn't log you in. Please try again later.", cancellationToken: cancellationToken);
}
}
return await step.EndDialogAsync(cancellationToken: cancellationToken);
}
注意:我同时尝试了AAD V1和AAD V2都导致相同的错误。 我在做什么错了。
更新 目标框架:.NET Core 2.2 Bot Builder版本:4.3.1
HTML代码:
<!DOCTYPE html>
<html>
<body>
<div id="webchat" role="main" style="height:700px;"></div>
<script src="https://cdn.botframework.com/botframework-
webchat/latest/webchat.js"></script>
<script>
window.WebChat.renderWebChat({
directLine: window.WebChat.createDirectLine({ token: 'tokenid' }),
userID: 'YOUR_USER_ID',
username: 'User',
locale: 'en-US',
botAvatarInitials: 'Bot',
userAvatarInitials: 'WW'
}, document.getElementById('webchat'));
</script>
</body>
</html>
当我检查chrome开发工具时,我遇到了错误
https://directline.botframework.com/v3/directline/session/getsessionid
{ “错误”:{ “ code”:“ BadArgument”, “消息”:“缺少令牌或机密” } }