问题描述
我的问题是关于在哪里以及如何:
My question is about where and how to:
- 隐藏 API 密钥
- 访问我的 app.js 文件中隐藏的 API 密钥
在这种情况下,我正在处理一个 Algolia 管理 API 密钥(但旨在以相当通用的方式提出这个问题).
In this case I am dealing with an Algolia Admin API Key (but aiming to ask this question in a fairly generic way).
为了让我的应用正常工作,根据某些用户操作,我需要更新我的 Algolia 索引(这需要一个管理 API 密钥才能执行).
In order for my app to work, based on certain user actions I need to update my Algolia index (which requires an Admin API Key in order to do).
我知道我不应该向前端公开我的管理 API 密钥(即不要将它放在我的 app.js 文件中).如何安全地将我的 API 管理密钥传递到我的 app.js 文件,以便我可以更新我的 Algolia 索引?
I understand that I am not supposed to expose my Admin API Key to the front-end (i.e. don’t put it in my app.js file). How can I securely pass my API Admin Key to my app.js file, so that I can make updates to my Algolia index?
我遇到的一些事情:
-我应该将它隐藏在 config.json
文件中吗?我无法弄清楚如何使用从我的 js 中的配置文件导出的信息(无论如何这可能会破坏目的?).我读了这个
-Should I hide it in a config.json
file? I can't figure out how use information exported from a config file in my js (which maybe would defeat the purpose anyways?). I read this
-还在 Firestore 文档中提到,在与 Algolia 合作时,应用 ID 和 API 密钥存储在函数配置变量中".如何将我的 API 密钥存储在配置变量中?
-Also on the Firestore docs it mentions, in reference to working with Algolia, that "App ID and API Key are stored in functions config variables". How do I store my API key in config variables?
推荐答案
You cannot give the key to the client, through any mechanism, and keep it secret.
构建网络服务(使用您选择的服务器端语言,使用任何适当的身份验证)并编写您自己的 API 以允许执行有限的操作选择.然后,您的网络服务充当 Algolia 的客户端.
这篇关于在哪里“隐藏"API 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!