【发布时间】:2013-01-02 16:36:56
【问题描述】:
我目前正在为我运行的网站开发 api。该 api 将在许多地方使用,其中一个地方是 Android 应用程序。
它的目的是允许用户登录和下载文件。我有 api 版本,它将使用 HTTPS,因此所有数据在传输时都很好。
我遇到的问题是 API 调用需要 API 密钥。使用此密钥,您将能够访问可能导致问题的 API 的某些功能。
我想知道,有没有办法保护这个 API 密钥?我根本不是 Android 开发人员,但人们会使用 Android 上的 API,所以我需要制定解决方案。
以下是 API 使用的流程示例:
// Log the user in with their username and password (HTTPS, so not really an issue)
romhut.request('/api/users/login?apikey=KEY', {username : 'scott', password : 'password'}, function(r) {
console.log(r);
// Once you have the token, request the API key that allows actions such as downloading
romhut.request('/api/files/download?apikey=KEY', {token : r.token, file : file}, function(d){
console.log(d);
// Download the file
}, 'POST');
}, 'POST');
【问题讨论】:
-
您想离线存储 API 密钥,还是登录后在运行时检索?
-
API 密钥由开发者提供,它从用户那里返回一个令牌,然后可以使用它来做请求
-
我已经更新了我的示例。使用例更简单。
-
您是否正在寻找有关此问题的其他信息?
标签: java php android security api