BotBuilder,Direct Line API返回"tokenParameters missing User".具有增强的身份验证选项 [英] BotBuilder, Direct Line API returns "tokenParameters is missing User" with Enhanced authentication options

查看:176
本文介绍了BotBuilder,Direct Line API返回"tokenParameters missing User".具有增强的身份验证选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个发布在Azure帐户上的机器人,我正在尝试从中删除魔术代码,因此请遵循

I have a bot published on an Azure account, from which I'm trying to take the magic code out, so following the Direct Line documentation I improved the code to hide the token. But once the Enhanced authentication options are enabled I always get the same response.

{
  "error": {
    "code": "BadArgument",
    "message": "tokenParameters is missing User."
  }
}

我无法弄清楚如何用用户数据完成HTTP请求.

And I am not able to figure out how to complete the HTTP Request with the user data.

该机器人基于BotFramework SDK v4,以及一些用于使用封装的密钥请求和刷新令牌的控制器. 我通过不同的错误方法将 userId 数据添加到请求中,从而始终获得相同的结果.

The bot is based on BotFramework SDK v4, plus some controllers for requesting and refreshing the token using the encapsulted secret key. I added userId data to the request by different and wrong ways getting always the same result.

请求令牌代码

server.post('/dl/tokenRequest', async (_, res) => {
  try {
    const userId = "dl_testuser1";
    const askToken = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', {
      headers: {
        authorization: Bearer ${ process.env.DIRECT_LINE_SECRET }
      },
      //HERE THE userId INFORMATION,
      method: 'POST'
    });
    const json = await askToken.json();
    if ('error' in json) {
      console.log('Requesting token - Error');
      res.send(500);
    } else {
      console.log(`Requesting token ` + json.token);
      res.send(json);
    }
  } catch (err) {
    res.send(500);
  }
});

在启用增强型工具之前,我应该如何放置用户信息以从DL API获得OK?

How should I put the user's information to obtain an OK from the DL API as I received before enabling the Enhanced tool?

推荐答案

似乎您的标头中缺少Content-Type.看看下面的代码片段.

It looks like you are missing the Content-Type in your header. Take a look at the code snippet below.

try {
  const res = await fetch('https://directline.botframework.com/v3/directline/tokens/generate', 
    { 
      method: 'POST',
      headers: {
        'Authorization': `Bearer <SECRET>`,
        'Content-Type': 'application/json'
      },
      body: {
        user: { 
          id: "dl_123", // user id must start with 'dl_'
          name: "user" 
        }
      }
    });

    const json = await res.json();

} catch (error) {
  console.log(error)
}

注意,您不必检查JSON响应中是否有错误"-try-catch块应负责解决这一问题.

Note, you shouldn't have to check is 'error' is in the JSON response - the try-catch block should take care of that.

希望这会有所帮助!

这篇关于BotBuilder,Direct Line API返回"tokenParameters missing User".具有增强的身份验证选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆