[英]AuthenticationClass needs duplicating with UrlVersioning - Luracast Restler
I would like to have an authenitcation class and also have my APIS versioned without having to duplicate my security code. 我想拥有一个身份验证类,并且还可以对APIS进行版本控制,而不必重复我的安全代码。
I have setup restler and added the following to index.php; 我已经安装了restler并将以下内容添加到index.php;
Defaults::setProperty('useUrlBasedVersioning', true);
$r->addAuthenticationClass('MyOrg\\Security\\APIAuth');
I have then setup my authentication class within another folder outside of the public folder. 然后,我在公用文件夹之外的另一个文件夹中设置了我的身份验证类。 It wasn't working on its own but I found due to using the UrlBased Versioning I had to repeat the class in the different namespaces.
它不能单独工作,但是我发现由于使用了UrlBased版本控制,我不得不在不同的命名空间中重复该类。
eg 例如
MyOrd ---> Security ---> v1 ---> APIAuth.php
MyOrd --->安全---> v1 ---> APIAuth.php
MyOrd ---> Security ---> v2 ---> APIAuth.php
MyOrd --->安全---> v2 ---> APIAuth.php
I don't want to have to do the above but more simple just have 我不想做以上但更简单的只是
MyOrd ---> Security ---> APIAuth.php
MyOrd --->安全性---> APIAuth.php
I'm using Restler RC5, any guidance would be appreciated or is this a bug with Restler. 我正在使用Restler RC5,任何指导将不胜感激,或者这是Restler的错误。
Also logged as issue with the restler project https://github.com/Luracast/Restler/issues/433 Restler项目还记录为问题https://github.com/Luracast/Restler/issues/433
Just implement the iProvideMultiVersionApi
and return the maximum version that is supported by the auth class, which in your case will be 2. See the example below 只需实现
iProvideMultiVersionApi
并返回auth类支持的最大版本(在您的情况下为2)。请参见以下示例
namespace MyOrg\Security;
use Luracast\Restler\iAuthenticate;
use Luracast\Restler\iProvideMultiVersionApi;
class Auth implements iAuthenticate, iProvideMultiVersionApi{
public function __isAllowed(){
return isset($_GET['api_key']) && $_GET['api_key'] =='allow';
}
public function __getWWWAuthenticateString(){
return 'Query';
}
/**
* Maximum api version supported by the api class
* @return int
*/
public static function __getMaximumSupportedVersion()
{
return 2;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.