samedi 28 mars 2015

Slim library error Api key is misssing


Vote count:

0




I followed this

http://ift.tt/1kQXOIa

and came up with a REST API. It works fine on my localhost but when I deploy it to an online server I get an error

"Api key is misssing"

but when I make requests that don't require authentication the API responds fine. below is the Authorization code



/**
* Adding Middle layer to authenticate every request
* Checking if the request has valid api key in the 'Authorization' header
*/
function authenticate(\Slim\Route $route) {
//Getting request headerstip
$headers = apache_request_headers();
$response = array();
$app = \Slim\Slim::getInstance();

//Verifying Authorization Header
if (isset($headers['Authorization'])) {
$db = new DbHandler();

//get the api key
$api_key = $headers['Authorization'];
if (isset($headers['category']) && is_numeric($headers['category'])) {

global $category;
$category = $headers['category'];

if (isset($headers['info_id']) && is_numeric($headers['info_id'])) {

global $info_id;

$info_id = $headers['info_id'];
}
}
//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();
}
}


asked 1 min ago







Slim library error Api key is misssing

Aucun commentaire:

Enregistrer un commentaire