简体   繁体   English

如何将jQuery.getJSON()的响应仅限制到某些域?

[英]How to restrict the response of a jQuery.getJSON() only to certain domains?

I have a jQuery script in a clientDomain.com/show.php page that shows some data loaded from a serverDomain.com/echo.php page using jQuery.getJSON(). 我在clientDomain.com/show.php页面中有一个jQuery脚本,其中显示了一些使用jQuery.getJSON()从serverDomain.com/echo.php页面加载的数据。 I want that only allowed domains can show the data because I don't want that unauthorized people install the script in their own website without my permission. 我希望只有允许的域才能显示数据,因为我不希望未经授权的人在未经我许可的情况下将脚本安装在自己的网站中。 Is there any way to restrict the response of a jQuery.getJSON() only to certain domains? 有什么方法可以将jQuery.getJSON()的响应仅限制于某些域吗? The solution should prevent also the use of iframe by the client. 该解决方案还应防止客户端使用iframe。 In conclusion, the data should be seen only if someone visit directly serverDomain.com/echo.php page or one of the allowed client domains. 总之,仅当有人直接访问serverDomain.com/echo.php页面或允许的客户端域之一时,才应该看到数据。 Thanks in advance for the support! 预先感谢您的支持!

My request/response script works like the first example in jQuery.getJSON() | 我的请求/响应脚本的工作方式类似于jQuery.getJSON()中的第一个示例。 jQuery API Documentation jQuery API文档

I can only code the client jQuery script (that will be ditribuited to the allowed domains) and the serverDomain.com/echo.php page (that is my property). 我只能编写客户端jQuery脚本(将分发到允许的域)和serverDomain.com/echo.php页面(这是我的财产)。

Don't do that. 不要那样做 Use auth tokens instead that are updated regularly. 而是使用定期更新的身份验证令牌。 Anybody can fake an HTTP referrer. 任何人都可以伪造HTTP引荐来源网址。

Here's a good answer on SO which covers resful api authentication: REST API Token-based Authentication 这是涵盖SO api身份验证的SO的一个很好的答案: 基于REST API令牌的身份验证

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM