2012-12-07 65 views
2

我已经创建了一个使用锂php框架的RESTful应用程序,现在我的问题是如何保护它?如何保护锂电池RESTful API?

是否有任何现有的OAUTH或HTTP Digest验证代码使用锂框架?

+0

这是什么意思,甚至?什么样的安全性? Cookies,API令牌,授权,访问控制?锂是一个框架,它提供了工具和结构,但是(出于需要)假定你是一个知道如何编写软件的程序员。对不起,这个问题没有意义。 –

+0

对不起,如果它不清楚,但我提到REST应用程序,它意味着Oauth或Http摘要式身份验证。我想知道是否有任何现有的OAuth或摘要身份验证代码在锂? –

回答

2

虽然我不知道你在找什么样的安全的...

有内置的安全锂电池,你可以看到两个简短教程让你去这里:

的基本信息在 “简单身份验证” 的教程......你需要:

  • 来跟踪你的用户
  • 引导Auth通过
  • 设置会话&验证适配器

那就要看,如果你要通过形式做authenticaion数据库,或通过其他方法。

的turtorials将告诉你如何建立一个形式,但是你也可以“安全”的路径(网址),正在通过config/routes.php文件像这样要求...

<?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; }); 

?>