如何将 reactJS 应用与 Google Cloud Functions 和 Cloud 运行 集成并启用身份验证?

How to integrate reactJS app with Google Cloud Functions and Cloud Run with authentication enabled?

我正在开发一个将在浏览器中 运行 的 reactJS 应用程序。我想从该应用向部署在 Google Cloud 运行 和 Google Cloud Functions 中的服务发出请求,两者都启用了身份验证,但我不知道如何对请求进行身份验证。

我有一个有权调用这些服务的服务帐户凭据,但由于 reactJS 环境变量名称,我无法使用默认凭据,而且我无法使用 NodeJS Google Cloud SDK。

如何验证来自 Google 云之外的 reactJS 应用对云 Functions/Cloud 运行 的请求?

您必须使用客户端身份验证机制。 Firebase Auth works very well, and you have the Google Cloud version name Google Identity Platform.


编辑 1

如果您的用户未通过身份验证,您将无法使用身份验证服务。您应该限制对您的 Cloud Functions 和 Cloud 运行 服务的访问、成本和滥用。为此,您需要使用 API Gateway, such as Google Cloud API Gateway, or a more entreprise grade with APIGee.

您还可以使用 HTTPS Load Balancer in front of Cloud Functions or Cloud Run and activate Cloud Armor 来防止对您的服务的攻击(但这不是速率限制)。