【问题标题】:Luracast Restler Multiple Authentication Classes Not Allowing AccessLuracast Restler 多重身份验证类不允许访问
【发布时间】:2015-05-22 00:47:32
【问题描述】:

我定义了两个身份验证类。

  1. API 密钥 (APIKeyAuth)
  2. OAUTH2(OAUTH2 服务器)

在我的 index.php 中,我定义了以下内容

$r = new Restler();

$r->addAuthenticationClass('APIKeyAuth');
$r->addAuthenticationClass('OAUTH2Server');

然后我保护 APIKeyAuth 的其余方法之一

/**
 * @access protected
 * @class  APIKeyAuth{@requires apikey}
 */
  public function .......etc

如果我调试它,它会通过第一步,$authObj(请参阅下面来自 restler.php 的代码)将 是 APIKeyAuth。它检查 __isAllowed 并返回 true ... 这很好。

然后它会通过 OAUTH2Server(在我看来,它不应该像其他方法一样) 被修饰为使用 APIKeyAuth。

因此它通过并且 OAUTH2Server 中的 __isAllowed 为 false,因此用户将获得 Unauthorzied 响应。

foreach ($this->authClasses as $authClass) {
    $authObj = Scope::get($authClass);
    if (!method_exists($authObj,
      Defaults::$authenticationMethod)
     ) {
       throw new RestException (
         500, 'Authentication Class ' .
         'should implement iAuthenticate');
      } elseif (
        !$authObj->{Defaults::$authenticationMethod}()
       ) {
         throw new RestException(401);
       }
 }

我是否需要更改 OAUTH2 服务器以检查其是否使用 API 密钥并添加逻辑? (似乎是错误的做法)。

【问题讨论】:

    标签: php restful-authentication restler


    【解决方案1】:

    Restler 直到 RC5 串行处理身份验证类,这意味着所有身份验证类必须返回 true 才能通过受保护的 api 调用

    自 RC6 以来,这已更改为并行,这意味着任何一个身份验证类都可以允许访问受保护的 api

    【讨论】:

      猜你喜欢
      • 2011-12-15
      • 2019-08-19
      • 1970-01-01
      • 2014-02-19
      • 2015-12-25
      • 2020-07-01
      • 2012-12-18
      • 1970-01-01
      • 2021-05-27
      相关资源
      最近更新 更多