Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make REST calls secure

I'm calling a webservice using the REST methodology using JSON/JS/jquery and am wondering if there is a way to call the webservice without exposing my API keys in the source code. Anyone know of a way to hide the API keys from the public and still make the call?

I'm worried that if someone goes through my source, they will be able to use my API key.

like image 781
locoboy Avatar asked Jul 01 '11 20:07

locoboy


1 Answers

You could delegate the calls to your own server, so instead of:

  1. Browser sends HTTP request to external REST API, with API key
  2. External REST API sends response to browser

you have

  1. Browser sends HTTP request to your server
  2. Your server sends HTTP request to external REST API, with API key
  3. External REST API sends response to your server
  4. Your sever sends response to browser

I'm not sure that someone else "stealing" your API key is a huge problem, though, since API keys (Google, for example) are frequently associated with specific domains.

like image 180
Matt Ball Avatar answered Sep 22 '22 12:09

Matt Ball