reactjs - 我应该如何在我的 React 应用程序中对 Google Cloud Function 进行身份验证?
问题描述
我有一个 React + GraphQL 应用程序,它可以访问 Google Cloud Function 来运行一些代码。目前我允许未经身份验证的访问,但我希望将其锁定。我没有看到如何在我的 React 应用程序中进行这样的身份验证:
fetch("https://REGION-PROJECT_ID.cloudfunctions.net/FUNCTION_NAME", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': access_token // <-------- this is what I want
},
body: JSON.stringify(something)
})
此示例在此线程中进行了说明:https ://github.com/googleapis/google-auth-library-nodejs/issues/775
我很想使用服务帐户进行身份验证,但我不想使用 Node 服务器。我是否被迫走 API 密钥路线?
这是用于验证云功能的文档:
https://cloud.google.com/functions/docs/securing/authenticating
谢谢!
解决方案
我知道我的用例应该有更好的解决方案。API Gateway 是新的,所以在我寻找选项时它没有出现。感谢您的回复。
推荐阅读
- php - Laravel - 如何清除数组语言的缓存
- node.js - MalformedResponse expected_inputs[0].input_prompt.rich_initial_prompt:“carousel_browse”仅支持支持 Web 浏览器的客户端
- javascript - PHP 将 PHP 数据传递到 JS 数组中
- haskell - 为什么surfaceDimensions(出现)返回一个双封闭向量(V2 V2 CInt)?
- php - 从 Eclipse PHPUnitLogger 错误和端口 7478 错误运行 PHPUnit
- python - 如何将来自ansible play的大型json结果传递给python脚本
- r - 如何对两列中具有目标值的行中的值求和?
- sql - 如何计算表格中分组值的次数?
- python - 返回语句的Python问题
- scala - Spark中的累积产品