【发布时间】:2016-11-08 07:49:47
【问题描述】:
我已经为我的应用程序实现了一个苗条的 api,它在标题中获得一个 api_key 得到有效的请求 这是代码
function authenticate(\Slim\Route $route) {
// Getting request headers
$headers = apache_request_headers();
$response = array();
$app = \Slim\Slim::getInstance();
// Verifying Authorization Header
if (isset($headers['Authorization'])) {
$db = new DbHandler();
global $api_key;
// get the api key
$api_key = $headers['Authorization'];
// validating api key
if (!$db->isValidApiKey($api_key)) {
// api key is not present in users table
$response["error"] = true;
$response["message"] = "Access Denied. Invalid Api key";
echoRespnse(401, $response);
$app->stop();
} else {
global $user_id;
// get user primary key id
$user_id = $db->getUserId($api_key);
}
} else {
// api key is missing in header
$response["error"] = true;
$response["message"] = "Api key is misssing";
echoRespnse(400, $response);
$app->stop();
}
} 它工作正常,但突然我的代码没有任何变化,我得到了 apikey 虽然我现在在标题中添加授权,如果我将授权更改为 Authorizationn 或其他一些东西,它会再次工作但我担心一段时间后我得到新地址再次出现 smae 错误。现在的问题是主机头中的一个特定地址是否有任何限制,或者任何人都知道它为什么会发生
【问题讨论】:
-
你用什么来测试你的请求?
-
google chroom 上的邮递员和我在 android 中的应用程序都给我 api 密钥丢失!