如何从智能家居的 google 操作中使用的 OAuth 获取访问令牌

How to fetch access token from OAuth used in google action for smart home

对于我的智能家居操作,我使用了假身份验证,如 codelab-smartwasher 应用程序中所示。 (用于测试目的)。该应用程序运行良好。我已经构建了自己的代码来使用我的设备(开关)。现在,当我实施使用我自己的自定义 OAuth 服务器的 OAuth 时。我无法弄清楚如何在我的代码中实现它。当我测试时,OAuth 正在根据需要工作。但我需要帮助将其与 google 操作集成。我在获取访问令牌时遇到问题。 代码如下:

exports.fakeauth = functions.https.onRequest((request, response) => {
      const responseurl = util.format('%s?code=%s&state=%s',
        decodeURIComponent(request.query.redirect_uri), request.query.code,
        request.query.state);
      console.log('*********'+responseurl);
      return response.redirect(responseurl);
    });

    exports.faketoken = functions.https.onRequest((request, response) => {
      const grantType = request.query.grant_type
        ? request.query.grant_type : request.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,
        };
      }
      response.status(HTTP_STATUS_OK)
        .json(obj);
        console.log('********** TOKEN **********',response);
    });

以上代码使用假身份验证执行。 为什么在我实施自定义 OAuth 时没有执行? 我需要在 firebase 中对 clienID 和 secret 做任何更改吗? 如何获取 OAuth 返回的访问令牌?

请帮忙。我是 node.js.

的新手

请求中返回的授权代码将作为授权字段出现在 header 中。这是使用 Node.js.

将其拉出的方法
function getToken(headers) {
  // Authorization: "Bearer 123ABC"
  return headers.authorization.substr(7);
}