移动后端API密钥的安全性 [英] Security of Mobile Backend API key
问题描述
假设我正在开发一个移动应用程序,该应用程序可以调用API服务器. API服务器由API密钥保护.
Suppose I am developing a mobile application that makes calls to an API server. The API server is secured by an API Key.
我无法在移动应用程序内部对API密钥进行硬编码,因为它可能被盗.
I cannot hard-code the API Key inside the mobile application because it can be stolen.
如何保护API密钥?
推荐答案
通常如何解决该问题?
How is that problem usually solved?
(听起来您要保护的API密钥是针对您不拥有的API服务的.)
(It sounds like the API-key you are trying to protect is for an API service that you don't own.)
一种方法是使用身份验证服务器.私有API密钥保留在身份验证服务器上,只有在有效登录后才能共享.
One approach is by using an authentication server. The private API-key is kept on the authentication server and only shared after a valid login.
那么这是怎么工作的?
- 移动客户端上的用户输入登录名&密码
- 这些凭据将发送到验证服务器,并在其中进行验证
- 如果登录名有效,则将API密钥发送到移动客户端
在架构上,您将需要一个单独的身份验证服务器,该服务器将为您提供2个不同的服务器:
Architecturally, you would need a separate authentication server which would leave you with 2 different servers:
-
某些API密钥服务器,您需要使用私有API密钥才能使用
Some API-key server that you need a private API-key to use
身份验证服务器(用于验证用户登录并交换专用API密钥)
Authentication server (used to verify user login and exchange private API-keys)
第二种方法是使用直通服务器.私有API密钥永远不会以这种方式共享.可以在直通服务器上添加身份验证,但这不是必需的.
A second approach is to use a pass through server. The private API-key is never shared in this approach. It is possible to add authentication onto the pass-thru server, but not required.
那么这是怎么工作的?
- 移动用户联系直通服务器以获取来自API的数据
- 直通服务器(使用存储的专用API密钥)进行api调用
- API服务器使用数据响应直通服务器
- 直通服务器将API响应转发到移动应用
在这种情况下,您拥有直通服务器,因此您无需共享API密钥,并且用户身份验证是可选的.
In this case, you own the pass-thru server so you never need to share your API keys and user authentication is optional.
这篇关于移动后端API密钥的安全性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!