如何防止其他iOS/Android应用程序使用我的RESTful API? [英] How can I prevent other iOS/Android apps from using my RESTful API?

查看:71
本文介绍了如何防止其他iOS/Android应用程序使用我的RESTful API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个预先存在的iOS&我正在为其进行更新的Android应用程序,其中包括RESTful服务API和用于用户身份验证的Facebook登录.该应用程序的一般流程是:

I have a pre-existing iOS & Android app, that I'm making an update for that includes a RESTful services API and Facebook login for user authentication. The general flow of the app is:

  1. 用户通过Facebook的SDK登录"我的应用,这些SDK将访问令牌返回到我的应用.
  2. 应用程序调用RESTful服务,包括Facebook访问令牌作为参数(使用HTTPS和SSL)
  3. 被调用的服务,将接收到的访问令牌(以及仅存储在我的服务器上的应用程序密码)发送到Facebook,以验证用户身份,并根据该用户执行操作.Facebook设置为要求服务器端调用提供应用程序机密.

我的应用程序已经流行并且已经有多个克隆,我想阻止这些克隆使用我的RESTful API(因为我确信在发布更新时它们会尝试这样做).让我们假设这些克隆是智能的,正在使用与我的应用相同的Facebook访问令牌(如果可能的话),并且遵循类似的模式&调用我的应用程序执行的API的频率.

My app has gained popularity and has several clones already, and I want to prevent these clones from being able to use my RESTful API (as I am sure that they will try to do when I release the update). Let's assume that the clones are smart, are using the same Facebook access tokens that my app does (if this is possible), and are following a similar pattern & frequency of calling the API that my app does.

总有办法确保或几乎确保对我的服务的调用仅来自我的应用程序,而不是克隆吗?

Is there anyway to ensure, or nearly ensure, that calls to my services are coming only from my app, and not the clones?

提前谢谢!

推荐答案

您可以通过在请求中包含签名并进行验证来实现.

You can do this by including a signature in the request, and verifying it.

应用程序一侧:

  1. 执行以下操作: signature = md5(md5(url + data)+ MY_RANDOM_KEY)

签名附加到数据或url等.

append signature to the data, or url, etc.

将呼叫发送到REST api(照常)

send call to REST api (as usual)

服务器端:

  1. 从正文/URL中提取签名(并从其中删除).

计算出您的想法: signature_should_be = md5(md5(url +数据)+ MY_RANDOM_KEY) [请记住,您已删除了 signature 从url/data中获取,以便您以原始哈希前状态获得url/data]

calculate what you think it should be: signature_should_be = md5( md5(url + data) + MY_RANDOM_KEY) [keep in mind you've removed signature from url/data so that you get url/data in its original pre-hash state]

验证签名 signature_should_be 是否相等

执行此操作以及SSL,应该可以使您的API足够安全.

Doing this, along with SSL, should make your API secure enough.

这篇关于如何防止其他iOS/Android应用程序使用我的RESTful API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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