【问题标题】:AuthenticationClass needs duplicating with UrlVersioning - Luracast RestlerAuthenticationClass 需要使用 UrlVersioning 复制 - Luracast Restler
【发布时间】:2015-03-27 06:10:04
【问题描述】:

我希望有一个身份验证类,并且我的 APIS 版本也不需要复制我的安全代码。

我已经设置了restler并在index.php中添加了以下内容;

Defaults::setProperty('useUrlBasedVersioning', true);
$r->addAuthenticationClass('MyOrg\\Security\\APIAuth');

然后我在公用文件夹之外的另一个文件夹中设置了我的身份验证类。它不能单独工作,但我发现由于使用 UrlBased 版本控制,我不得不在不同的命名空间中重复该类。

例如

MyOrd ---> 安全性 ---> v1 ---> APIAuth.php

MyOrd ---> 安全性 ---> v2 ---> APIAuth.php

我不想做上述但更简单的只是有

MyOrd ---> 安全性 ---> APIAuth.php

我正在使用 Restler RC5,任何指导都将不胜感激,或者这是 Restler 的错误。

也记录为restler项目https://github.com/Luracast/Restler/issues/433的问题

【问题讨论】:

    标签: php restler


    【解决方案1】:

    只需实现 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;
        }
    }
    

    【讨论】:

    • 非常感谢!我还在您的 UrlVersioning 示例中发现它提到了接口,感谢您不告诉我只使用 RTFM :)。
    猜你喜欢
    • 1970-01-01
    • 2011-12-15
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多