Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep API keys secret when using client side Javascript?

For example, check out this Facebook plugin.

In the client side the API key is clearly visible. What is stopping another user from obtaining this key and using this feature on a different site?

I figured a very naive implementation would be to check the domain the request comes from but things like this are easy to fake.

If I were to create something similar, how would I go about securing the authentication process?

I want as much of this work to be client side, though some form of server authentication will be required surely? Any links or advice would be greatly appreciated.

Update

Similar question about API keys that I found useful.

like image 431
Finglas Avatar asked Oct 21 '11 08:10

Finglas


People also ask

How do I secure API key in client side?

The only way to protect an API key is to keep the key only on the server. The client asks your server for some data and your server uses the API key to get the data from the API source and returns it back to the client. Anything you send to the client will be visible to any hacker.


1 Answers

In three words: server-side validation. FB itself will throw an error when you use a key that's incorrect for the given site. The API key is not supposed to be secret (as opposed to the secret key).

like image 161
Piskvor left the building Avatar answered Oct 11 '22 11:10

Piskvor left the building