Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与我自己的OAuth服务器链接的帐户在Google上的操作缺少授权类型_Oauth_Action_Actions On Google_Account Linking - Fatal编程技术网

与我自己的OAuth服务器链接的帐户在Google上的操作缺少授权类型

与我自己的OAuth服务器链接的帐户在Google上的操作缺少授权类型,oauth,action,actions-on-google,account-linking,Oauth,Action,Actions On Google,Account Linking,我正在尝试实施smarthome操作。 它是从这个例子开始的 这是有效的 本例使用firestore作为云服务。 我想自己实现这个服务器。作为本地PC上的服务器进行第一次测试,可通过端口转发进行访问。 我创建了一个let's encrypt证书,并使用了nodejs express htpps服务器。 对于Oauth实现,我使用与示例相同的“不安全”代码 expressApp.get('/fakeauth', async (req, res) => { conso

我正在尝试实施smarthome操作。 它是从这个例子开始的

这是有效的

本例使用firestore作为云服务。
我想自己实现这个服务器。作为本地PC上的服务器进行第一次测试,可通过端口转发进行访问。
我创建了一个let's encrypt证书,并使用了nodejs express htpps服务器。
对于Oauth实现,我使用与示例相同的“不安全”代码

    expressApp.get('/fakeauth', async (req, res) => {
        console.log('fakeauth',req.headers, req.body, req.query);
        const responseurl = util.format('%s?code=%s&state=%s',
          decodeURIComponent(req.query.redirect_uri), 'xxxxxx',
          req.query.state);
        console.log(responseurl);
        return res.redirect(responseurl);
    });

    expressApp.all('/faketoken', async (req, res) => {
        console.log('faketoken',req.headers, req.body, req.query);
        const grantType = req.query.grant_type
          ? req.query.grant_type : req.body.grant_type;
        const secondsInDay = 86400; // 60 * 60 * 24
        const HTTP_STATUS_OK = 200;
        console.log(`Grant type ${grantType}`);

        let obj;
        if (grantType === 'authorization_code') {
          obj = {
            token_type: 'bearer',
            access_token: '123access',
            refresh_token: '123refresh',
            expires_in: secondsInDay,
          };
        } else if (grantType === 'refresh_token') {
          obj = {
            token_type: 'bearer',
            access_token: '123access',
            expires_in: secondsInDay,
          };
      }
        res.status(HTTP_STATUS_OK)
          .json(obj);
    });

现在我更改了将URL链接到本地服务器的帐户。 当我尝试连接到此操作时,它不起作用

对fakeauth端点的请求正常。
但是当google调用faketoken端点时,查询将丢失,正文为空。
请求的url为…/faketoken,没有任何查询和空正文

fakeauth请求的响应不会有问题,因为如果我将fakeauth请求发送到我的服务器,并将faketoken请求发送到firestore服务器,则帐户链接正在工作。
我第二次尝试。
将fakeauth发送到firestore服务器,将faketoken发送到我的服务器。
结果是一样的。没有查询也没有正文

我不知道我做错了什么,因为谷歌的请求是错误的

有人知道怎么回事吗。我已经搜索过了,但找不到有同样问题的人

谢谢你的帮助。
您可以使用验证帐户链接实现是否正常工作。以下是如何配置此工具以测试自定义端点:

  • 打开设置档位,将OAuth端点更改为自定义
  • 从操作控制台输入授权和令牌URL
  • 从操作控制台输入您的客户端ID和密码

  • 您不会授权任何Google API,因此对于步骤1,您只需输入类似“设备”的内容,然后单击授权API。您可以按照步骤2中的流程来验证授权和令牌交换是否正常工作。如果流程中出现任何错误,该工具将报告。

    为了帮助其他人,我将描述该问题

    我认为数据是作为url查询发送的,因为代码从查询对象读取数据

    但它们以内容类型发送到正文中:
    application/x-www-form-urlencoded

    如果我使用

    expressApp.use(bodyParser.urlencoded());
    

    数据被添加到查询中,原始测试代码正在运行。

    谢谢。这很有帮助。在这方面的帮助下,我发现了问题。