I want to restrict access to the method if the parameter has a specific value. Take for example this class:
Simple.php:
class Simple
{
function item($name)
{
if($name == "somerestricted")
{
if($authenticated)
{
}
else
{
}
}
else
{
echo "Hi!";
}
}
}
Using this authentication class:
BasicAuthentication.php:
class BasicAuthentication implements iAuthenticate
{
const REALM = 'Restricted API';
function __isAllowed()
{
if(isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW']))
{
$user = $_SERVER['PHP_AUTH_USER'];
$pass = $_SERVER['PHP_AUTH_PW'];
if($user == 'laterfetched' && $pass == 'fromdatabase')
{
return true;
}
}
header('WWW-Authenticate: Basic realm="'.self::REALM.'"');
throw new RestException(401, 'Basic Authentication Required');
}
}
Index.php (gateway): addAuthenticationClass ('BasicAuthentication'); $ R-> addAPIClass ('Simple'); $ R-> handle ();
Now the method simple/itemis available to the public. However, if I turn itemit into a function protected, the request each needs authentication. This is not what I want to do. Only simple/item/somerestrictedrequires authentication.
, iAuthenticate ? , ?
( ).
: Rester 3.0 Basic Authentication Luracast Restler
Restler rc4.