首页 > 解决方案 > 对从 App Engine 到 Cloud Function 的请求进行身份验证

问题描述

关于这个主题有几个问题,但似乎大多数用例都围绕着 Firebase。

我在 App Engine 上运行了一个简单的 Node/Express 应用程序。我在那里安排了几个 cron 作业,它们在同一个项目中调用一些 Cloud Functions。我想将我的 Cloud Functions 配置为仅接受来自该 App Engine 服务的请求。

根据 Google 的 Cloud Function 文档,是不是就这么简单?

exports.myFunction = (req, res) => {
  // Set CORS headers for preflight requests

  res.set('Access-Control-Allow-Origin', 'https://my-app-engine-project.appspot.com');
  res.set('Access-Control-Allow-Credentials', 'true');

  if (req.method === 'OPTIONS') {
    // Send response to OPTIONS requests
    res.set('Access-Control-Allow-Methods', 'GET');
    res.set('Access-Control-Allow-Headers', 'Authorization');
    res.set('Access-Control-Max-Age', '3600');
    res.status(204).send('');
  } else {
    // The rest of my cloud function logic goes here
  }
};

我不清楚我需要从 App Engine 路由传递什么才能成功授权所有内容。

标签: node.jsgoogle-app-enginegoogle-cloud-functions

解决方案


推荐阅读