无法从 aws lambda 中的 google 智能家居操作同步意图获取 oauth 令牌

Can't get oauth token from google smart home action sync intent in aws lambda

我正在使用 aws lambda 函数进行 google 智能家居操作。我使用 aws api gateway for fulfillment url 到达 lambda。我可以使用以下代码成功处理 google 助手的意图:-

const {smarthome} = require('actions-on-google');
const app = smarthome();

app.onExecute((body, headers) => {
  return {
    requestId: 'ff36...',
    payload: {
      // ...
    },
  };
});

app.onQuery((body, headers) => {
  return {
    requestId: 'ff36...',
    payload: {
      // ...
    },
  };
});

app.onSync((body, headers) => {
  console.log("body: "+JSON.stringify(body));
  console.log("headers: "+JSON.stringify(headers));
  return {
    requestId: 'ff36...',
    payload: {
      // ...
    },
  };
});

exports.handler = app;

在这个函数中硬编码设备细节,它可以成功反映在google家庭应用程序中。但是要获得用户的实际设备,我需要从“SYNC”意图中获取 oauth 令牌。但是我从这段代码中得到的只是这个输出:-

body: {"inputs":[{"intent":"action.devices.SYNC"}],"requestId":"5604033533610827657"}

headers: {}

不同于Alexa技能的“发现指令”在request.directive.endpoint.scope.token中包含token,google的intent似乎没有携带。对于 O Auth,我使用的是 AWS Cognito,它可以与 Alexa Account linking 一起正常工作,对于 google home,它也可以成功 link 我在 lambda 函数中硬编码的帐户和显示设备。

根据回答,令牌在

headers.authorization.substr(7)

我试过了,但一无所获。它显示

"Cannot read property 'substr' of undefined".

lambda handler in the Actions on Google client library assumes that the request headers are present at event.headers within the input event parameter of a Lambda Proxy Integration. If you have a custom Lambda integration or have otherwise modified the input mapping, you may need to edit your mapping template 以确保 headers 放置在客户端库期望的位置。