Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery $.ajax.post to a service with secret API Key

let's assume that there is a service out there as following;

http://exmaple.com/service1/GetSomething?apikey={api-key-goes-here}

an my api key is : 96a143c8-2f62-470c-b81f-dec5fc271873

so we will be making calls to > http://exmaple.com/service1/GetSomething?apikey=96a143c8-2f62-470c-b81f-dec5fc271873 link and it gives back the response as JSON.

when I consume that with JQuery (or any other client side JavaScript library), how will that key will be secure? I am thinking that and I figured there is no way. If I am going to make a call to that service with client side call, it will be our in the open.

any idea on this?

thanks.

like image 676
tugberk Avatar asked Dec 22 '22 13:12

tugberk


1 Answers

Make a proxy.

Post the values to one of your pages and from this page make the real request on the server-side, then return the value you get.

Of note: You cannot make a cross-domain request with javascript, mainly browsers don't allow this for security reasons.

like image 140
BrunoLM Avatar answered Jan 09 '23 18:01

BrunoLM