从 Firebase 为 API 个端点生成 API 密钥

Generate API key for API Endpoints from Firebase

我在云 运行 中有一个 API,我想使用 API 密钥保护它。我一直在使用 https://cloud.google.com/endpoints/docs/openapi/get-started-cloud-run#configure_esp to configure the endpoints for the API. I've successfully created the API and the developer portal. My goal is for users to log in to a mobile and/or web app (using Firebase) and then be able to generate an API key that allows them to access the API. I've only found documentation on manually creating API keys for users: https://cloud.google.com/endpoints/docs/openapi/restricting-api-access-with-api-keys#create-an-api-key-for-each-caller

我的身份验证方案是一种常见模式(github,例如,使用这种模式),我很惊讶它在 GCP 上如此困难。我能够在 AWS 中成功实施此方案。我错过了什么?

您没有错过任何东西,这根本不可能。 API 密钥安全性不被 Google 推荐(弱于 OAuth2 身份验证机制)并且围绕 API 密钥的所有操作仅适用于 Google 内部调用。

您是否尝试过自己验证 API 密钥?同样的结果:不可能。只有 Cloud Endpoint 可以通过调用内部 Google API,没有 public.

来做到这一点

如果您使用 Firebase,我建议您使用 Firebase Auth 对 API 上的用户进行身份验证。它是 integrated to CLoud Endpoint,您只需更新您的安全定义即可。