I have a simple project that makes HTTP requests to an API endpoint and uses an API Key that I want to keep secret. Initially I put the key in its own file, imported the key into the file that uses it, and added the key file to the .gitignore. The problem is that this approach won't work if someone clones the GitHub repository.
So my question is - how can I keep my API key secret, but have my project still be functional if someone clones the repo?
Any feedback greatly appreciated.
The only way to hide it is to proxy your request through your own server. Netlify Functions are a free way to add some simple backend code to a frontend app. This is this method I used while learning to program in college, where I needed to share my progress with my peer group without disclosing my API keys.
Most importantly, you do not add it, ever. If you added it, committed it, and then removed it, it is still possible to recover it as a stranger with access to your repo by checking out the old commit.
With that out of the way, what you can do:
secret.config
, but commit sample_secret.config
so that anybody who forks your repository can see what syntax he would need to use. sample_secret.config
is never used by the software, and instead of the API key contains a key like this-is-4-dummy-API-key-3232
or whatever makes sense.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With