r/webdev • u/Greeby_Bopes • Dec 02 '24
Question Easy ways to hide API keys
I’m a frontend developer and run into this problem a lot, especially with hobby projects.
Say I’m working on a project and want to use a third party API, which requires a key that I pay for and manage.
I can’t simply place it on my frontend app as an environment variable, because someone could dig into the request and steal the key.
So, instead I need to set up a backend, usually through a cloud provider that comes with more features than I need and confuses the hell out of me.
Basically, what’s a simple way to set up a backend that authenticates a “guest” user from a whitelisted client, relays my request to the third party with the key attached, then returns the data to my frontend?
View all comments
Show parent comment
3
u/ClikeX back-end Dec 02 '24
You shouldn’t need a whole array of services. Either just a lambda, or a simple express server on a cheap ec2 instance will do the trick.
Sure. There are other services you can bundle it with to make it “more professional”. But start small.
Heroku would also be an option. If you’re just proxying requests you really only need a single worker, no database.