[英]How to secure a Lithium php RESTful API?
我使用Lithium php框架创建了一个RESTful应用程序,现在我的问题是如何保护它?
是否存在使用锂框架的OAUTH或HTTP摘要式身份验证的现有代码?
虽然我不确定你在寻找什么样的安全性......
有一个内置的锂安全,你可以看到两个简短的教程,让你去这里:
“简单身份验证”教程中介绍了基础知识......您需要:
Auth
通过config/bootstrap.php
那么这取决于你是否要通过表格或其他方法进行认证。
turtorials将向您展示如何设置表单,但您也可以通过config/routes.php
文件“保护”正在请求的路由(url),如此...
<?php
use lithium\net\http\Router;
use lithium\core\Environment;
use lithium\security\Auth;
// check if the user is logged in
$user = Auth::check('default');
// these routes are not behind a login
Router::connect('/login', 'Sessions::add');
Router::connect('/logout', 'Sessions::delete');
if ($user && $user["user"] == "admin") {
// these two routes will only work if a user is authenticated.
Router::connect('/{:controller}/{:action}/{:args}.{:type}');
Router::connect('/{:controller}/{:action}/{:args}');
}
// redirect the user to a login if no other routes match
Router::connect('/{:args}', array(), function($request) { header('Location: /login/url/'.str_replace('/','*',$request->url)); exit; });
?>
感谢您编辑问题以实际询问具体内容。 请参阅以下内容:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.