【发布时间】:2016-08-17 23:24:59
【问题描述】:
我是苗条框架的新手,正在尝试构建基于 json 的 api。我只想问如何保护我的 api,所以只有那些应用程序会调用具有用户名和密码的 api 函数
这是我的rest api的代码
require __DIR__ . '/vendor/autoload.php';
$app = new Slim\App();
//slim application routes
$app->get('/', function ($request, $response, $args) {
$response->withJson("Welcome Message", 201);
return $response;
});
$app->get('/orders/status/{status}', function ($request, $response, $args) {
return get_Orders($request, $response, $args);
});
$app->run();
function get_Orders($request, $response, $args){
if($args['status'] == "processing"){
$response->withJson("list of processing orders}", 200);
return $response;
}
else{
$response->withJson("Premission not guranted", 200);
return $response;
}
}
我只是构建了一个简单的 get 路由并且它可以工作,但是我如何保护它,以便如果应用程序具有有效的用户名和密码,那么只有它返回结果。
【问题讨论】: