阻止对JSON API的不必要使用 [英] Block unwanted use of json API

查看:110
本文介绍了阻止对JSON API的不必要使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,您可以在其中使用ajax从我们的服务器请求数据作为json(仅在我们的网站上使用).现在,我发现人们开始使用我们的请求从我们的系统中获取数据.有没有一种方法可以阻止用户使用我们的公共json API.我一直在思考的想法是:

I have a website where you can request data using ajax from our servers as json (only to be used on our site). Now i found that people start using our requests to get data from our system. Is there a way to block users from using our public json API. Ideas that i have been thinking about is:

  • 某种校验和.
  • 页面上必须与服务器端匹配的会话唯一javascript值
  • 某种具有1000个不同有效值的滚动密码.

所有这些都不是100%安全的,但使使用我们的数据更加困难.任何其他想法或解决方案都很好.

All these are not 100% safe but makes it harder to use our data. Any other ideas or solutions would be great.

(您可以执行的请求是对邮政编码,电话号码,ssn等进行查找和翻译)

(The requests that you can do is lookup and translations of zip codes, phone numbers, ssn and so on)

推荐答案

您可以使用相同的 API-密钥身份验证方法,Google用来限制对其API的访问.

You could use the same API-key authentication method Google uses to limit access to its APIs.

  • 每个用户都必须具有有效的API密钥,才能请求数据.
  • 当用户请求时,生成API密钥并将其存储在数据库中.

链接::这样,您可以监视API的使用情况,并对其施加使用限制.

This way, you can monitor usage of your API, and impose usage limits on it.

@ c69指出,您还可以将生成的API密钥绑定到API用户的domain.然后,如果不是从API用户的域发出的,则可以检查Referer URL(PHP中的$_SERVER['HTTP_REFERER'])并拒绝请求.

As @c69 pointed out, you could also bind the API keys you generate to the API-user's domain . You can then check the Referer URL ($_SERVER['HTTP_REFERER'] in PHP), and reject request, if it is not being made from the API-user's domain.

这篇关于阻止对JSON API的不必要使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆